Invoke SDK initialization when using OpenTelemetry.Extensions.Hosting (#2901)

This commit is contained in:
Alan West 2022-02-16 06:48:45 -08:00 committed by GitHub
parent 360957dc44
commit a2c1b6e69e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -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;

View File

@ -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

View File

@ -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>());