Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B3Format extract creates an ActivityContext with default id when not passed in the request #1750

Open
christopher-taormina-zocdoc opened this issue Jul 22, 2020 · 1 comment
Labels
bug Something isn't working comp:instrumentation.aspnetcore Things related to OpenTelemetry.Instrumentation.AspNetCore

Comments

@christopher-taormina-zocdoc

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

@christopher-taormina-zocdoc christopher-taormina-zocdoc added the bug Something isn't working label Jul 22, 2020
@eddynaka
Copy link
Contributor

@christopher-taormina-zocdoc , I debugged the application and yes, if you don't pass in the header X-B3-TraceId OR X-B3-SpanId, we will generate a Default value, so TraceId and SpanId will be zero.

@cijothomas , is that expected?

https://github.com/open-telemetry/opentelemetry-dotnet/blob/cbe99df381f1f1b8c05825b509486ad81dd9f3f2/src/OpenTelemetry/Context/Propagation/B3Format.cs#L185-L210

@reyang reyang transferred this issue from open-telemetry/opentelemetry-dotnet May 13, 2024
@reyang reyang added the comp:instrumentation.aspnetcore Things related to OpenTelemetry.Instrumentation.AspNetCore label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working comp:instrumentation.aspnetcore Things related to OpenTelemetry.Instrumentation.AspNetCore
Projects
None yet
Development

No branches or pull requests

3 participants