From 8394aa2e86b92593c5bcc368be19dbcf8a943ab7 Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Tue, 15 Feb 2022 17:32:01 -0800 Subject: [PATCH 1/3] Tickle the SDK from OpenTelemetry.Extensions.Hosting --- .../OpenTelemetryServicesExtensions.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/OpenTelemetry.Extensions.Hosting/OpenTelemetryServicesExtensions.cs b/src/OpenTelemetry.Extensions.Hosting/OpenTelemetryServicesExtensions.cs index deace5adb7d..609bd2d71db 100644 --- a/src/OpenTelemetry.Extensions.Hosting/OpenTelemetryServicesExtensions.cs +++ b/src/OpenTelemetry.Extensions.Hosting/OpenTelemetryServicesExtensions.cs @@ -18,6 +18,7 @@ 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 @@ private static IServiceCollection AddOpenTelemetryTracing(this IServiceCollectio Guard.ThrowIfNull(services, nameof(services)); Guard.ThrowIfNull(createTracerProvider, nameof(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()); @@ -115,6 +120,10 @@ private static IServiceCollection AddOpenTelemetryMetrics(this IServiceCollectio 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()); From 48f79577773a356e7729b596a62ef4b3abdc436b Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Tue, 15 Feb 2022 17:34:32 -0800 Subject: [PATCH 2/3] Use the DefaultTextMapPropagator from the microservices example --- examples/MicroserviceExample/Utils/Messaging/MessageReceiver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/MicroserviceExample/Utils/Messaging/MessageReceiver.cs b/examples/MicroserviceExample/Utils/Messaging/MessageReceiver.cs index 72dfa63040d..e5e321ad14f 100644 --- a/examples/MicroserviceExample/Utils/Messaging/MessageReceiver.cs +++ b/examples/MicroserviceExample/Utils/Messaging/MessageReceiver.cs @@ -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 logger; private readonly IConnection connection; From 5c303270c9af8a6b09747c1888191b988f808b69 Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Tue, 15 Feb 2022 20:22:11 -0800 Subject: [PATCH 3/3] Update changelog --- src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md b/src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md index 7431f10d428..a65a5cd7812 100644 --- a/src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md +++ b/src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md @@ -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