Dynatrace / OneAgent-SDK-for-dotnet

Enables custom tracing of .NET applications in Dynatrace
https://www.dynatrace.com/support/help/extend-dynatrace/oneagent-sdk/what-is-oneagent-sdk/
Apache License 2.0
19 stars 3 forks source link

Tracing async WCF calls #28

Closed BaterPL closed 8 months ago

BaterPL commented 1 year ago

Hi,

I have a question about tracing async calls to the WCF server. For some time now we were using IClientMessageInspector to track requests, starting trace and adding dynatrace header in BeforeSendRequest and stopping tracer in AfterReceiveReply. It works perfectly fine for synchronous API, but for asynchronous the behavior is unpredictable. I've read in readme that Start/End is not supposed to be used in async flow, so I expect it to cause that issue as BeforeSendRequest and AfterReceiveReply might be performed on different threads.

I know you provide TrackAsync method, but it's not possible to wrap these two methods mentioned above, as they are invoked by WCF. How should I approach this problem?

Oberon00 commented 12 months ago

So basically you get two separate callback invocations but you want them to logically belong to the same operation? Unfortunately, that is not supported by the SDK. You might have more luck with OpenTelemetry/System.Diagnostics.Activity: https://docs.dynatrace.com/docs/shortlink/otel-wt-dotnet

If you want to keep using the SDK for this, consider tracing them separately and maybe using an in-process link tracer between them (assuming there isn't already a span/trace node active in AfterReceiveReply.