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

[AzureMonitorDistro] Add ASP.NET Core and HTTP Client metrics instrumentation #42307

Merged
merged 27 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
138ade5
Add ASP.NET Core and HTTP Client metrics instrumentation
rajkumar-rangaraj Feb 29, 2024
24a9c88
Changelog update
rajkumar-rangaraj Mar 1, 2024
c82191d
Update .NET 8.0 and above to use built-in meter.
rajkumar-rangaraj Mar 4, 2024
0078f65
Update readme
rajkumar-rangaraj Mar 4, 2024
5af5324
readme - swich doc to use new api.
rajkumar-rangaraj Mar 4, 2024
5865e07
Update sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/README.md
TimothyMothra Mar 11, 2024
a3bb051
Merge branch 'main' into rajrang/addInsMetrics
TimothyMothra Mar 11, 2024
b343543
Update sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/README.md
TimothyMothra Mar 11, 2024
0945da9
Update CHANGELOG.md
TimothyMothra Mar 11, 2024
1a27445
Update CHANGELOG.md
TimothyMothra Mar 11, 2024
1d8da40
Update CHANGELOG.md
TimothyMothra Mar 11, 2024
f2a6133
Update CHANGELOG.md
TimothyMothra Mar 11, 2024
0535347
Update sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/README.md
TimothyMothra Mar 11, 2024
645283d
Update README.md
TimothyMothra Mar 11, 2024
80eaff1
Update README.md
TimothyMothra Mar 11, 2024
abe70b6
Update sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/CHANGELOG.md
TimothyMothra Mar 11, 2024
22237ae
Update README.md
TimothyMothra Mar 12, 2024
a647c16
Update README.md
TimothyMothra Mar 12, 2024
501a7f9
Update README.md
TimothyMothra Mar 12, 2024
78f399d
Update OpenTelemetryBuilderExtensions.cs
TimothyMothra Mar 12, 2024
ffc80fe
Update sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/README.md
TimothyMothra Mar 12, 2024
6e1e6b1
Update README.md
TimothyMothra Mar 12, 2024
8691c09
Update README.md
TimothyMothra Mar 12, 2024
0e796e4
Update sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/CHANGELOG.md
TimothyMothra Mar 12, 2024
65b502d
Update sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/CHANGELOG.md
TimothyMothra Mar 12, 2024
71c7134
Update sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/README.md
TimothyMothra Mar 12, 2024
b122c99
Update sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/README.md
TimothyMothra Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@

### Features Added

