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

[Do not Merge] Testing net7.0 HttpClient with ActivitySourceListener #3016

Conversation

vishweshbankwar
Copy link
Member

@vishweshbankwar vishweshbankwar commented Mar 10, 2022

Fixes #3018

@codecov
Copy link

codecov bot commented Mar 15, 2022

Codecov Report

Merging #3016 (19d36dc) into main (5a566e6) will increase coverage by 0.03%.
The diff coverage is 96.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3016      +/-   ##
==========================================
+ Coverage   85.39%   85.42%   +0.03%     
==========================================
  Files         270      270              
  Lines        9561     9581      +20     
==========================================
+ Hits         8165     8185      +20     
  Misses       1396     1396              
Impacted Files Coverage Δ
...tp/Implementation/HttpHandlerDiagnosticListener.cs 70.52% <90.00%> (+1.20%) ⬆️
....Instrumentation.Http/HttpClientInstrumentation.cs 100.00% <100.00%> (ø)
...umentation.Http/TracerProviderBuilderExtensions.cs 75.00% <100.00%> (+3.57%) ⬆️
...tation/OpenTelemetryProtocolExporterEventSource.cs 75.00% <0.00%> (-10.00%) ⬇️
...metryProtocol/Implementation/ActivityExtensions.cs 95.60% <0.00%> (+1.09%) ⬆️
...emetry.Api/Internal/OpenTelemetryApiEventSource.cs 76.47% <0.00%> (+2.94%) ⬆️

@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.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Mar 23, 2022
@github-actions
Copy link
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Mar 30, 2022
@cijothomas cijothomas reopened this Apr 26, 2022
@vishweshbankwar vishweshbankwar changed the title [Do not Merge] Testing net7.0 HttpClient [Do not Merge] Testing net7.0 HttpClient with ActivitySourceListener Apr 27, 2022
@@ -25,13 +25,37 @@ internal class HttpClientInstrumentation : IDisposable
{
private readonly DiagnosticSourceSubscriber diagnosticSourceSubscriber;

private readonly Func<string, object, object, bool> isEnabled = (activityName, obj1, obj2) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

private readonly Func<string, object, object, bool> isEnabled = (activityName, obj1, obj2) => activityName == "System.Net.Http.HttpRequestOut";

internal static readonly Version Version = AssemblyName.Version;
internal static readonly ActivitySource ActivitySource = new(ActivitySourceName, Version.ToString());
internal static readonly bool IsNet7OrGreater = typeof(HttpClient).Assembly.GetName().Version.Major >= 7;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: IsHttpClientVersion7OrGreater?

internal static readonly Version Version = AssemblyName.Version;
internal static readonly ActivitySource ActivitySource = new(ActivitySourceName, Version.ToString());
internal static readonly bool IsNet7OrGreater = typeof(HttpClient).Assembly.GetName().Version.Major >= 7;
Copy link
Contributor

Choose a reason for hiding this comment

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

This check looks ok to me. I double checked the supported versions of http client, and this check is good enough. The other idea can be checking Environment.Version to know if running on .NET 7.0 or later as http client 7.0 will be used only on .NET 7.0. But I don't prefer this option as in the future http client can decide to run down-level versions including netfx.

One other idea can be, enable DiagnosticSource listener till you get the first http client activity and then check the Activity.Source as @noahfalk suggested. Then if the Source is not null, turn off DiagnosticSource listener on http client and enable ActivitySource for it. Maybe this will immune you against versioning changes/risks.

Choose a reason for hiding this comment

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

I think the check as-is in this PR is a good tradeoff between simplicity and reliability. My suggestion to use the Activity.Source property was assuming we were running logic in a callback that had the Activity passed in and that no caching would be necessary. Trying to do that check in this case feels unnecessarily complex.

Copy link
Member Author

@vishweshbankwar vishweshbankwar Apr 29, 2022

Choose a reason for hiding this comment

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

Thanks @tarekgh @noahfalk - The second option could introduce an issue - Thinking about the edge case - If I have sampler always returning ActivitySamplingResult.None. In this case HttpClient will fall back to check if there is a diagnostic listener present, if there is one it will create activity using new Activity(). For this case, we will never get an activity with source set.

I am checking source property as well here as there could be another diagnosticsource listener present (e.g. another instrumentation library) which could ultimately cause activity to be created.

Please correct me if I am wrong.

Copy link

@noahfalk noahfalk Apr 29, 2022

Choose a reason for hiding this comment

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

I think this PR is doing the right things : )

@vishweshbankwar vishweshbankwar marked this pull request as ready for review June 6, 2022 20:58
@vishweshbankwar vishweshbankwar requested a review from a team June 6, 2022 20:58
@vishweshbankwar vishweshbankwar marked this pull request as draft June 6, 2022 20:59
@github-actions
Copy link
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Jun 14, 2022
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.

[.NET7.0] Update HttpClient instrumentation to enable activity creation using ActivitySource
5 participants