[Instrumentation.AspNet] Fix activity being closed before processing completes - #1388
Conversation
|
@qhris, please sign CLA, it is hard requirement to proceed with PR. Please let us know if you have any issue with the procedure. |
|
@Kielek I had missed the CLA requirement as I submitted the PR. I have no idea how that works so I'll look it over tomorrow since I wasn't prepared having to sign something with my physical address... In regards to the changes: Something that struck me is that this will be a breaking change as it changes the order of the processor's |
|
Did some additional testing this morning comparing the flow to a .NET 7 application. I used In the .NET 7 application we have the following flow:
The .NET Framework application (pre-patch) has the following behavior:
This PR would bring the implementations in line between .NET and .NET Framework by swapping items 6 and 7 for .NET Framework. |
67cdb50 to
488d2ac
Compare
The ASP.NET Core behavior is correct and this fix for asp.net is correct! Thanks. |
Codecov Report
@@ Coverage Diff @@
## main #1388 +/- ##
==========================================
+ Coverage 73.91% 80.06% +6.15%
==========================================
Files 267 160 -107
Lines 9615 4450 -5165
==========================================
- Hits 7107 3563 -3544
+ Misses 2508 887 -1621
Flags with carried forward coverage won't be shown. Click here to find out more.
|
cijothomas
left a comment
There was a problem hiding this comment.
LGTM with a changelog entry!
Thanks for your contribution!
|
|
||
| ## Unreleased | ||
|
|
||
| * Release together with `OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule`. |
There was a problem hiding this comment.
You can remove this line. These two packages are always released together.
|
@qhris Thanks for fixing the issue. You can use the |
|
@qhris This change has a side effect of broken metrics instrumentation. Now that the activity is stopped after the onStopCallBack is fired, the activity.Duration would always result in |
|
@vishweshbankwar thanks for letting me know, I'll take a look to reproduce and I'll submit a fix for it. |
Fixes #1138.
Findings
This PR implements the fix suggested by @jdaigle.
I have tested this on an a .NET Framework 4.8 ASP MVC application I've been maintaining.
I ran into this issue trying to modify the span name to be prefixed by the http method as recommended by the spec. The problem I ran into was the
HttpInListeneroverriding whatever changes the processor made to the span name.It also seems odd to me that the activity is closed and then updated (through
HttpInListener.OnStopActivity). I think there is a race condition with exporters here. I was able to trigger this by setting a breakpoint beforeonRequestStoppedCallbackis called; sometimes the exported span would have the pre-callback display name and sometimes it would have the post-callback display name. This is due to the exporters being processors, and processors are triggered on stopping the activity (?). This of course depends on you're using the simple exporter or a batched one.This is how I think it works (pre-patch):
aspNetActivity.Stop()is called.HttpInListener.OnStopActivityis called (throughonRequestStoppedCallback.I'm still pretty new to OTEL in dotnet, so I might be missing something here, but this seems like a problem to me.
Questions
content.Items[ContextKey] = nullbe moved as well, as the context is cleared out now beforeasnNetActivity.Stop()is called?Changes
This changes the point at which the activity is stopped to after the
onRequestStoppedCallbackfunction is called.For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes