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

Add AspNet metrics instrumentation #2985

Conversation

vishweshbankwar
Copy link
Member

@vishweshbankwar vishweshbankwar commented Mar 7, 2022

Fixes #2556

Changes

This change enables http.server.duration metric collection noted in spec for ASP.NET applications. It relies on activity to calculate the duration however, we need to update this at a later stage to make it independent of trace/activity creation. Opened #2994

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

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

@codecov
Copy link

codecov bot commented Mar 7, 2022

Codecov Report

Merging #2985 (d911f81) into main (5bb9f26) will increase coverage by 0.13%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2985      +/-   ##
==========================================
+ Coverage   84.09%   84.23%   +0.13%     
==========================================
  Files         255      258       +3     
  Lines        9062     9090      +28     
==========================================
+ Hits         7621     7657      +36     
+ Misses       1441     1433       -8     
Impacted Files Coverage Δ
...nTelemetry.Instrumentation.AspNet/AspNetMetrics.cs 100.00% <100.00%> (ø)
...ion.AspNet/Implementation/HttpInMetricsListener.cs 100.00% <100.00%> (ø)
...mentation.AspNet/MeterProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
...nTelemetry/Internal/OpenTelemetrySdkEventSource.cs 75.43% <0.00%> (+1.75%) ⬆️
...lemetry/Internal/SelfDiagnosticsConfigRefresher.cs 92.30% <0.00%> (+5.76%) ⬆️

new KeyValuePair<string, object>(SemanticConventions.AttributeHttpStatusCode, context.Response.StatusCode),
};

this.httpServerDuration.Record(activity.Duration.TotalMilliseconds, tags);
Copy link
Member

Choose a reason for hiding this comment

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

We need to fix the issue of this depending on tracing being enabled for metrics to work. But this limitation already exists in aspnet core as well. It is okay to merge this for an initial release. This is better than nothing.
(We definitely need to remove the Metrics dependency on Tracing before stable.)

Copy link
Contributor

@utpilla utpilla left a comment

Choose a reason for hiding this comment

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

LGTM. Left a comment about allocation. That could be done in a later PR.

/// <inheritdoc/>
public void Dispose()
{
this.meter?.Dispose();
Copy link
Member

Choose a reason for hiding this comment

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

do we need ? check?

@cijothomas cijothomas merged commit efeaac9 into open-telemetry:main Mar 9, 2022
@cijothomas
Copy link
Member

@vishweshbankwar Could you update the example asp.net app to leverage this? https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/examples/AspNet/Global.asax.cs

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.

Metric instrumentation for Asp.Net
4 participants