Skip to content

XE session overhaul: event_file target, stale-session hygiene, Azure ON DATABASE, CONTEXT_INFO-scoped predicates #621

Description

@nanoDBA

Problem

sp_StatUpdate_XE_Session.sql captures to an 8 MB ring buffer, which wraps long before a 5-hour maintenance window ends — the events you most want (from the start of the run) are gone by the time you look. It also leaves stale sessions behind, does not work on Azure SQL Database, and captures server-wide noise instead of scoping to sp_StatUpdate's own activity.

Fix

  1. event_file target (with rollover) instead of / alongside the ring buffer, read back via fn_xe_file_target_read_file filtering on object_name and timestamp before casting to xml.
  2. Stale-session hygiene: sweep-and-drop prior sessions by name prefix on create; unique session-name suffix to avoid collisions.
  3. Azure SQL DB support: ON DATABASE variant, with event existence probed via sys.dm_xe_objects before inclusion.
  4. Scoped predicates: filter on the SU| CONTEXT_INFO prefix that sp_StatUpdate now stamps per session, so the trace captures only this tool's statements.
  5. Pre-build CREATE/START/STOP/DROP as a four-string lifecycle so any code path can clean up.

Pattern source: sp_HumanEvents session engineering (DarlingData).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    azureAzure SQL Database / Managed Instance specific behaviorenhancementNew feature or requestp2-importantSemantic gap, missing warning, or undocumented behavior that affects correctness

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions