-
Notifications
You must be signed in to change notification settings - Fork 147
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 HttpModule: Fix bug when adding to web.config #584
AspNet HttpModule: Fix bug when adding to web.config #584
Conversation
… Currently, going to the root '/' causes both the DatadogModule and the CustomLoggingModule to run twice.
…t and still operate correctly. Only creates the trace on the first OnBegin and ends the trace on the last OnEnd or OnError. Small fix Another small fix Last small fix OMG last small fix I swear
…n simultaneously handle adding the module both statically and dynamically.
…rst HttpModule invoked and only respond to the callbacks with that object instance.
@@ -72,6 +74,13 @@ private void OnBeginRequest(object sender, EventArgs eventArgs) | |||
return; | |||
} | |||
|
|||
// Only one HttpModule will respond to ASP.NET lifecycle events | |||
// Do nothing if another HttpModule has already been run | |||
if (httpContext.Items[_httpContextOwningModuleKey] is TracingHttpModule) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this accounts for it not being in the Items list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. If the key is not present, then the Items
lookup will return null, and a null value will cause the is
check to return false
. I thought to follow the previous convention with this style of check, but would there be another way to express this concisely?
…t handlers for one TracingHttpModule per HttpApplication object.
The previous implementation of the HttpModule did not behave correctly when it was invoked more than once in one ASP.NET request. Multiple scopes would be created and only the innermost one would be closed, so the root span would not be closed and the Datadog UI would show no traces. The new implementation registers the first HttpModule to hit the event handlers as the only one allowed to create/modify Scope objects, so only one scope is created and closed. This fix is important to support customers who have other HttpModules in their system web.config that subscribe to the BeginRequest and would like our Tracer to start spans before hitting them. As a result, the customer will enter our HttpModule before the other HttpModule's in their web.config which causes our the ASP.NET application to create and invoke two instances of our HttpModule: once from the web.config declaration and once from the dynamic module after referencing our NuGet package.
Changes proposed in this pull request:
The previous implementation of the HttpModule did not behave correctly when it was invoked more than once in one ASP.NET request. Multiple scopes would be created and only the innermost one would be closed, so the root span would not be closed and the Datadog UI would show no traces. The new implementation registers the first HttpModule to hit the event handlers as the only one allowed to create/modify
Scope
objects, so only one scope is created and closed.This fix is important to support customers who have other HttpModules in their system
web.config
that subscribe to theBeginRequest
and would like our Tracer to start spans before hitting them. As a result, the customer will enter our HttpModule before the other HttpModule's in theirweb.config
which causes our the ASP.NET application to create and invoke two instances of our HttpModule: once from theweb.config
declaration and once from the dynamic module after referencing our NuGet package.@DataDog/apm-dotnet