-
Notifications
You must be signed in to change notification settings - Fork 764
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
Add HttpClient metrics for .NET Framework #4768
Add HttpClient metrics for .NET Framework #4768
Conversation
src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.Http/MeterProviderBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.Http/MeterProviderBuilderExtensions.cs
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs
Outdated
Show resolved
Hide resolved
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4768 +/- ##
==========================================
- Coverage 85.46% 82.30% -3.17%
==========================================
Files 314 314
Lines 12940 12956 +16
==========================================
- Hits 11059 10663 -396
- Misses 1881 2293 +412
|
> Metrics are not available for .NET Framework. | ||
> Metrics are only available for .NET Framework when traces are recorded. This requires: | ||
> 1. Tracing to be enabled by calling `.AddHttpClientInstrumentation()` on `TracerProviderBuilder` | ||
> 2. [If a sampler is in place, return `SamplingDecision.RecordAndSampled` for `ShouldSample`](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/docs/trace/extending-the-sdk/README.md#filtering-processor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits:
"If a sampler" is not right, as there is always a sampler! Suggestion:
The sampler must return RecordAndSample
for ever Activity
in order for the Metrics to be accurate. If some spans (Activity) are sampled, but others not, it'll affect Metrics accuracy, as Metric Tags (Attributes) are generated based on the Activity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, the user provided Filters can also affect this,
Line 274 in 06c704b
if (!WebRequestActivitySource.HasListeners() || !Options.EventFilterHttpWebRequest(request)) |
- Enable tracing.
- Sampler returns RecordAndSample
- No user defined filters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest revisit the design of relying on Activity for generating metrics, and instead produce Metrics independently.
The approach done in this PR is more like a "Span2Metrics" processor, and can done as a regular ActivityProcessor
instead, so it'll be easy to convey that Metrics are only as good as the underlying Activity.
Could you check how big of a change it'd to produce metrics independently? (It may not be as bad to rely on Activity for duration alone...but not for the whole tags.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did some research and have an idea. Could follow a similar pattern to HttpClient. The idea would be to:
- Call ActivitySource.CreateActivity if tracing is enabled. This Activity would be used by metrics and traces
- Instantiate a standalone Activity if only metrics are enabled. This wouldn't cause a trace to be emitted
- Null Activity if neither metrics nor traces are enabled
If metrics or traces are enabled, the existing tags would still be set, with the only difference being whether the Activity ends up processed by an exporter.
Does this approach sound OK? There are some details to work through, but this looks feasible to me. Also welcome to other ideas if anyone has thoughts.
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. |
Fixes #4764
Changes
Extends the existing tracing implementation to also generate metrics. This requires tracing to be enabled - while not ideal, this significantly limits the scope of changes to get metrics working.
To enable metrics, you must call
AddHttpClientInstrumentation()
onTracerProviderBuilder
.A single metric is published:
http.client.duration
, same as the .NET Core/.NET metrics implementation.Unit tests have been modified to cover HttpClient metrics on .NET Framework. All unit test are passing.
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial changes