open-telemetry / opentelemetry-dotnet-contrib

This repository contains set of components extending functionality of the OpenTelemetry .NET SDK. Instrumentation libraries, exporters, and other components can find their home here.
https://opentelemetry.io
Apache License 2.0
474 stars 283 forks source link

[bug] No traces for AspNetCore instrumentation when AppService has CORS turned ON (traceparent header exists) #2206

Open wallyrion opened 1 month ago

wallyrion commented 1 month ago

Component

OpenTelemetry.Instrumentation.AspNetCore

Package Version

Package Name Version
OpenTelemetry.Instrumentation.AspNetCore 1.9.0
OpenTelemetry 1.9.0
OpenTelemetry.Exporter.OpenTelemetryProtocol 1.9.0

Runtime Version

net8.0

Description

When deploying an application to Azure App Service with CORS enabled, traces generated by OpenTelemetry.Instrumentation.AspNetCore are not being created. Changing the exporter has no effect on this behavior. However, traces from other sources, such as EntityFrameworkCore and HttpClient instrumentation, are successfully exported.

The key difference between requests when CORS is enabled versus disabled in App Service is the presence of the traceparent header (e.g., traceparent: 00-63beafd20fc56a364971ebee560f6e9c-ad151c22e8fbe470-00). This header seems to be the likely cause of the missing traces when CORS is active.

Steps to Reproduce

When CORS is enabled, additional headers are introduced: traceparent: 00-63beafd20fc56a364971ebee560f6e9c-ad151c22e8fbe470-00 Content-Length: 0

You can see my sample app here https://github.com/wallyrion/OpenTelemetry.AppService.CorsIssue

Expected Result

I'm not sure about the expected behaviour here.

Actual Result

Http traces are not created and this is not obvious at all.

Additional Context

No response

TimothyMothra commented 3 weeks ago

HI @wallyrion,

  1. Can you confirm that Traces are collected in your app when CORS is disabled?
  2. With CORS enabled, can you please collect the Self-Diagnostics. We need to review what errors are occuring. https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry/README.md#troubleshooting
wallyrion commented 3 weeks ago

Hi @TimothyMothra

  1. I can confirm that Traces are collected when CORS is disabled
  2. I've done this, but looks useless imho logs_when_cors_is_enabled.zip