-
I have a project that wants to use the AddOpenTelemetryTracing() builder function with the AddOtlpExporter to output data to Jeager. There's an AddSource where you can add a source by string name and another function to create a default source with a name. These appear to create sources I can access with TracerProvider.Default.GetTracer but they aren't the same as the System.Diagnostics.ActivitySource from MS. Is there a way to add the ActivitySource to the builder so that Activities can flow to the OpenTelemetry tracer? See this discussion for some information. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
opentelemetry-dotnet/src/OpenTelemetry.Api/Trace/TracerProvider.cs Lines 44 to 52 in d74ac9e We've created these wrapper APIs simply to provide an API that is more closely aligned with the terminology from the OpenTelemetry specification. Some people find this more comfortable. However, the recommendation is to just
Yes, you do so by using the name of the const string MyActivitySourceName = "MySource";
// Configure OpenTelemetry tracing
services.AddOpenTelemetryTracing(options =>
{
options
.AddSource(MyActivitySourceName)
.AddOtlpExporter(...);
}
// Then elsewhere in your code
var activitySource = new ActivitySource(MyActivitySourceName);
// This Activity will be created and exported
using (var activity = activitySource.StartActivity("MyActivity"))
{
...
} |
Beta Was this translation helpful? Give feedback.
-
So I finally figured out the issue, I was already doing like you said as far as the ActivitySources are concerned. Though I don't really understand the reason that there's no overload to provide the ActivitySource reference. The underlying problem I was having is I'm not using StartActivity in the simple way since I want to add the ActivityContext to the event with the trace id that I'm setting. The ActivityContext needs to have the ActivityTraceFlags set to ActivityTraceFlags.Recorded or the event does not flow out of the AddOtlpExporter. When you do StartActivity(string) it appears that this is not an issue. |
Beta Was this translation helpful? Give feedback.
So I finally figured out the issue, I was already doing like you said as far as the ActivitySources are concerned. Though I don't really understand the reason that there's no overload to provide the ActivitySource reference. The underlying problem I was having is I'm not using StartActivity in the simple way since I want to add the ActivityContext to the event with the trace id that I'm setting. The ActivityContext needs to have the ActivityTraceFlags set to ActivityTraceFlags.Recorded or the event does not flow out of the AddOtlpExporter. When you do StartActivity(string) it appears that this is not an issue.