Invoke SDK initialization when using OpenTelemetry.Extensions.Hosting (#2901)
This commit is contained in:
parent
360957dc44
commit
a2c1b6e69e
|
|
@ -31,7 +31,7 @@ namespace Utils.Messaging
|
|||
public class MessageReceiver : IDisposable
|
||||
{
|
||||
private static readonly ActivitySource ActivitySource = new ActivitySource(nameof(MessageReceiver));
|
||||
private static readonly TextMapPropagator Propagator = new TraceContextPropagator();
|
||||
private static readonly TextMapPropagator Propagator = Propagators.DefaultTextMapPropagator;
|
||||
|
||||
private readonly ILogger<MessageReceiver> logger;
|
||||
private readonly IConnection connection;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
* Fixes an issue where the initialization of some aspects of the SDK can be
|
||||
delayed when using the `AddOpenTelemetryTracing` and
|
||||
`AddOpenTelemetryMetrics` methods. Namely, self-diagnostics and the default
|
||||
context propagator responsible for propagating trace context and baggage.
|
||||
([#2901](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2901))
|
||||
|
||||
## 1.0.0-rc9
|
||||
|
||||
Released 2022-Feb-02
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ using System;
|
|||
using System.Diagnostics;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Extensions.Hosting.Implementation;
|
||||
using OpenTelemetry.Internal;
|
||||
using OpenTelemetry.Metrics;
|
||||
|
|
@ -91,6 +92,10 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
Guard.ThrowIfNull(services);
|
||||
Guard.ThrowIfNull(createTracerProvider);
|
||||
|
||||
// Accessing Sdk class is just to trigger its static ctor,
|
||||
// which sets default Propagators and default Activity Id format
|
||||
_ = Sdk.SuppressInstrumentation;
|
||||
|
||||
try
|
||||
{
|
||||
services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, TelemetryHostedService>());
|
||||
|
|
@ -115,6 +120,10 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
Debug.Assert(services != null, $"{nameof(services)} must not be null");
|
||||
Debug.Assert(createMeterProvider != null, $"{nameof(createMeterProvider)} must not be null");
|
||||
|
||||
// Accessing Sdk class is just to trigger its static ctor,
|
||||
// which sets default Propagators and default Activity Id format
|
||||
_ = Sdk.SuppressInstrumentation;
|
||||
|
||||
try
|
||||
{
|
||||
services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, TelemetryHostedService>());
|
||||
|
|
|
|||
Loading…
Reference in New Issue