You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found an issue with using async handlers in IHttpModule that causes correlation (Activity.Current) to be completely lost in any handlers that are called after the async handler has been called.
The issue seems to be caused by the legacy Asynchronous Programming Model (APM) that Http Modules use, which doesn't seem to propagate ExecutionContext.
It only occurs with async handlers. Synchronous handlers, even when using the APM model propagate ExecutionContext and Activity.Current correctly.
This is an example module that reproduces the problem. To run it, just add this HttpModule to any empty .NET application with the Application Insights Web SDK installed, then send requests to it and watch the Debug output.
I would expect that the second log entry would also have a valid System.Diagnostics.Activity, but it's null. If you replace the postAuthenticate handler with a synchronous method, then the Activity is propagated down to the postAuthorize handler as expected, so it appears to only be an issue with async handler chains.
The unfortunate result of Activity being wiped is that any dependency calls I make in the second handler don't have any correlation context, no operation_ParentId and different operation_Id values for each dependency.
I wonder why there isn't any comment on this thread in more than 2 years. I guess I have run into a similar problem. The only difference is that my own module (which has async handlers) comes before the TelemetryHttpModule. Any activity that gets created in my custom module does not get propagated to the Telemetry module.
I've found an issue with using async handlers in IHttpModule that causes correlation (Activity.Current) to be completely lost in any handlers that are called after the async handler has been called.
The issue seems to be caused by the legacy Asynchronous Programming Model (APM) that Http Modules use, which doesn't seem to propagate ExecutionContext.
It only occurs with async handlers. Synchronous handlers, even when using the APM model propagate ExecutionContext and Activity.Current correctly.
This is an example module that reproduces the problem. To run it, just add this HttpModule to any empty .NET application with the Application Insights Web SDK installed, then send requests to it and watch the Debug output.
When I run this, it produces the following:
DependencyTrackingHandler Activity: System.Diagnostics.Activity
DependencyTrackingHandler Activity:
I would expect that the second log entry would also have a valid System.Diagnostics.Activity, but it's null. If you replace the postAuthenticate handler with a synchronous method, then the Activity is propagated down to the postAuthorize handler as expected, so it appears to only be an issue with async handler chains.
The unfortunate result of Activity being wiped is that any dependency calls I make in the second handler don't have any correlation context, no operation_ParentId and different operation_Id values for each dependency.
The text was updated successfully, but these errors were encountered: