EventSource trace with correlated activity id

I started using ETW and the incomplete semantic registration block from Entlib 6. When I use async / await, CurrentThreadActivityId is not set in the continuation thread, and the TPL system does not register the transfer event. This makes it difficult to perform end-to-end tracing.

According to Microsoft documentation, the TPL platform should register the transfer event and generate a new activityid, but I cannot get it to work.

Entlib 6 Documentation

Here is a small example showing the problem:

To log TPL events, I use the following:

<eventSource name="System.Threading.Tasks.TplEventSource" level="Informational" matchAnyKeyword="1"/>

And here is my test code:

using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AsyncContextTest
{
    class Program
    {
        static Guid _activityId = Guid.NewGuid();

        static void Main(string[] args)
        {
            EventSource.SetCurrentThreadActivityId(_activityId);
            Console.WriteLine(EventSource.CurrentThreadActivityId);
            Task t = Task.Run(async () => await DoStuffAsync());
            Console.WriteLine(EventSource.CurrentThreadActivityId);

            Console.Read();
        }

        public static async Task DoStuffAsync()
        {
            var x = "one,two,three".Split(',');
            Console.WriteLine(EventSource.CurrentThreadActivityId);
            await Task.Delay(1000);
            Console.WriteLine(EventSource.CurrentThreadActivityId);
            var y = String.Join(",", x);

            Console.WriteLine("Done");

        }
    }
}

results

334540cc-ccb1-4196-8587-815abf237e4c
334540cc-ccb1-4196-8587-815abf237e4c
00000000-0000-0000-0000-000000000000
00000000-0000-0000-0000-000000000000
Done

Does anyone have a simple example showing the correct way to do end-to-end tracing with ETW and async / wait?

EDIT:

, . TPL .

+4
1

, GUID .

<eventSource id="2e5dba47-a3d2-4d16-8ee0-6671ffdcd7b5" level="Informational" />

:

605e615a-c849-4ee7-95b8-e6677f945c3f
605e615a-c849-4ee7-95b8-e6677f945c3f
00000001-0001-0000-0c22-0000ffdcd7b5
00000002-0001-0000-0c22-0000ffdcd7b5
Done

- , ETW /?

...

0

All Articles