Attempt to reduce provider lifetime issues (#2848)

This commit is contained in:
Cijo Thomas 2022-02-02 13:57:53 -08:00 committed by GitHub
parent c1c5436023
commit 3833a4f503
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 0 deletions

View File

@ -31,6 +31,16 @@ using OpenTelemetry.Metrics;
using var meterProvider = Sdk.CreateMeterProviderBuilder().Build();
```
In a typical application, a single `MeterProvider` is created at application
startup and disposed at application shutdown. It is important to ensure that the
provider is not disposed too early. Actual mechanism depends on the application
type. For example, in a typical ASP.NET application, `MeterProvider` is created
in `Application_Start`, and disposed in `Application_End` (both methods part of
Global.asax.cs file) as shown [here](../../../examples/AspNet/Global.asax.cs). In
a typical ASP.NET Core application, `MeterProvider` lifetime is managed by
leveraging the built-in Dependency Injection container as shown
[here](../../../examples/AspNetCore/Startup.cs).
## MeterProvider configuration
`MeterProvider` holds the metrics configuration, which includes the following:

View File

@ -34,6 +34,16 @@ using OpenTelemetry.Trace;
using var tracerProvider = Sdk.CreateTracerProviderBuilder().Build();
```
In a typical application, a single `TracerProvider` is created at application
startup and disposed at application shutdown. It is important to ensure that the
provider is not disposed too early. Actual mechanism depends on the application
type. For example, in a typical ASP.NET application, `TracerProvider` is created
in `Application_Start`, and disposed in `Application_End` (both methods part of
Global.asax.cs file) as shown [here](../../../examples/AspNet/Global.asax.cs). In
a typical ASP.NET Core application, `TracerProvider` lifetime is managed by
leveraging the built-in Dependency Injection container as shown
[here](../../../examples/AspNetCore/Startup.cs).
## TracerProvider configuration
`TracerProvider` holds the tracing configuration, which includes the following:

View File

@ -354,6 +354,12 @@ namespace OpenTelemetry.Internal
this.WriteEvent(36, instrumentName, reason, fix);
}
[Event(37, Message = "'{0}' Disposed.", Level = EventLevel.Informational)]
public void ProviderDisposed(string providerName)
{
this.WriteEvent(37, providerName);
}
#if DEBUG
public class OpenTelemetryEventListener : EventListener
{

View File

@ -133,6 +133,7 @@ namespace OpenTelemetry.Logs
}
this.disposed = true;
OpenTelemetrySdkEventSource.Log.ProviderDisposed(nameof(OpenTelemetryLoggerProvider));
}
base.Dispose(disposing);

View File

@ -491,6 +491,7 @@ namespace OpenTelemetry.Metrics
}
this.disposed = true;
OpenTelemetrySdkEventSource.Log.ProviderDisposed(nameof(MeterProvider));
}
base.Dispose(disposing);

View File

@ -375,6 +375,7 @@ namespace OpenTelemetry.Trace
}
this.disposed = true;
OpenTelemetrySdkEventSource.Log.ProviderDisposed(nameof(TracerProvider));
}
base.Dispose(disposing);