OpenTelemetry.Extensions.Hosting
1.11.0-rc.1
Prefix Reserved
dotnet add package OpenTelemetry.Extensions.Hosting --version 1.11.0-rc.1
NuGet\Install-Package OpenTelemetry.Extensions.Hosting -Version 1.11.0-rc.1
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.11.0-rc.1" />
paket add OpenTelemetry.Extensions.Hosting --version 1.11.0-rc.1
#r "nuget: OpenTelemetry.Extensions.Hosting, 1.11.0-rc.1"
// Install OpenTelemetry.Extensions.Hosting as a Cake Addin #addin nuget:?package=OpenTelemetry.Extensions.Hosting&version=1.11.0-rc.1&prerelease // Install OpenTelemetry.Extensions.Hosting as a Cake Tool #tool nuget:?package=OpenTelemetry.Extensions.Hosting&version=1.11.0-rc.1&prerelease
OpenTelemetry.Extensions.Hosting
Installation
dotnet add package OpenTelemetry.Extensions.Hosting
Overview
The OpenTelemetry.Extensions.Hosting package provides extension methods for
automatically starting (and stopping) OpenTelemetry tracing (TracerProvider
)
and metrics (MeterProvider
) in ASP.NET
Core and
.NET Generic
hosts. These are completely optional extensions meant to simplify the
management of the OpenTelemetry SDK lifecycle.
Extension method reference
Targeting Microsoft.Extensions.DependencyInjection.IServiceCollection
:
AddOpenTelemetry
: Registers an IHostedService to automatically start tracing and/or metric services in the supplied IServiceCollection and then returns anOpenTelemetryBuilder
class.[!NOTE]
AddOpenTelemetry
should be called by application host code only. Library authors see: Registration extension method guidance for library authors.[!NOTE] Multiple calls to
AddOpenTelemetry
will NOT result in multiple providers. Only a singleTracerProvider
and/orMeterProvider
will be created in the targetIServiceCollection
. To establish multiple providers use theSdk.CreateTracerProviderBuilder()
and/orSdk.CreateMeterProviderBuilder()
methods. See TracerProvider configuration and Building a MeterProvider for more details.OpenTelemetryBuilder
methods:ConfigureResource
: Registers a callback action to configure theResourceBuilder
for tracing and metric providers.WithTracing
: Enables tracing and optionally configures theTracerProvider
.WithMetrics
: Enables metrics and optionally configures theMeterProvider
.
Usage
The following example shows how to register OpenTelemetry tracing & metrics in an ASP.NET Core host using the OpenTelemetry.Extensions.Hosting extensions.
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
var appBuilder = WebApplication.CreateBuilder(args);
appBuilder.Services.AddOpenTelemetry()
.ConfigureResource(builder => builder.AddService(serviceName: "MyService"))
.WithTracing(builder => builder.AddConsoleExporter())
.WithMetrics(builder => builder.AddConsoleExporter());
var app = appBuilder.Build();
app.Run();
A fully functional example can be found here.
Resources
To dynamically add resources at startup from the dependency injection you can
provide an IResourceDetector
.
To make use of it add it to the dependency injection and then you can use the
IServiceProvider
to add it to OpenTelemetry:
public class MyResourceDetector : IResourceDetector
{
private readonly IWebHostEnvironment webHostEnvironment;
public MyResourceDetector(IWebHostEnvironment webHostEnvironment)
{
this.webHostEnvironment = webHostEnvironment;
}
public Resource Detect()
{
return ResourceBuilder.CreateEmpty()
.AddService(serviceName: this.webHostEnvironment.ApplicationName)
.AddAttributes(new Dictionary<string, object> { ["host.environment"] = this.webHostEnvironment.EnvironmentName })
.Build();
}
}
services.AddSingleton<MyResourceDetector>();
services.AddOpenTelemetry()
.ConfigureResource(builder =>
builder.AddDetector(sp => sp.GetRequiredService<MyResourceDetector>()))
.WithTracing(builder => builder.AddConsoleExporter())
.WithMetrics(builder => builder.AddConsoleExporter());
Migrating from pre-release versions of OpenTelemetry.Extensions.Hosting
Pre-release versions (all versions prior to 1.4.0) of
OpenTelemetry.Extensions.Hosting
contained signal-specific methods for
configuring tracing and metrics:
AddOpenTelemetryTracing
: Configure OpenTelemetry and register an IHostedService to automatically start tracing services in the supplied IServiceCollection.AddOpenTelemetryMetrics
: Configure OpenTelemetry and register an IHostedService to automatically start metric services in the supplied IServiceCollection.
These methods were marked obsolete and later removed. You should migrate your
code to the new AddOpenTelemetry
method documented above. Refer the
old
and
new
versions of the example application to assist you in your migration.
Hosted Service Ordering and Telemetry Capture
TBD
References
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- OpenTelemetry (>= 1.11.0-rc.1)
-
.NETStandard 2.0
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- OpenTelemetry (>= 1.11.0-rc.1)
-
net8.0
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- OpenTelemetry (>= 1.11.0-rc.1)
-
net9.0
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- OpenTelemetry (>= 1.11.0-rc.1)
NuGet packages (297)
Showing the top 5 NuGet packages that depend on OpenTelemetry.Extensions.Hosting:
Package | Downloads |
---|---|
Azure.Monitor.OpenTelemetry.AspNetCore
An OpenTelemetry .NET distro that exports to Azure Monitor |
|
Sitko.Core.App
Sitko.Core is a set of libraries to help build .NET Core applications fast |
|
Steeltoe.Management.OpenTelemetryBase
Steeltoe Management OpenTelemetry |
|
Steeltoe.Management.TracingBase
Base package for enabling request tracing in distributed systems. |
|
IEvangelist.Azure.CosmosRepository
This client library enables client applications to connect to Azure Cosmos via a repository pattern around the official Azure Cosmos .NET SDK. Azure Cosmos is a globally distributed, multi-model database service. For more information, refer to http://azure.microsoft.com/services/cosmos-db/. |
GitHub repositories (132)
Showing the top 5 popular GitHub repositories that depend on OpenTelemetry.Extensions.Hosting:
Repository | Stars |
---|---|
jasontaylordev/CleanArchitecture
Clean Architecture Solution Template for ASP.NET Core
|
|
ardalis/CleanArchitecture
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core
|
|
dotnet/runtime
.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
|
|
dotnet/AspNetCore.Docs
Documentation for ASP.NET Core
|
|
JustArchiNET/ArchiSteamFarm
C# application with primary purpose of farming Steam cards from multiple accounts simultaneously.
|
Version | Downloads | Last updated | |
---|---|---|---|
1.11.0-rc.1 | 2,336 | 12/12/2024 | |
1.10.0 | 1,043,577 | 11/12/2024 | |
1.10.0-rc.1 | 6,748 | 11/1/2024 | |
1.10.0-beta.1 | 22,842 | 9/30/2024 | |
1.9.0 | 14,648,545 | 6/14/2024 | |
1.9.0-rc.1 | 139,545 | 6/7/2024 | |
1.9.0-alpha.1 | 41,215 | 5/20/2024 | |
1.8.1 | 8,542,701 | 4/18/2024 | |
1.8.0 | 2,614,304 | 4/3/2024 | |
1.8.0-rc.1 | 21,134 | 3/27/2024 | |
1.8.0-beta.1 | 48,274 | 3/14/2024 | |
1.7.0 | 9,079,509 | 12/9/2023 | |
1.7.0-rc.1 | 108,276 | 11/30/2023 | |
1.7.0-alpha.1 | 448,960 | 10/17/2023 | |
1.6.0 | 9,089,165 | 9/6/2023 | |
1.6.0-rc.1 | 380,488 | 8/21/2023 | |
1.6.0-alpha.1 | 299,136 | 7/12/2023 | |
1.5.1 | 5,826,217 | 6/26/2023 | |
1.5.0 | 1,465,696 | 6/6/2023 | |
1.5.0-rc.1 | 160,542 | 5/26/2023 | |
1.5.0-alpha.2 | 986,078 | 4/1/2023 | |
1.5.0-alpha.1 | 529,644 | 3/8/2023 | |
1.4.0 | 8,498,514 | 2/24/2023 | |
1.4.0-rc.4 | 696,340 | 2/11/2023 | |
1.4.0-rc.3 | 563,332 | 2/2/2023 | |
1.4.0-rc.2 | 719,316 | 1/9/2023 | |
1.4.0-rc.1 | 1,128,939 | 12/12/2022 | |
1.0.0-rc9.9 | 1,452,883 | 11/7/2022 | |
1.0.0-rc9.8 | 495,994 | 10/17/2022 | |
1.0.0-rc9.7 | 355,086 | 9/30/2022 | |
1.0.0-rc9.6 | 1,271,394 | 8/18/2022 | |
1.0.0-rc9.5 | 1,233,294 | 8/3/2022 | |
1.0.0-rc9.4 | 6,371,617 | 6/3/2022 | |
1.0.0-rc9.3 | 2,163,967 | 4/20/2022 | |
1.0.0-rc9.2 | 1,891,877 | 4/13/2022 | |
1.0.0-rc9.1 | 667,034 | 3/30/2022 | |
1.0.0-rc9 | 2,942,424 | 2/3/2022 | |
1.0.0-rc8 | 5,664,521 | 10/8/2021 | |
1.0.0-rc7 | 2,006,738 | 7/13/2021 | |
1.0.0-rc6 | 310,764 | 6/26/2021 | |
1.0.0-rc5 | 406,973 | 6/9/2021 | |
1.0.0-rc4 | 329,849 | 4/23/2021 | |
1.0.0-rc3 | 496,300 | 3/19/2021 | |
1.0.0-rc2 | 791,034 | 1/30/2021 | |
1.0.0-rc10 | 119,656 | 3/5/2022 | |
1.0.0-rc1.1 | 521,044 | 11/18/2020 | |
0.8.0-beta.1 | 97,237 | 11/5/2020 | |
0.7.0-beta.1 | 15,952 | 10/16/2020 | |
0.6.0-beta.1 | 136,220 | 9/16/2020 | |
0.5.0-beta.2 | 8,338 | 8/28/2020 | |
0.4.0-beta.2 | 114,598 | 7/25/2020 | |
0.3.0-beta.1 | 1,272 | 7/23/2020 | |
0.2.0-alpha.275 | 184,374 | 5/19/2020 |
For highlights and announcements see: https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.11.0-rc.1/RELEASENOTES.md.
For detailed changes see: https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.11.0-rc.1/src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md.