* ASP.NET Core and HTTP Client Metrics Collection: Implemented conditional
instrumentation for ASP.NET Core and HTTP Client metrics to optimize telemetry
collection across various .NET runtime environments. This update ensures the
most relevant and efficient metrics collection tailored to the specific
version of the .NET runtime being used.
* For .NET 8 and above, we now utilize built-in Metrics for
`Microsoft.AspNetCore.Hosting` and `System.Net.Http`. This approach
leverages the latest .NET runtime capabilities to provide detailed insights
directly from the runtime environment. See detailed metrics documentation
for
[Microsoft.AspNetCore.Hosting](https://learn.microsoft.com/en-in/dotnet/core/diagnostics/built-in-metrics-aspnetcore#microsoftaspnetcorehosting)
and
[System.Net.Http](https://learn.microsoft.com/en-in/dotnet/core/diagnostics/built-in-metrics-system-net#systemnethttp).
* For environments below .NET 8, distro uses ASP.NET Core and HTTP Client
Instrumentation to ensure compatibility with older runtime versions. Detailed
metrics information can be found in the [ASP.NET Core
Instrumentation](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Instrumentation.AspNetCore/README.md)
and [HTTP Client
Instrumentation](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Instrumentation.Http/README.md)
documentation.
([#42307](https://github.com/Azure/azure-sdk-for-net/pull/42307))

### Breaking Changes

### Bugs Fixed
Expand Down
24 changes: 22 additions & 2 deletions sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ The Azure Monitor Distro is a distribution of the .NET OpenTelemetry SDK with in
* **HTTP Client Instrumentation**: Provides automatic tracing for outgoing HTTP requests made using [System.Net.Http.HttpClient](https://docs.microsoft.com/dotnet/api/system.net.http.httpclient).
* **SQL Client Instrumentation** Provides automatic tracing for SQL queries executed using the [Microsoft.Data.SqlClient](https://www.nuget.org/packages/Microsoft.Data.SqlClient) and [System.Data.SqlClient](https://www.nuget.org/packages/System.Data.SqlClient) packages. (While the OpenTelemetry SqlClient instrumentation remains in its beta phase, we have taken the step to vendor it and include it in our Distro)

* Metrics
* Provides automatic collection of Application Insights Standard metrics.
* Metrics
* **Application Insights Standard Metrics**: Provides automatic collection of Application Insights Standard metrics.
* **Conditional Instrumentation for ASP.NET Core and HTTP Client Metrics**: To adapt to different .NET runtime environments and optimize telemetry collection, our distro now includes a dynamic approach to these instrumentations. Based on the .NET runtime version, we selectively enable metrics collection for ASP.NET Core and HTTP client activities:
* **.NET 8 and above**: Utilizes built-in Metrics `Microsoft.AspNetCore.Hosting` and `System.Net.Http` from the .NET. For a detailed list of metrics produced, refer to the [Microsoft.AspNetCore.Hosting](https://learn.microsoft.com/en-in/dotnet/core/diagnostics/built-in-metrics-aspnetcore#microsoftaspnetcorehosting) and [System.Net.Http](https://learn.microsoft.com/en-in/dotnet/core/diagnostics/built-in-metrics-system-net#systemnethttp) metrics documentation.
* **Below .NET 8**: Falls back to ASP.NET Core Instrumentation and HTTP Client Instrumentation for compatibility with older runtime versions. For a detailed list of metrics produced, refer to the [ASP.NET Core Instrumentation](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Instrumentation.AspNetCore/README.md) and [HTTP Client Instrumentation](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Instrumentation.Http/README.md) documentation.

* [Logs](https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/docs/logs/getting-started-console)

Expand Down Expand Up @@ -263,6 +266,23 @@ builder.Services.AddOpenTelemetry().UseAzureMonitor(o =>
});
```

#### Drop a Metrics Instrument

If you want to exclude specific instruments from being collected in your application's telemetry, such as metrics from the distro or custom metrics, use the following code snippet.

```C#
builder.Services.ConfigureOpenTelemetryMeterProvider(b =>
b.AddView((instrument) =>
{
if (instrument.Name == "http.server.request.duration")
{
return null;
}

return null;
}));
```

## Key concepts

The Azure Monitor Distro is a distribution package that facilitates users in sending telemetry data to Azure Monitor. It encompasses the .NET OpenTelemetry SDK and instrumentation libraries for ASP.NET Core, HttpClient, and SQLClient, ensuring seamless integration and data collection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public static OpenTelemetryBuilder UseAzureMonitor(this OpenTelemetryBuilder bui
.AddAzureMonitorTraceExporter());

builder.WithMetrics(b => b
.AddHttpServerAndClientMetrics()
.AddAzureMonitorMetricExporter());

builder.Services.AddLogging(logging =>
Expand Down Expand Up @@ -217,5 +218,12 @@ private static TracerProviderBuilder AddVendorInstrumentationIfPackageNotReferen

return tracerProviderBuilder;
}

private static MeterProviderBuilder AddHttpServerAndClientMetrics(this MeterProviderBuilder meterProviderBuilder)
{
return Environment.Version.Major >= 8 ?
meterProviderBuilder.AddMeter("Microsoft.AspNetCore.Hosting").AddMeter("System.Net.Http")
: meterProviderBuilder.AddAspNetCoreInstrumentation().AddHttpClientInstrumentation();
}
}
}