Attempt to reduce provider lifetime issues (#2848)
This commit is contained in:
parent
c1c5436023
commit
3833a4f503
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ namespace OpenTelemetry.Logs
|
|||
}
|
||||
|
||||
this.disposed = true;
|
||||
OpenTelemetrySdkEventSource.Log.ProviderDisposed(nameof(OpenTelemetryLoggerProvider));
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
|
|
|
|||
|
|
@ -491,6 +491,7 @@ namespace OpenTelemetry.Metrics
|
|||
}
|
||||
|
||||
this.disposed = true;
|
||||
OpenTelemetrySdkEventSource.Log.ProviderDisposed(nameof(MeterProvider));
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
|
|
|
|||
|
|
@ -375,6 +375,7 @@ namespace OpenTelemetry.Trace
|
|||
}
|
||||
|
||||
this.disposed = true;
|
||||
OpenTelemetrySdkEventSource.Log.ProviderDisposed(nameof(TracerProvider));
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
|
|
|
|||
Loading…
Reference in New Issue