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

Modify httpclient instrumentation to take advantage of sampling decision #1894

Merged
merged 3 commits into from
Mar 10, 2021

Conversation

cijothomas
Copy link
Member

@cijothomas cijothomas commented Mar 10, 2021

Just a single instrumentation in this PR. More instrumentations can leverage similar optimization.
Follows #1893

Changes

Please provide a brief description of the changes here.

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

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

@cijothomas cijothomas requested a review from a team March 10, 2021 01:57
// By this time, samplers have already run and
// activity.IsAllDataRequested populated accordingly.

if (Sdk.SuppressInstrumentation)
Copy link
Member Author

Choose a reason for hiding this comment

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

this check is done to make sure to have no side-effect if under supression. Even without this, TracerProviderSdk drops the activity if under supressions, but this method does propagation. This check prevents every side effect including propagation if under suppression.

@codecov
Copy link

codecov bot commented Mar 10, 2021

Codecov Report

Merging #1894 (01df421) into main (822ce19) will increase coverage by 0.02%.
The diff coverage is 84.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1894      +/-   ##
==========================================
+ Coverage   83.33%   83.35%   +0.02%     
==========================================
  Files         188      188              
  Lines        6137     6139       +2     
==========================================
+ Hits         5114     5117       +3     
+ Misses       1023     1022       -1     
Impacted Files Coverage Δ
...tp/Implementation/HttpHandlerDiagnosticListener.cs 71.42% <84.61%> (+0.64%) ⬆️
...ter.ZPages/Implementation/ZPagesActivityTracker.cs 100.00% <0.00%> (+2.85%) ⬆️

@cijothomas cijothomas merged commit 45a02a8 into main Mar 10, 2021
@cijothomas cijothomas deleted the cijothomas/improveinstr1 branch March 10, 2021 04:31
if (!this.startRequestFetcher.TryFetch(payload, out HttpRequestMessage request) || request == null)
{
HttpInstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnStartActivity));
return;
}

// TODO: Investigate why this check is needed.
Copy link
Contributor

@utpilla utpilla Mar 10, 2021

Choose a reason for hiding this comment

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

I think it was put for redirection cases where a redirect request might already have the context in the headers.

But I don't think the listener callback gets called for redirect cases. I tried this scenario: Call http://google.com from an HttpClient. This results in a 301 redirection to http:www.//google.com. The way HttpHandlerDiagnostics is currently configured, we only see one OnStartActivity and one OnStopActivity method call.

In the OnStartActivity method they request payload has the original Uri: http://google.com whereas in the OnStopActivity method the payload has the redirected Uri: http:www.//google.com. This would mean that we only enter OnStartActivity once for the original HttpRequestOut call. So this logic would not be used for redirects.

Copy link
Member

Choose a reason for hiding this comment

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

I know there were cases when I was working on HttpWebRequest instrumentation where it would re-use the request, but it has been a while so my memory is foggy. I think SSL upgrade/downgrade was one of them? Pretty sure I added a test or two for it. That is for the .NET Framework stuff but posting here because there are probably many similarities with the .NET Core side.

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.

4 participants