Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 6 additions & 10 deletions docs/trace/customizing-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ using OpenTelemetry.Trace;
var appBuilder = WebApplication.CreateBuilder(args);

appBuilder.Services.AddOpenTelemetry()
.WithTracing(builder => builder.AddConsoleExporter())
.StartWithHost();
.WithTracing(builder => builder.AddConsoleExporter());
```

> **Note**
> The
[StartWithHost](../../../src/OpenTelemetry.Extensions.Hosting/README.md#extension-method-reference)
[AddOpenTelemetry](../../../src/OpenTelemetry.Extensions.Hosting/README.md#extension-method-reference)
extension automatically starts and stops the `TracerProvider` with the host.

### Using Sdk.CreateTracerProviderBuilder
Expand Down Expand Up @@ -442,16 +441,15 @@ appBuilder.Services.AddSingleton<MyCustomService>();

appBuilder.Services.AddOpenTelemetry()
.WithTracing(builder => builder
.AddProcessor<MyCustomProcessor>())
.StartWithHost();
.AddProcessor<MyCustomProcessor>());
```

When using the `AddOpenTelemetry` & `WithTracing` extension methods the
`TracerProvider` does not own its `IServiceCollection` and instead registers
into an existing collection (typically the collection used is the one managed by
the application host). The `TracerProviderBuilder` will be able to access all
services registered into that collection. For lifecycle management, the
`StartWithHost` registers an [IHostedService
`AddOpenTelemetry` registers an [IHostedService
](https://learn.microsoft.com/dotnet/api/microsoft.extensions.hosting.ihostedservice)
which is used to automatically start the `TracerProvider` when the host starts
and the host will automatically shutdown and dispose the `TracerProvider` when
Expand Down Expand Up @@ -651,8 +649,7 @@ appBuilder.Services.Configure<JaegerExporterOptions>(
appBuilder.Configuration.GetSection("OpenTelemetry:Jaeger"));

appBuilder.Services.AddOpenTelemetry()
.WithTracing(builder => builder.AddJaegerExporter())
.StartWithHost();
.WithTracing(builder => builder.AddJaegerExporter());
```

The OpenTelemetry .NET SDK supports running multiple `TracerProvider`s inside
Expand Down Expand Up @@ -696,6 +693,5 @@ appBuilder.Services.Configure<JaegerExporterOptions>(
appBuilder.Services.AddOpenTelemetry()
.WithTracing(builder => builder
.AddJaegerExporter(name: "JaegerPrimary", configure: null)
.AddJaegerExporter(name: "JaegerSecondary", configure: null))
.StartWithHost();
.AddJaegerExporter(name: "JaegerSecondary", configure: null));
```
2 changes: 1 addition & 1 deletion docs/trace/extending-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ this case).
> **Note**
> `ConfigureOpenTelemetryTracerProvider` and
`ConfigureOpenTelemetryMeterProvider` do not automatically start OpenTelemetry.
The host is responsible for either calling `StartWithHost` in the
The host is responsible for either calling `AddOpenTelemetry` in the
[OpenTelemetry.Extensions.Hosting](../../../src/OpenTelemetry.Extensions.Hosting/README.md)
package, calling `Build` when using the `Sdk.CreateTracerProviderBuilder` and
`Sdk.CreateMeterProviderBuilder` methods, or by accessing the `TracerProvider`
Expand Down
5 changes: 2 additions & 3 deletions docs/trace/getting-started-aspnetcore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ appBuilder.Services.AddOpenTelemetry()
.AddService(serviceName: "OTel.NET Getting Started"))
.WithTracing(builder => builder
.AddAspNetCoreInstrumentation()
.AddConsoleExporter())
.StartWithHost();
.AddConsoleExporter());
```

> **Note**
> The `StartWithHost` extension is part of the
> The `AddOpenTelemetry` extension is part of the
[OpenTelemetry.Extensions.Hosting](../../../src/OpenTelemetry.Extensions.Hosting/README.md)
package.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static class OpenTelemetryDependencyInjectionMetricsServiceCollectionExte
/// <item>A <see cref="MeterProvider"/> will not be created automatically
/// using this method. To begin collecting metrics use the
/// <c>IServiceCollection.AddOpenTelemetry</c> extension in the
/// <c>OpenTelemetry</c> package.</item>
/// <c>OpenTelemetry.Extensions.Hosting</c> package.</item>
/// </list>
/// </remarks>
/// <param name="services">The <see cref="IServiceCollection" /> to add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static class OpenTelemetryDependencyInjectionTracingServiceCollectionExte
/// <item>A <see cref="TracerProvider"/> will not be created automatically
/// using this method. To begin collecting metrics use the
/// <c>IServiceCollection.AddOpenTelemetry</c> extension in the
/// <c>OpenTelemetry</c> package.</item>
/// <c>OpenTelemetry.Extensions.Hosting</c> package.</item>
/// </list>
/// </remarks>
/// <param name="services">The <see cref="IServiceCollection" /> to add
Expand Down