-
Notifications
You must be signed in to change notification settings - Fork 17
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
Create single activity for rewrite rule #74
Conversation
src/Microsoft.AspNet.TelemetryCorrelation/TelemetryCorrelationHttpModule.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNet.TelemetryCorrelation/TelemetryCorrelationHttpModule.cs
Outdated
Show resolved
Hide resolved
} | ||
else | ||
{ | ||
// Rewrite: In case of rewrite, a new request context is created, called the child request, and it goes through the entire IIS/ASP.NET integrated pipeline. |
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.
ideally somebody from asp.net team needs to comment on any other situation this may have happened. I can think of one off the top of my head - if there is another module registered before this module and it returned 401
or some actual content from the BeginRequest call. Than Begin will not be called for this module at all. And we will end up loosing the fact of this call.
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.
Specifically for UrlRewrite, @TimothyMothra was working on logic that ensured that those will be parented to each other. This logic is somewhere in Application Insights http module. I wonder if this is a different case or the same
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.
@SergeyKanzhelev, @TimothyMothra has worked on a change in application insights where parent and child request has same HttpContext. In this scenario, HttpContext generated at parent and child are different. I internally worked with IIS engineering team to check for the scenarios and came up with this change.
I will investigate the 401 error.
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.
- Created new HttpModule and registered before TelemetryCorrelationHttpModule in pipeline
<modules>
<add name="One" type="WebApplication1.MyHttpModule1"/>
<add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="managedHandler"/>
</modules>
- Added below code to BeginRequest of custom module to respond with HTTP 401.
private void Application_BeginRequest(object sender, EventArgs e)
{
var context = ((HttpApplication)sender).Context;
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
}
Requested got executed in below order and Activity got created
- MyHttpModule1.BeginRequest
- TelemetryCorrelationHttpModule.BeginRequest
- MyHttpModule1.EndRequest
- TelemetryCorrelationHttpModule.EndRequest
Will check if we could get someone from ASP.NET team to review this one.
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.
try to end the response after setting the status. Otherwise the module doesn't actually behave as authentication module as it continues an execution.
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.
Commented
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.
LGTM and it meets with the recommendation we've got from ASP.NET team.
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.
LGTM.
Addressing Issue #73
Changes
(Please provide a brief description of the changes here.)
Modified EndRequest in TelemetryCorrelationHttpModule to skip activity creation for rewrite generated parent request.
Background Information
Initial version of the TelemetryCorrelationHttpModule had this activity creation within Application_Error and later moved to EndRequest.
https://github.com/aspnet/Microsoft.AspNet.TelemetryCorrelation/pull/1/files
https://github.com/aspnet/Microsoft.AspNet.TelemetryCorrelation/blob/cc1592d241fee1df40442790fddf7779c787e838/src/Microsoft.AspNet.Diagnostics/DiagnosticsHttpModule.cs
#2
https://github.com/aspnet/Microsoft.AspNet.TelemetryCorrelation/blob/c0c6b8ce9e3f371c6012a2646e4a5f253fcaea41/src/Microsoft.AspNet.Diagnostics/DiagnosticsHttpModule.cs
Notes from PR