orleans icon indicating copy to clipboard operation
orleans copied to clipboard

Trace Context not propagated unless source for Microsoft.Orleans.* has been added

Open mkstephenson opened this issue 1 year ago • 3 comments

I have been playing around with OpenTelemetry tracing and Orleans and found that unless you instruct the OpenTelemetry SDK to listen to the trace source "Microsoft.Orleans.*" (well, I have a * there, I'm sure you can have a more precise name there), the parent activity is not propagated to child activities across Orleans calls and remains null. This means that you can't choose to "just" instrument your own code, you must also add the Orleans source if you wish to have connected spans in Open Telemetry.

I am not sure if this is by design or not, but if it was, I wasn't able to find anything in the documentation related to this caveat. Would it be possible to add a note to the documentation if this is intended behaviour?

I am using 8.2.0 of the Microsoft.Orleans.Server package for reference and starting the application/tracing through an Aspire project.

mkstephenson avatar Oct 16 '24 21:10 mkstephenson

Hi @mkstephenson, I don't quite understand - how should this behave?

ReubenBond avatar Oct 16 '24 23:10 ReubenBond

Ah sorry, I forgot to mention the important bit that the parent is not propagated, even if AddActivityPropagation() has been called on the silo.

I think the behaviour is correct, but because Orleans handles all grain calls without the caller knowing its internals, it is not obvious that the parent Activity is not forwarded unless the Microsoft.Orleans namespace has been added to the OpenTelemetry tracing sources. Therefore I was wondering if we could expand the documentation to highlight this. It should hopefully save some other developers a bit of headscratching when they puzzle why the parent is null, even though they activated ActivityPropagation.

mkstephenson avatar Oct 17 '24 06:10 mkstephenson

I think the official docs already well described how to enable it. https://learn.microsoft.com/en-us/dotnet/orleans/host/monitoring/?pivots=orleans-7-0

builder.Services.AddOpenTelemetry()
    .WithTracing(tracing =>
    {
        // Set a service name
        tracing.SetResourceBuilder(
            ResourceBuilder.CreateDefault()
                .AddService(serviceName: "GPSTracker", serviceVersion: "1.0"));

        tracing.AddSource("Microsoft.Orleans.Runtime");
        tracing.AddSource("Microsoft.Orleans.Application");

        tracing.AddZipkinExporter(zipkin =>
        {
            zipkin.Endpoint = new Uri("http://localhost:9411/api/v2/spans");
        });
    });

scalalang2 avatar Oct 21 '24 00:10 scalalang2

While it does contain the important namespace to trace in the example, it does not mention the importance of the namespaces and why those two should be included to ensure that all other tracing works. Because the Microsoft.Orleans namespace has been used as a demonstration namespace in the other examples on the page, reading it makes you think that the namespaces in the example were not chosen for a particular reason, rather than, if you exclude these, no distributed tracing will work at all.

mkstephenson avatar Oct 21 '24 06:10 mkstephenson

If you could point out the examples for tracing using just Microsoft.Orleans (no * or Runtime/Appication), then those can get corrected.

rkargMsft avatar Oct 21 '24 16:10 rkargMsft

Ah, I see now that there are no other examples for tracing (there's just that one small code snippet), just the meters (which are all under the Microsoft.Orleans namespace).

mkstephenson avatar Oct 21 '24 17:10 mkstephenson