[ASP.NET Core] Add support for .NET8.0 specific metrics#4934
Conversation
Codecov Report
@@ Coverage Diff @@
## main open-telemetry/opentelemetry-dotnet#4934 +/- ##
==========================================
- Coverage 83.31% 83.28% -0.04%
==========================================
Files 295 295
Lines 12361 12375 +14
==========================================
+ Hits 10299 10306 +7
- Misses 2062 2069 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
|
src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreMetricsInstrumentationOptions.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.AspNetCore/MeterProviderBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
|
@JamesNK @davidfowl PTAL |
src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs
Show resolved
Hide resolved
|
Do we want the rate limiting to be included by default or does it only get emitted if used? |
what is rate limiting? |
Please see . These metrics should only be emitted when user has configured rate limiting. |
oops sorry! I misread as something related to throttling within the SDK ! |
src/OpenTelemetry.Instrumentation.AspNetCore/MeterProviderBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.AspNetCore/MeterProviderBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
...nTelemetry.Instrumentation.AspNetCore/Implementation/AspNetCoreInstrumentationEventSource.cs
Outdated
Show resolved
Hide resolved
…pNetCoreInstrumentationEventSource.cs Co-authored-by: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com>
src/OpenTelemetry.Instrumentation.AspNetCore/MeterProviderBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
…derExtensions.cs Co-authored-by: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com>
...nTelemetry.Instrumentation.AspNetCore/Implementation/AspNetCoreInstrumentationEventSource.cs
Outdated
Show resolved
Hide resolved
…pNetCoreInstrumentationEventSource.cs Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
….com/vishweshbankwar/opentelemetry-dotnet into vibankwa/add-net8-aspnetcore-metrics
| // We need to let metric callback execute as it is executed AFTER response was returned. | ||
| // In unit tests environment there may be a lot of parallel unit tests executed, so | ||
| // giving some breezing room for the callbacks to complete | ||
| await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false); |
There was a problem hiding this comment.
This seems super unreliable. Why not use a mock listener ?
There was a problem hiding this comment.
what is a mock listener here? MeterListener?
There was a problem hiding this comment.
@vishweshbankwar If you performed await app.DisposeAsync(); here would that cause everything to flush out in a more deterministic way?
There was a problem hiding this comment.
@CodeBlanch - That would require configuring meterprovider via services.AddOpenTelemetry() - is that right?
There was a problem hiding this comment.
You could keep it how you have it. Just dispose both...
await app.DisposeAsync(); // Flush AspNetCore
this.meterProvider.Dispose(); // Flush manual providerShould be fine.
You could do it all from the host if you wanted to like this...
var metricItems = new List<Metric>();
var builder = WebApplication.CreateBuilder();
builder.Logging.ClearProviders();
builder.Services.AddOpenTelemetry()
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.AddInMemoryExporter(metricItems));
var app = builder.Build();
app.MapGet("/", () => "Hello");
_ = app.RunAsync();
using var client = new HttpClient();
var res = await client.GetStringAsync("http://localhost:5000/").ConfigureAwait(false);
Assert.NotNull(res);
await app.DisposeAsync(); // This should flush AspNetCore and the MeterProvider in this case
// inspect metricItems here it should be populated with everything that happenedThere was a problem hiding this comment.
Thanks! - I will follow up on this. Opened #4972 for tracking
There was a problem hiding this comment.
LGTM for the pre-release.
Need the following before stable:
- Readme updates, with View recipes to drop metrics not part of semantic conventions. Also indicate the enrich/filter part linking to .NET docs where appropriate.
- Benchmarks to see the extra metrics affects perf. If yes, we need to only enable the ones from semantic convention. Irrespective of that, I'd like to see why would enable the extra metrics by default? I think they should be opt-in only.
Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
| _ = app.RunAsync(); | ||
|
|
||
| using var client = new HttpClient(); | ||
| var res = await client.GetStringAsync("http://localhost:5000/").ConfigureAwait(false); |
There was a problem hiding this comment.
If we really are expecting these tests to run in parallel (I don't think they actually do) we should probably randomize the port and handle the case where it is in use? I know we do that for other tests where we need to start up a listener.
@davidfowl Any other patterns perhaps we could use to cause the pieces of aspnetcore to fire we need instead of exercising the whole pipeline?
There was a problem hiding this comment.
Yes I think these tests need to be rewritten to use the WebApplicationFactory and fakes for the meter listener.
cc @JamesNK as he wrote tests for meters in ASP.NET Core.
There was a problem hiding this comment.
Randomizing port is something I was planning to do to avoid conflicts (we do have issues right now related to it).
we use WebApplicationFactory in most of the tests here. This new pattern is used as it relatively lightweight and does not require an additional template app like WebApplicationFactory does. If WebApplicationFactory is the recommended way then we can stick with it.
CodeBlanch
left a comment
There was a problem hiding this comment.
Some test feedback, but LGTM. We could improve the tests as a follow-up.
Towards open-telemetry/opentelemetry-dotnet-contrib#1753
Details: open-telemetry/opentelemetry-dotnet-contrib#1753
open-telemetry/opentelemetry-dotnet-contrib#1753
Changes
This PR adds support for ASP.NET Core metrics that are available natively when targeting
.NET8.0framework.Following metrics will now be enabled by default. The metrics will be exported based on the individual application configuration/scenarios
Meter :
Microsoft.AspNetCore.Hostinghttp.server.request.durationhttp.server.active_requestsMeter :
Microsoft.AspNetCore.Server.Kestrelkestrel.active_connectionskestrel.connection.durationkestrel.rejected_connectionskestrel.queued_connectionskestrel.queued_requestskestrel.upgraded_connectionskestrel.tls_handshake.durationkestrel.active_tls_handshakesMeter :
Microsoft.AspNetCore.Http.Connectionssignalr.server.connection.durationsignalr.server.active_connectionsMeter :
Microsoft.AspNetCore.Routingaspnetcore.routing.match_attemptsMeter :
Microsoft.AspNetCore.Diagnosticsaspnetcore.diagnostics.exceptionsMeter :
Microsoft.AspNetCore.RateLimitingaspnetcore.rate_limiting.active_request_leasesaspnetcore.rate_limiting.request_lease.durationaspnetcore.rate_limiting.queued_requestsaspnetcore.rate_limiting.request.time_in_queueaspnetcore.rate_limiting.requestsTODO: Update Readme
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes