Skip to content

Commit

Permalink
Update TracerProviderBuilderExtensions.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescrosswell committed Feb 7, 2024
1 parent aaf69bb commit fbe26ad
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Sentry.OpenTelemetry/TracerProviderBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Trace;
Expand All @@ -10,6 +11,9 @@ namespace Sentry.OpenTelemetry;
/// </summary>
public static class TracerProviderBuilderExtensions
{
private const string SentryNotInitializedMessage =
"No IHub service registered and SentrySdk.CurrentHub is null. Sentry doesn't appear to have been initialized correctly.";

/// <summary>
/// Ensures OpenTelemetry trace information is sent to Sentry.
/// </summary>
Expand Down Expand Up @@ -41,7 +45,12 @@ public static TracerProviderBuilder AddSentry(this TracerProviderBuilder tracerP
enrichers.Add(new AspNetCoreEnricher(userFactory));
}
var hub = services.GetRequiredService<IHub>();
var hub = services.GetService<IHub>() ?? SentrySdk.CurrentHub;
if (hub.IsEnabled)
{
var logger = services.GetService<ILogger<TracerProviderBuilder>>();
logger?.LogWarning(SentryNotInitializedMessage);
}
return new SentrySpanProcessor(hub, enrichers);
});
}
Expand Down

0 comments on commit fbe26ad

Please sign in to comment.