Skip to content
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

New design for TelemetryHttpModule using ActivitySource + OpenTelemetry.API part 3 #2256

Conversation

CodeBlanch
Copy link
Member

Relates to #2249

Changes

  • Moved TelemetryHttpModule options to their own class and exposed as a static. See below.
  • Updated ASP.NET instrumentation to use the new TelemetryHttpModule. We no longer need to create extra Activity instances just to switch propagation! 🥂
  • Added RecordException option in ASP.NET instrumentation. The one thing I set out to do that spawned all of this 😄

Notes & interesting lessons learned

Turns out there is no single instance of HttpApplication and HttpModules aren't singletons. Check it out:

https://github.com/microsoft/referencesource/blob/5697c29004a34d80acdaf5742d7e699022c64ecd/System.Web/HttpApplicationFactory.cs#L67-L71

There are two different bags of HttpApplications. The "special" ones are for application-level events (ex Application_Start). The "free" ones are created/re-used for each request and are sent request-level events (ex Begin_Request). This makes it much more difficult than I anticipated to find the TelemetryHttpModule and attach callbacks for instrumentation. I ended up just adding a static for the options. Not the most elegant solution but probably the least code. We could try to hook into HttpApplicationFactory with reflection and monkey patch in some code to call us anytime an HttpApplication is created/re-used.

@CodeBlanch CodeBlanch requested a review from a team August 13, 2021 20:11
Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

{
return uri.ToString();
activity.SetStatus(Status.Error);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cijothomas @alanwest Check this out. In the case of exception thrown when !activity.IsAllDataRequested I thought we should still at least mark the status as Error. What you guys think about that?

I'll do the same for AspNetCore if we all agree this is desired:

public override void OnException(Activity activity, object payload)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up removing this. Turns out anything with !activity.IsAllDataRequested isn't fed to the processor(s) so it seemed kind of pointless to do.

@CodeBlanch CodeBlanch merged commit 8b1fd83 into open-telemetry:aspnet-telemetrycorrelation-otelintegration Aug 16, 2021
@CodeBlanch CodeBlanch deleted the aspnet-telemetrycorrelation-otelintegration-part3 branch August 16, 2021 16:44
CodeBlanch added a commit that referenced this pull request Aug 25, 2021
…e + OpenTelemetry.API (#2270)

* New design for TelemetryHttpModule using ActivitySource + OpenTelemetry.API. (#2249)

* New design for TelemetryHttpModule using ActivitySource + OpenTelemetry.API part 2 (#2254)

* Use a single context.Items key for state management to make things more efficient.

* Added a comment for clarity.

* Code review.

* New design for TelemetryHttpModule using ActivitySource + OpenTelemetry.API part 3 (#2256)

* Update ASP.NET instrumentation to use the new TelemetryHttpModule.

* Fixed TelemetryHttpModule not starting its Activity objects. Added an example of request suppression.

* Tweaks an logging improvements.

* Sealed AspNetInstrumentationEventSource.

* Code review.

* New design for TelemetryHttpModule using ActivitySource + OpenTelemetry.API part 4 (#2258)

* Fixed up TelemetryHttpModule unit tests.

* Added tests for the new HasStarted helper and added checks for StartedButNotSampledObj when not sampled.

* Code review.

* New design for TelemetryHttpModule using ActivitySource + OpenTelemetry.API part 5 (#2261)

* Updated ASP.NET instrumentation tests for new TelemetryHttpModule.

* Added a test for the new RecordException option.

* Code review.

* New design for TelemetryHttpModule using ActivitySource + OpenTelemetry.API part 6 (#2264)

* CHANGELOG & README updates.

* Apply suggestions from code review

Co-authored-by: Reiley Yang <reyang@microsoft.com>

Co-authored-by: Reiley Yang <reyang@microsoft.com>

* Lint + sanity checks.

* Lint attempt 2.

* Restored CHANGELOG changes lost in merge.

Co-authored-by: Reiley Yang <reyang@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants