-
Notifications
You must be signed in to change notification settings - Fork 772
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
[hosting] Support .NET 8 IMetricsBuilder API #4958
[hosting] Support .NET 8 IMetricsBuilder API #4958
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4958 +/- ##
==========================================
+ Coverage 83.24% 83.35% +0.10%
==========================================
Files 294 296 +2
Lines 12321 12301 -20
==========================================
- Hits 10257 10253 -4
+ Misses 2064 2048 -16
Flags with carried forward coverage won't be shown. Click here to find out more.
|
How would you feel about names like |
@noahfalk I'm happy to name it whatever you want! If we do @reyang Had an interesting idea I want to also capture. IIRC, it was to recommend users use the "services.AddOpenTelemetry().With*" pattern for their pipeline configuration: appBuilder.Logging.AddOpenTelemetry(); // Turn on ILogger integration
appBuilder.Metrics.AddOpenTelemetry(); // Turn on IMetricsListener integration
// Current style: Configure the pipeline
appBuilder.Services.AddOpenTelemetry()
.WithLogging(logging => logging.AddOtlpExporter()
.WithMetrics(metrics => metrics.AddOtlpExporter();
// Future style: Configure the pipeline using cross-cutting helper (https://github.com/open-telemetry/opentelemetry-dotnet/issues/4940)
appBuilder.Services.AddOpenTelemetry().AddOtlpExporter(); |
Yeah, I was assuming we'd use the same name across logging + metrics (+distributed tracing eventually) |
The other question which @samsp-msft raised that would good to look at is defaults. Effectively if an app author writes this and nothing else: services.AddOpenTelemetry().WithMetrics() ... does it include IMetricsBuilder metrics by default or do they have to explicitly also call metricsBuilder.UseOpenTelemetry() to make that happen? Certainly having it happen automatically seems nice in the vast majority of cases I can think of. The only case where it feels a little weird is:
That case feels fairly contrived so I'm leaning that yes the IMetricsBuilder metrics would be included by default when calling WithMetrics(). If we did it for metrics I think we'd also want to do it for logging (and distributed tracing in time) so that they are all consistent. Thoughts on this one? |
Agreed. As this also requires changing config, there should be no changes to the app until they start adding metrics via config.
There have to be 2 changes here - updating the SDK and adding config.
Next - can we do away with WithMetrics()? Can there be an extension methods off the return from AddOpenTelemetry() that enable me to configure an exporter for all 3 sources. And can we bring logging into the fold so its configured the same way? |
@noahfalk @samsp-msft Let's try to nail down the names here and get the initial support completed. For the cross-cutting extension I have #4940 and for the default behavior I just opened #4985 we can tackle those things separately after this groundwork is completed? |
Sure. I'll narrow my proposal down to: IMetricsBuilder.UseOpenTelemetry()
ILoggingBuilder.UseOpenTelemetry() If everyone is happy with that we can go with it, if not we can workshop other names. For the defaults I don't think it has to be this PR, but it do think it should be part of the same OTel SDK release that adds support for WithLogging() and IMetricsBuilder. |
FYI I updated the code and the proposal in the description for "UseOpenTelemetry" |
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.
Approving. I'll admit I did not have a chance to perform a super close review of the internals, test coverage, etc (and I'm out next week), but I support the overall vision and I'm ok with landing this PR
Fixes #4896
Relates to #4985
Relates to #4384
Overview
There is a new API in .NET 8: IMetricsBuilder
What this new API does is expose a metrics pipeline at the host level which works much like the logging pipeline (ILoggingBuilder).
The main feature that comes with this is being able to configure meters/instruments via configuration.
Changes
The
OpenTelemetryBuilder.WithMetrics
method will now register an IMetricsListener named "OpenTelemetry" into theIServiceCollection
.MeterProviderSdk
updated to log two new information-level events when an instrument is disabled:If an instrument is enabled via
IMetricsListener
ANDAddMeter
then theIMetricsListener
publish will be ignored.Merge requirement checklist
CHANGELOG.md
files updated for non-trivial changes