-
Notifications
You must be signed in to change notification settings - Fork 786
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
(AspNet.TelemetryHttpModule) Activity.Current not restored before all IIS LifeCycle events #3286
(AspNet.TelemetryHttpModule) Activity.Current not restored before all IIS LifeCycle events #3286
Comments
I believe this could be resolved by changing this line Lines 88 to 91 in 55c5dd1
to if (!context.IsPostNotification)
{
ActivityHelper.RestoreContextIfNeeded(context.ApplicationInstance.Context);
} |
So that rule is just something we carried over from the original version here: https://github.com/aspnet/Microsoft.AspNet.TelemetryCorrelation/blob/50f0acb7a0cb164d834eb91b839959a841577302/src/Microsoft.AspNet.TelemetryCorrelation/TelemetryCorrelationHttpModule.cs#L84 I don't think anyone is opposed to changing it. Could you possibly share a small repo that reproduces the problem so I can take it for a spin? |
Thanks @CodeBlanch I've setup a minimum reproduction here https://github.com/chris-smith-zocdoc/OtelSample You should be able to open the solution and hit F5 to run under IIS Express to see this easily. Set a breakpoint on https://github.com/chris-smith-zocdoc/OtelSample/blob/master/Global.asax.cs#L39 |
@chris-smith-zocdoc Thanks for that code, very helpful! I took it for a spin, here's my findings... It is a bit more complicated than simply removing The order of events firing in
That last line is the important one. Even if we call the restore code, the Activity has been stopped so there is nothing to restore 🤣 We could move the stop to the |
@CodeBlanch that may be true for
So I think there are two decisions here:
|
@CodeBlanch I opened open-telemetry/opentelemetry-dotnet-contrib#761 to restore the context before all events |
Bug Report
Activity.Current
lost in some IIS lifecycle eventsWe have a custom
HttpApplication
with handlers for most IIS lifecycle events. These events can start child spans (mostly sql) that should be attached to the current request trace. For a percentage of the IIS lifecycle events, we are seeing traces that don't appear to be properly restoringActivity.Current
, causing child spans to start their own trace.Runtime version
net48
Symptom
I believe Activity.Current is null
What is the expected behavior?
Activities started in IIS lifecycle methods should be attached to the request trace to which they belong
What is the actual behavior?
The Activities are orphaned, creating single span traces.
Additional Context
We aren't seeing this in all lifecycle events, only some of them and only a certain percentage of the time.
Here is the approximate percentage of time we're seeing this occur by lifecycle method. It happens most frequently in
PreSendRequestHeaders
(nearly every time)Unaffected
Affected by the bug
How are we tracking this? We have a custom span processor that adds the current lifecycle method to each span by reading it from HttpContext.Items
The text was updated successfully, but these errors were encountered: