Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,6 +92,10 @@ private static IServiceCollection AddOpenTelemetryTracing(this IServiceCollectio
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>());
Expand All @@ -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<IHostedService, TelemetryHostedService>());
Expand Down