opentelemetry-dotnet-contrib
opentelemetry-dotnet-contrib copied to clipboard
B3Format extract creates an ActivityContext with default id when not passed in the request
Describe your environment. Describe any aspect of your environment relevant to the problem:
- SDK version: 0.0.0-alpha.428 of OpenTelemetry.Exporter.Zipkin, OpenTelemetry.Extensions.Hosting, OpenTelemetry.Instrumentation.AspNetCore, OpenTelemetry.Instrumentation.Dependencies
- .NET runtime version (.NET or .NET Core, TargetFramework in the .csproj file): .netcore 2.1
- Platform and OS version: macOs 10.14.5
I've set up the aspnetcore instrumentation on netcoreapp2.1 with the following in Startup.cs
services.AddOpenTelemetry((builder) =>
builder
.AddRequestInstrumentation((options) => { options.TextFormat = new B3Format(); })
.UseZipkinExporter((o) =>
{
o.ServiceName = "service-name;
o.Endpoint = new Uri("http://some-zipkin");
})
);
While testing a request I noticed that the activity was given a SpanId of 0000000000000000
and TraceId of 00000000000000000000000000000000
. It seems like when the HttpInListener
detects a Request assembly with a major version < 3, the TextFormat
option is used to pull the trace id's out from the http request headers and create a new ActivityContext. However, if these are not set in the request we end up with default id's of all 0's.
This seems to be caused by this line in the B3Format Extract function that returns RemoteInvalidContext.
I would expect these id's to be generated when not set on the HttpRequest, denoting a call made to an edge service and starting a new Trace.
Steps to reproduce. Setup an aspnetcore 2.1 server with the following in Startup.cs
services.AddOpenTelemetry((builder) =>
builder
.AddRequestInstrumentation((options) => { options.TextFormat = new B3Format(); })
.UseZipkinExporter((o) =>
{
o.ServiceName = "service-name;
o.Endpoint = new Uri("http://some-zipkin");
})
);
Make an httpRequest to the server without the X-B3-TraceId
and X-B3-SpanId
headers sent.
See trace sent to zipkin with default SpanId and TraceId
What is the expected behavior? New TraceId and SpanId generated by the sdk.
What is the actual behavior? Default ids