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

Instrumentation docs Part #2 - HTTP options #1244

Merged
merged 9 commits into from
Nov 5, 2020

Conversation

alanwest
Copy link
Member

@alanwest alanwest commented Sep 9, 2020

Relates to #1233. Adds documentation of HTTP instrumentation options.

@alanwest alanwest requested a review from a team September 9, 2020 16:40
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, well written! 👍

Comment on lines 59 to 64
For .NET Framework, two extensions methods exist:
`AddHttpClientInstrumentation` and `AddHttpWebRequestInstrumentation`.
.NET Framework's implementation of HttpClient uses HttpWebRequest internally,
so using one extension method over the other allows for configuring options
independently for HttpClient instrumentation vs. HttpWebRequest
instrumentation.
Copy link
Member Author

@alanwest alanwest Sep 9, 2020

Choose a reason for hiding this comment

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

Based on our conversation regarding HttpClient and HttpWebRequest, I took a stab at better wording for this section, though I'm not convinced that it is accurate because our conversation has made me a bit confused by this code

#if NETFRAMEWORK
/// <summary>
/// Enables HttpClient and HttpWebRequest instrumentation.
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
/// <param name="configureHttpClientInstrumentationOptions">HttpClient configuration options.</param>
/// <param name="configureHttpWebRequestInstrumentationOptions">HttpWebRequest configuration options.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddHttpClientInstrumentation(
this TracerProviderBuilder builder,
Action<HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions = null,
Action<HttpWebRequestInstrumentationOptions> configureHttpWebRequestInstrumentationOptions = null)
#else

This seems to suggest the ability to set options for HttpClient and HttpWebRequest, but if I'm understanding things correctly, the options passed to this method for HttpClient effectively remain unused. Right? If so, then it seems like we should remove the configureHttpClientInstrumentationOptions parameter from the .NET Framework compilation.

Copy link
Member

Choose a reason for hiding this comment

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

mm. The TracerProviderBuilderExtensions code seems bit puzzling to me as well. Let me take another close look and get back to you.

Copy link
Member

Choose a reason for hiding this comment

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

In .NET Framework, HttpClient uses HttpWebRequest. So really, only AddHttpWebRequestInstrumentation will be active. But if you use a .NET Standard package that pulls in .NET Standard HttpClient, what will happen? Could .NET Core bits get in there? Not totally sure about that but I think that's why both are there.

Copy link
Member Author

@alanwest alanwest Sep 10, 2020

Choose a reason for hiding this comment

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

Hmm. I'm pretty sure the guidance is to not consume HttpClient as a nuget package for .net framework. While it's technically possible it often leads to problems. I feel like I've read more "official" guidance on this somewhere but all I'm finding offhand is a tweet from Immo Landwerth https://twitter.com/terrajobst/status/997262020108926976?s=20.

I guess my thought is if there's a general consensus that this isn't best practice then should we seek to support it?

Copy link
Member

Choose a reason for hiding this comment

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

should we just remove AddHttpWebRequest to avoid confusion, and have a single method AddHttpClientInstrumentation for both .NET core and .NET framework?
And in the documentation for filter, state that, In .NET Core, HttpRequestMessage and .NET Framework, HttpWebRequest is the type passed to Filter?

Copy link
Member Author

Choose a reason for hiding this comment

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

For now, I just removed this section distinguishing between the two add methods. I actually didn't realize until just now that AddHttpWebRequestInstrumentation is an internal method - sorry 🤦 - so in effect this was already true:

should we just remove AddHttpWebRequest to avoid confusion, and have a single method AddHttpClientInstrumentation for both .NET core and .NET framework?

Though, I am still curious about the behavior of things when the NuGet package is used in the context of .NET Framework. I'll spend a little time experimenting with this, because I feel if we can simplify and remove the configureHttpClientInstrumentationOptions for .NET Framework, that would be kinda nice.

@cijothomas cijothomas merged commit 6278780 into open-telemetry:master Nov 5, 2020
@alanwest alanwest deleted the alanwest/docs-http branch November 5, 2020 23:11
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