temporalio / sdk-dotnet

Temporal .NET SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] OpenTelemetry support

cretz opened this issue · comments

Describe the solution you'd like

Need OpenTelemetry interceptor as separately published project

Sounds like a good idea. Do you have any design thoughts on this yet, I'm thinking about this too, I think it should be possible to do Spans, Tracing and Metrics.

Any ideas of what Metrics would be useful to track? Could we contribute on this one ?

This is only for tracing. OTel is already supported for metrics (you can create your own TemporalRuntime w/ metrics telemetry options set to an OTel gRPC URL and use it throughout the life of your application). https://docs.temporal.io/references/sdk-metrics are the metrics we track.

I have been working on the tracing part just this morning and I'll jot some notes down here. So it will be interceptor powered (like Python's, see https://github.com/temporalio/sdk-python/blob/main/temporalio/contrib/opentelemetry.py and https://github.com/temporalio/samples-python/tree/main/open_telemetry), but I am struggling with how best to split the project up.

So I was first thinking of a separate project for Temporalio.Extensions.OpenTelemetry, but since OTel support is basically just using https://learn.microsoft.com/en-us/dotnet/core/diagnostics/distributed-tracing, a more generic Temporalio.Extensions.Tracing project may make more sense (didn't want it part of main project because our oldest supported .NET versions would require System.Diagnostics.DiagnosticSource as an explicit dependency which I was wanting to avoid).

The problem I am at now is that I have to use https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs and https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Api/Context/Propagation/CompositeTextMapPropagator.cs to serialize spans to Temporal headers that are compatible with other languages who have OTel too. I am digging into if I can use .NET's DistributedContextPropagator easily without making the user do too much work or if I am going to need to make OTel helpers for them and therefore an OTel specific project again.

Active research is ongoing.

@johnkattenhorn - Maybe you can help me here. I have restored an activity context and baggage via propagation similar to this. This has the ActivityContext but there's no way I see to attach current context in OpenTelemetry terms given the ActivityContext only. Other OTel SDKs let me set the "current" context, but .NET only allows the "current" activity and I don't want to create a new activity with the parent, I just want to restore the parent to "current". Any ideas?

Oh man sound like it works like AppInsights, inthink we had to recreate the activity as you could only set the parentID in the constructor and copy everything across.

I'm going to ask someone from our team but just boarding a flight back to the UK so might be a delay.

Thanks! Definitely no rush (can be days/weeks, don't waste weekend time). I also have a question out on #otel-dotnet on CNCF Slack. I am sure I'm just missing something. Maybe that's what I have to do is create the activity and just set all the fields I can and know about and set it as Activity.Current.