{"id":1083,"date":"2020-01-23T06:30:56","date_gmt":"2020-01-23T14:30:56","guid":{"rendered":"http:\/\/3.209.169.194\/blogs\/erin\/?p=1083"},"modified":"2020-01-23T07:08:29","modified_gmt":"2020-01-23T15:08:29","slug":"what-events-are-in-a-trace","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/","title":{"rendered":"What Events are in a Trace?"},"content":{"rendered":"<p>Yes&#8230;I&#8217;m writing a post about <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/sql-trace\/sql-trace?view=sql-server-ver15\">SQL Trace<\/a>&#8230;specifically events in a trace. There are still lots of folks that use <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/tools\/sql-server-profiler\/sql-server-profiler?view=sql-server-ver15\">Profiler<\/a> and run server-side traces, and when I work with those customers I like to understand how the traces are configured. I want to see what events are in a trace, but I also want to see the filters and if the traces are writing to a file or rowset provider. I wrote this query ages ago and went looking for it today, which means I really should write a post so it&#8217;s easier to find \ud83d\ude42<\/p>\n<h2>Where to start<\/h2>\n<p>In order to determine the events in the trace, you first need to know the ID for the trace, which is automatically generated when you create the trace.\u00a0 You can find the ID in sys.traces:<\/p>\n<p>SELECT *<br \/>\nFROM sys.traces;<br \/>\nGO<\/p>\n<p>If I run this on my local instance, I get the output below:<\/p>\n<figure id=\"attachment_1085\" aria-describedby=\"caption-attachment-1085\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_2.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-1085 size-large\" src=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_2-1024x84.jpg\" alt=\"sys.traces output, part I\" width=\"1024\" height=\"84\" srcset=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_2-1024x84.jpg 1024w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_2-300x25.jpg 300w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_2-768x63.jpg 768w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_2.jpg 1477w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-1085\" class=\"wp-caption-text\">sys.traces output, part I<\/figcaption><\/figure>\n<figure id=\"attachment_1084\" aria-describedby=\"caption-attachment-1084\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_1.jpg\"><img decoding=\"async\" class=\"size-large wp-image-1084\" src=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_1-1024x92.jpg\" alt=\"sys.traces output, part II\" width=\"1024\" height=\"92\" srcset=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_1-1024x92.jpg 1024w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_1-300x27.jpg 300w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_1-768x69.jpg 768w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_1.jpg 1351w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-1084\" class=\"wp-caption-text\">sys.traces output, part II<\/figcaption><\/figure>\n<h2><\/h2>\n<h2>What to review<\/h2>\n<p>I broke the output into two images because there are a few things to point out.\u00a0 The trace with id = 1 is, almost always, represents the default trace.\u00a0 I yet to find a system where it is not the default trace, but it&#8217;s possible (e.g. someone disables the default trace, or manages to get another trace to start up before the default trace).\u00a0 If it&#8217;s writing to the LOG folder where SQL Server is installed, then I&#8217;m confident it&#8217;s the default trace and I&#8217;m not worried about it.<\/p>\n<p>The second trace, with id = 2, is one I created as a server-side trace. Notice that for the trace with id = 3, the path is NULL.\u00a0 This indicates that the trace is not writing to a file, but to a rowset provider (this is why is_rowset = 1 for that row).\u00a0 The rowset provider is typically, but not always, the Profiler UI.\u00a0 When I see this for a client, I ask if they use a third-party monitoring tool (as this is how traces from third-party tools can appear).\u00a0 Even if the customer has a monitoring tool, I want to see what events are being collected, and the filter(s).<\/p>\n<p>Some other items of interest in the output:<\/p>\n<ul>\n<li>start_time (when the trace started)<\/li>\n<li>last_event_time (when the last event was captured by the trace)<\/li>\n<li>event_count (number of events captured)<\/li>\n<li>dropped_event_count (number of events not captured)<\/li>\n<\/ul>\n<p>Notice that for the traces which write to a file, dropped_event_count is NULL.\u00a0 When writing to a file, SQL Trace guarantees that it will not lose events.\u00a0 This might sound great &#8211; you don&#8217;t want to miss any data, right?\u00a0 But&#8230;that also means that if the volume of events captured exceeds SQL Trace&#8217;s ability to write those events out to the file, then the activities in SQL Server that generate those events might have to wait.\u00a0 That is not a great thing.\u00a0 Note that with the rowset provider, you can lose data.\u00a0 If there is a 20 second stall where SQL Trace cannot push the events to the provider, it will start dropping events.<\/p>\n<h2>What events are in the trace<\/h2>\n<p>The third trace is the one in which we are interested.\u00a0 It is writing to a rowset provider, so we want to determine the events in the trace and who is running it.\u00a0 The query below lists the events and columns that are being captured, along with any filters that exist:<\/p>\n<p>SELECT<br \/>\n     e.name,<br \/>\n     c.name,<br \/>\n     CASE<br \/>\n          WHEN f.logical_operator = 0 THEN &#8216;AND&#8217;<br \/>\n          ELSE &#8216;OR&#8217;<br \/>\n     END logical_operator,<br \/>\n     CASE<br \/>\n          WHEN f.comparison_operator = 0 THEN &#8216;EQUAL&#8217;<br \/>\n          WHEN f.comparison_operator = 1 THEN &#8216;NOT EQUAL&#8217;<br \/>\n          WHEN f.comparison_operator = 2 THEN &#8216;GREATER THAN&#8217;<br \/>\n          WHEN f.comparison_operator = 3 THEN &#8216;LESS THAN&#8217;<br \/>\n          WHEN f.comparison_operator = 4 THEN &#8216;GREATER THAN OR EQUAL&#8217;<br \/>\n          WHEN f.comparison_operator = 5 THEN &#8216;LESS THAN OR EQUAL&#8217;<br \/>\n          WHEN f.comparison_operator = 6 THEN &#8216;LIKE&#8217;<br \/>\n          WHEN f.comparison_operator = 7 THEN &#8216;NOT LIKE&#8217;<br \/>\n     END comparison_operator,<br \/>\n     f.value<br \/>\nFROM sys.fn_trace_geteventinfo(@traceID) t<br \/>\nJOIN sys.trace_events e<br \/>\n     ON t.eventid = e.trace_event_id<br \/>\nJOIN sys.trace_columns c<br \/>\n     ON t.columnid = c.trace_column_id<br \/>\nLEFT OUTER JOIN sys.fn_trace_getfilterinfo(@traceID) f<br \/>\n     ON c.trace_column_id = f.columnid<br \/>\nORDER BY e.name, c.name;<br \/>\nGO<\/p>\n<p>Here is a subset of the output:<\/p>\n<figure id=\"attachment_1086\" aria-describedby=\"caption-attachment-1086\" style=\"width: 925px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace-3.jpg\"><img decoding=\"async\" class=\"size-large wp-image-1086\" src=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace-3-925x1024.jpg\" alt=\"Events, columns, and filters for a trace\" width=\"925\" height=\"1024\" srcset=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace-3-925x1024.jpg 925w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace-3-271x300.jpg 271w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace-3-768x850.jpg 768w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace-3.jpg 1108w\" sizes=\"(max-width: 925px) 100vw, 925px\" \/><\/a><figcaption id=\"caption-attachment-1086\" class=\"wp-caption-text\">Events, columns, and filters for a trace<\/figcaption><\/figure>\n<p>The good news is that there is a filter applied for the SP: StmtCompleted and SQL: StmtCompleted events.\u00a0 The not-so-good news is that the Showplan XML event is being captured.\u00a0 This event adds tremendous overhead to a system and is not recommended for a production environment.\u00a0 Now I really want to know who is running this trace.<\/p>\n<p>If you remember, back in the sys.traces output we had reader_spid, with a value of 78 for id = 3.\u00a0 We can take that and query sys.dm_exec_sessions to get more information:<\/p>\n<p>SELECT host_name, program_name, login_name<br \/>\nFROM sys.dm_exec_sessions<br \/>\nWHERE session_id = 78;<br \/>\nGO<\/p>\n<figure id=\"attachment_1087\" aria-describedby=\"caption-attachment-1087\" style=\"width: 817px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_4.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1087\" src=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_4.jpg\" alt=\"Output from sys.dm_exec_sessions\" width=\"817\" height=\"61\" srcset=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_4.jpg 817w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_4-300x22.jpg 300w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_4-768x57.jpg 768w\" sizes=\"(max-width: 817px) 100vw, 817px\" \/><\/a><figcaption id=\"caption-attachment-1087\" class=\"wp-caption-text\">Output from sys.dm_exec_sessions<\/figcaption><\/figure>\n<p>I now know the machine from which the rowset provider (in this case, Profiler) is running, and I know who is running it.\u00a0 I can also look through the ERRORLOG to see who last started a trace with that ID, but I&#8217;m lazy and the query is easier.\u00a0 In the ERRORLOG you will see a message:<\/p>\n<blockquote>\n<pre>SQL Trace ID 3 was started by login \"HEDWIG\\Erin\"<\/pre>\n<\/blockquote>\n<p>A similar message is added when the trace is stopped.<\/p>\n<h2>Summary<\/h2>\n<p>If SQL Trace is used in production environments, it is important to be able to identify not just what events are captured in a trace, but also the filters and to a lesser extent, the columns.\u00a0 The query above is the quickest way to determine the components of a trace, as they are not available in any UI.\u00a0 The exception is if you have started Profiler, and then you can only see the definition of the trace you have started.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yes&#8230;I&#8217;m writing a post about SQL Trace&#8230;specifically events in a trace. There are still lots of folks that use Profiler and run server-side traces, and when I work with those customers I like to understand how the traces are configured. I want to see what events are in a trace, but I also want to [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What Events are in a Trace? - Erin Stellato<\/title>\n<meta name=\"description\" content=\"This post will explain how to determine what events are in a trace that is already running, along with the columns collected and the filters being used.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What Events are in a Trace? - Erin Stellato\" \/>\n<meta property=\"og:description\" content=\"This post will explain how to determine what events are in a trace that is already running, along with the columns collected and the filters being used.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/\" \/>\n<meta property=\"og:site_name\" content=\"Erin Stellato\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-23T14:30:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-01-23T15:08:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_2-1024x84.jpg\" \/>\n<meta name=\"author\" content=\"Erin Stellato\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Erin Stellato\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/\",\"name\":\"What Events are in a Trace? - Erin Stellato\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#website\"},\"datePublished\":\"2020-01-23T14:30:56+00:00\",\"dateModified\":\"2020-01-23T15:08:29+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158\"},\"description\":\"This post will explain how to determine what events are in a trace that is already running, along with the columns collected and the filters being used.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What Events are in a Trace?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/\",\"name\":\"Erin Stellato\",\"description\":\"The SQL Sequel\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158\",\"name\":\"Erin Stellato\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0c8b485bd54ea26b57e99f79b525f409?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0c8b485bd54ea26b57e99f79b525f409?s=96&d=mm&r=g\",\"caption\":\"Erin Stellato\"},\"sameAs\":[\"http:\/\/3.209.169.194\/blogs\/erin\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/author\/erin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What Events are in a Trace? - Erin Stellato","description":"This post will explain how to determine what events are in a trace that is already running, along with the columns collected and the filters being used.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/","og_locale":"en_US","og_type":"article","og_title":"What Events are in a Trace? - Erin Stellato","og_description":"This post will explain how to determine what events are in a trace that is already running, along with the columns collected and the filters being used.","og_url":"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/","og_site_name":"Erin Stellato","article_published_time":"2020-01-23T14:30:56+00:00","article_modified_time":"2020-01-23T15:08:29+00:00","og_image":[{"url":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/01\/trace_2-1024x84.jpg"}],"author":"Erin Stellato","twitter_misc":{"Written by":"Erin Stellato","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/","url":"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/","name":"What Events are in a Trace? - Erin Stellato","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#website"},"datePublished":"2020-01-23T14:30:56+00:00","dateModified":"2020-01-23T15:08:29+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158"},"description":"This post will explain how to determine what events are in a trace that is already running, along with the columns collected and the filters being used.","breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/what-events-are-in-a-trace\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/erin\/"},{"@type":"ListItem","position":2,"name":"What Events are in a Trace?"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/erin\/","name":"Erin Stellato","description":"The SQL Sequel","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/erin\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158","name":"Erin Stellato","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0c8b485bd54ea26b57e99f79b525f409?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0c8b485bd54ea26b57e99f79b525f409?s=96&d=mm&r=g","caption":"Erin Stellato"},"sameAs":["http:\/\/3.209.169.194\/blogs\/erin"],"url":"https:\/\/www.sqlskills.com\/blogs\/erin\/author\/erin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/posts\/1083"}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/comments?post=1083"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/posts\/1083\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/media?parent=1083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/categories?post=1083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/tags?post=1083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}