skip to Main Content

I am trying to apply OpenTelemetry tracing to my project,
and I have some claims to tracing the logic.

My question is – is there a way to get an activity or a span by some attribute,
for example GetActivityByParentId.

I have 2 systems, that sending requests to each other and I want to put some Id from one system to be able to get an activity by this Id from another system to continue adding info in Activity.

Referring to https://opentelemetry.io/docs/languages/net/instrumentation/ there is no such method.

If I am not mistaken, current implementation provide only Add methods.

Can anyone provide some examples ?

2

Answers


  1. Chosen as BEST ANSWER

    So I've found out that it's possible to extract parent context providing parent id and trace state to ActivityContext.TryParse("","", out var context); method.

    It allows to trace additional info to previous traces to keep it in one hierarchy.

    Next step after you gget the parent activity context is to create a new one using it:

    using (var childActivity = aSource.StartActivity(ActivityKind.Producer, context, tags, links, DateTime.Now, "another additional activity"))
        {
             childActivity?.AddTag("dicelib.rolled", 1);
        }
    

  2. As part of tracing (beyond OpenTelemetry) each system will generate and send spans to the backend independently. The only part of the Span/Activity that the downstream system knows about is the SpanId and the TraceId, and those are purely so that they’re added to the new spans in that downstream/child system so that you can correlate them.

    You can pass data from the Upstream/source system to the child systems using a mechanism called "Baggage", however you can’t pass it upstream. This is because that span could have been already sent to the backend platform by the time you try to add something.

    Most modern platforms allow you to solve this in the backend by allowing you to query at the "trace" level, rather than at the individual Span/Activity level.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search