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

[.NET7.0] AspNetCore ActivitySource Migration #3391

Conversation

vishweshbankwar
Copy link
Member

@vishweshbankwar vishweshbankwar commented Jun 20, 2022

Fixes #.
#3019

TODO: Add additional tests.

Changes

Please provide a brief description of the changes here.

For significant contributions please make sure you have completed the following items:

  • Appropriate CHANGELOG.md updated for non-trivial changes
  • Design discussion issue #
  • Changes in public API reviewed

@vishweshbankwar vishweshbankwar changed the title [.NET7.] AspNetCore ActivitySource Migration [.NET7.0] AspNetCore ActivitySource Migration Jun 20, 2022
@vishweshbankwar vishweshbankwar marked this pull request as ready for review June 20, 2022 18:17
@vishweshbankwar vishweshbankwar requested a review from a team June 20, 2022 18:17
@codecov
Copy link

codecov bot commented Jun 22, 2022

Codecov Report

Merging #3391 (e7e813f) into net7.0 (3a90287) will decrease coverage by 0.10%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           net7.0    #3391      +/-   ##
==========================================
- Coverage   86.13%   86.02%   -0.11%     
==========================================
  Files         258      258              
  Lines        9254     9261       +7     
==========================================
- Hits         7971     7967       -4     
- Misses       1283     1294      +11     
Impacted Files Coverage Δ
...tation.AspNetCore/Implementation/HttpInListener.cs 89.80% <100.00%> (+0.13%) ⬆️
...tion.AspNetCore/TracerProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
...entation/ExportClient/OtlpGrpcTraceExportClient.cs 35.71% <0.00%> (-42.86%) ⬇️
...xporter.OpenTelemetryProtocol/OtlpTraceExporter.cs 36.36% <0.00%> (-40.91%) ⬇️
src/OpenTelemetry.Api/BaseProvider.cs 66.66% <0.00%> (-33.34%) ⬇️
...Propagators/OpenTelemetryPropagatorsEventSource.cs 87.50% <0.00%> (-12.50%) ⬇️
...ZPages/Implementation/ZPagesExporterEventSource.cs 56.25% <0.00%> (-6.25%) ⬇️
...metryProtocol/Implementation/ActivityExtensions.cs 91.20% <0.00%> (-3.30%) ⬇️
...ter.ZPages/Implementation/ZPagesActivityTracker.cs 97.14% <0.00%> (-2.86%) ⬇️
...nTelemetry/Internal/OpenTelemetrySdkEventSource.cs 76.66% <0.00%> (+1.66%) ⬆️
... and 5 more

Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

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

LGTM

// For .NET6.0 and below, we will continue to use legacy way.
if (HttpInListener.IsNet7OrGreater)
{
var activitySourceService = serviceProvider?.GetService<ActivitySource>();
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this is safe. Anyone can add ActivitySource to DI, and how do we know if this is the one added by asp.net core?

Copy link
Member Author

@vishweshbankwar vishweshbankwar Jul 15, 2022

Choose a reason for hiding this comment

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

@@ -135,8 +157,11 @@ public override void OnStartActivity(Activity activity, object payload)
return;
}

ActivityInstrumentationHelper.SetActivitySourceProperty(activity, ActivitySource);
ActivityInstrumentationHelper.SetKindProperty(activity, ActivityKind.Server);
if (!IsNet7OrGreater)
Copy link
Member

Choose a reason for hiding this comment

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

why we have used pre-processor directives (NET7_0_OR_GREATER) in some places and the static variable in other place?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point - we should use preprocessor directive everywhere. let me know if there is any case where it wont work

// For .NET6.0 and below, we will continue to use legacy way.
#if NET7_0_OR_GREATER
// TODO: Check with .NET team to see if this can be prevented
// as this allows user to override the ActivitySource.
Copy link
Member

Choose a reason for hiding this comment

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

would be good to write a unittest which simulates this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

Vishwesh Bankwar added 2 commits July 18, 2022 09:50
@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Issues and pull requests which have been flagged for closing due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants