Closed gfournierflinks closed 1 year ago
By default ASP.NET Core is using tracecontext
propagator to inject/extract information about span context.
Your DummyWebApp
does not have any any telemetry listener, but AspNetCore Activities are created and marked as non-registered. That information is propagated by http headers in the request to the DummyAPI.
What is more OpenTelemetry by default is using new ParentBasedSampler(new AlwaysOnSampler())
. That means if you do not have parent based information - sample always. If you have it, respect sampling decision from the parent.
It can be overriten by in your DummyAPI package.
builder.Services
.AddOpenTelemetry()
.WithTracing(b => b
.SetSampler(new AlwaysOnSampler())
.AddAspNetCoreInstrumentation()
.AddConsoleExporter())
.StartWithHost();
After changes, call from DummyWebApp to DummyAPI (Activity.ParentSpanId is recorded) Activity.TraceId: 7aae8aede8340bdb938494b67f3b8f90 Activity.SpanId: 0bbf4f827511a35b Activity.TraceFlags: Recorded Activity.ParentSpanId: 3552debb27e61051 Activity.ActivitySourceName: OpenTelemetry.Instrumentation.AspNetCore Activity.DisplayName: WeatherForecast Activity.Kind: Server Activity.StartTime: 2023-01-12T06:15:56.8224144Z Activity.Duration: 00:00:00.0235171 Activity.Tags: net.host.name: localhost net.host.port: 7077 http.method: GET http.scheme: https http.target: /WeatherForecast http.url: https://localhost:7077/WeatherForecast http.flavor: 1.1 http.route: WeatherForecast http.status_code: 200 Resource associated with Activity: service.name: unknown_service:DummyAPI
After changes, call from broswer/console app to DummyAPI (Activity.ParentSpanId is not available) Activity.TraceId: 98ba9b17b1aac2c344ad49615fe8db95 Activity.SpanId: 7978f2606e469f39 Activity.TraceFlags: Recorded Activity.ActivitySourceName: OpenTelemetry.Instrumentation.AspNetCore Activity.DisplayName: WeatherForecast Activity.Kind: Server Activity.StartTime: 2023-01-12T06:16:00.8129651Z Activity.Duration: 00:00:00.0212744 Activity.Tags: net.host.name: localhost net.host.port: 7077 http.method: GET http.scheme: https http.target: /WeatherForecast http.url: https://localhost:7077/WeatherForecast http.flavor: 2.0 http.user_agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 http.route: WeatherForecast http.status_code: 200 Resource associated with Activity: service.name: unknown_service:DummyAPI
I would say, that it is not a bug, rather a feature.
It works well with
.SetSampler(new AlwaysOnSampler())
Thanks!
Bug Report
Symptom
Describe the bug In the context where OpenTelemetry is configure to add AspNetCore Instrumentation, if another web app is making a server to server call to the traced API, a trace is not generated. See Steps to reproduce for all the details.
I followed the instructions here https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Instrumentation.AspNetCore/README.md
Expected behavior All traces should be generated
Runtime environment (please complete the following information):
Reproduce
Steps to reproduce the behavior:
I join the code of a very simple API called DummyAPI (see zip files attached). The solution contains 3 projects:
The dummy API uses the following dependencies:
The DummyAPI is configured as such in the Program.cs:
The only endpoint of the dummy API is a GET /WeatherForecast
The API can we called in 3 different ways :
When testing from the browser, a trace is exported to the console. When testing from the ConsoleApp, a trace is exported to the console. However, when testing with the DummyWebApp, a trace is NOT exported to the console
Inspecting the System.Diagnostics.Activity.Current when calling via the DummyWebApp, I see this:
Comparing when It's called from the browser:
In the case of calling the DummyAPI via the DummyWebApp, the System.Diagnostics.Activity.Source doesn't seem to be set properly:
Compared to when the DummyAPI is called via the browser:
Am I missing something? DummyAPI.zip