Dotnet: OpenTelemetry, connect two scopes

631 views Asked by At

I have three services running on .Net with OpenTelemetry tracing enabled. Communication begins from the first service to the second one via HttpClient. Second service handle http request and add work item to its own queued background service. This work item makes http request to the third service.

Traces are exported to Jaeger.

I checked traceparent header on the second and third services and they are different.

I think this happened because the second service make http request in background in different scope. (new scope created for each work item) How can I connect such activity to see the entire communication in one trace?

I tried to create new activity inside work item lambda and set parent activity id but it didn't help.

1

There are 1 answers

0
Chen On

Where do you set parent activity id? Did you use the Activity.SetParentId method? According to this document:

This method is only intended for use with Activities created from the Activity constructor. Activities created by calling CreateActivity or StartActivity already have the parent ID set, and invoking this method has no effect.

This method should only be used before starting the Activity object. This method has no effect if you call it after the Activity object has started.

Not sure how your code is structured, but I refer to the example in this GitHub Issue and it works, you can check it. Here is the code.