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

HttpSemanticConventions - update AspNetCore histogram #4766

Closed
wants to merge 9 commits into from
Closed

HttpSemanticConventions - update AspNetCore histogram #4766

wants to merge 9 commits into from

Conversation

TimothyMothra
Copy link
Contributor

@TimothyMothra TimothyMothra commented Aug 11, 2023

Towards #4484.

CHANGED THIS PR TO DRAFT.
This PR is blocked until we have support for new default histogram bounds.

Changes

  • all the following changes are made behind the environment variable OTEL_SEMCONV_STABILITY_OPT_IN.
  • update Instrumentation.AspNetCore class HttpInMetricsListener to emit new metric.
  • Update unit test MetricTests.RequestMetricIsCaptured to evaluate all states of the environment variable (old, new, both).

Merge requirement checklist

  • CONTRIBUTING guidelines followed (nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@TimothyMothra TimothyMothra requested a review from a team August 11, 2023 23:35
@@ -78,6 +78,10 @@ public static class MeterProviderBuilderExtensions

builder.AddMeter(AspNetCoreMetrics.InstrumentationName);

builder.AddView(
instrumentName: HttpInMetricsListener.HttpServerDurationMetricName,
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a check for both Meter name and Instrument name.

@@ -78,6 +78,10 @@ public static class MeterProviderBuilderExtensions

builder.AddMeter(AspNetCoreMetrics.InstrumentationName);

builder.AddView(
Copy link
Member

Choose a reason for hiding this comment

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

This should be done by the application user, not the instrumentation library. Instrumentation Library can set Hint (once that feature is available), but it should not try to Configure View. View is a SDK concept, and instrumentation library should not have sdk dependency at all. (its an issue that this library has an undesired dependency on sdk, thats tracked separately)...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Experimental spec for Hint API ("instrument advice") is here:
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#instrument-advice

Seems that Trask is ready to move it to Stable:
open-telemetry/opentelemetry-specification#3391

I had a brief chat with Utkarsh about this.
Seems the Hint API will be a blocker for this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Hint API require DiagnosticSource changes, so not coming this year.
But i don't know if Hint API support is required before making this change. As users always have View API to adjust bounds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, that seems like a bad user experience.
If the Instrumentation library ships with the wrong buckets and users need to manually adjust.

Copy link
Member

Choose a reason for hiding this comment

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

mm. If that is the case, then the stable release of instrumentation must be tied with next .NET release (Nov 2024). dotnet/runtime#63650 (comment)

Or some options must be added for instrumentation library to use ms instead of s. I recommend to create a dedicated issue to discuss this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@cijothomas On thinking a bit more about this, I think it should be okay for the instrumentation library to use View until the Hint API is offered from DiagnosticSource. When the Hint API is available, the instrumentation library could get rid of View and switch to using the Hint API.

As of today, anyone using AspNetCoreInstrumentation library is going to take a dependency on the SDK anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can include a TODO here to call out that this needs to be changed to Hint API when available.

Copy link
Member

Choose a reason for hiding this comment

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

I think it should be okay for the instrumentation library to use View until the Hint API is offered from DiagnosticSource. When the Hint API is available, the instrumentation library could get rid of View and switch to using the Hint API.

As of today, anyone using AspNetCoreInstrumentation library is going to take a dependency on the SDK anyway.

I would open a dedicated issue to discuss and record this decision. It's a pretty fundamental principle that instrumentations should only depend on the API and not on the SDK, and so you'll want to document the rationale clearly in this case and make sure your entire community is onboard and understands the ramifications.

Copy link
Member

Choose a reason for hiding this comment

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

It can still cause other issues as Views are additive. If user adds another view matching the same metric, to drop an unwanted attribute, it'll result in 2 metrics stream.

Its a bug that the instrumentation has a SDK dependency. It is fixable (once we move the things the instrumentation need from SDK to API itself.). Its even worse if the instrumentation leverages the SDK dependency to define behavior, reserved for application owner to define.

There are other instrumentations where this trick/hack of using views from SDK cannot be used - like asp.net framework.

At the cost of exposing yet another public API, an option like RecordDurationInMillisecond could work, and is probably more desirable than misusing SDK dependency.

@codecov
Copy link

codecov bot commented Aug 12, 2023

Codecov Report

Merging #4766 (b2c5b82) into main (e330e57) will increase coverage by 0.10%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4766      +/-   ##
==========================================
+ Coverage   85.59%   85.70%   +0.10%     
==========================================
  Files         284      284              
  Lines       11686    11697      +11     
==========================================
+ Hits        10003    10025      +22     
+ Misses       1683     1672      -11     
Files Changed Coverage Δ
...AspNetCore/Implementation/HttpInMetricsListener.cs 80.35% <100.00%> (+15.65%) ⬆️
...ation.AspNetCore/MeterProviderBuilderExtensions.cs 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

Comment on lines 147 to 151
this.httpServerDuration.Record(Activity.Current.Duration.TotalMilliseconds, tags);
this.httpServerDuration.Record(Activity.Current.Duration.TotalSeconds, tags);
Copy link
Member

Choose a reason for hiding this comment

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

Java gates this change with the OTEL_SEMCONV_STABILITY_OPT_IN setting. Maybe we should too since this is potentially disruptive to end users and backends.

Unfortunately, it's not explicitly stated that this change should be gated, but maybe it should be... @trask what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

within the scope of HTTP semconv, I think(?) this is implied by the spec, since unit seconds is part of the frozen http semconv for http.server.request.duration

Copy link
Member

Choose a reason for hiding this comment

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

I think(?) this is implied by the spec

This was my original interpretation... but I also can understand how someone might have a different interpretation since the words from the warning text are very attribute-centric.

I'd be happy to take a stab at some clarifying verbiage to the text if folks would find that helpful.

Copy link
Member

Choose a reason for hiding this comment

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

the words from the warning text are very attribute-centric.

ah, thx, I see the confusion now

I'd be happy to take a stab at some clarifying verbiage to the text if folks would find that helpful.

that would be great

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

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 Sep 1, 2023
@TimothyMothra TimothyMothra deleted the 4484_aspnetcoreMetrics branch September 7, 2023 18:23
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.

5 participants