Skip to content
Open
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
21 changes: 13 additions & 8 deletions samples/Sentry.Samples.AspNetCore.Blazor.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@

using Microsoft.AspNetCore.Components.Server.Circuits;
using OpenTelemetry.Trace;
using Sentry.OpenTelemetry;
using Sentry.OpenTelemetry.Exporter;
using Sentry.Samples.AspNetCore.Blazor.Server.Services;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();

#if SENTRY_DSN_DEFINED_IN_ENV
var dsn = Environment.GetEnvironmentVariable("SENTRY_DSN")
?? throw new InvalidOperationException("SENTRY_DSN environment variable is not set");
#else
// A DSN is required. You can set here in code, or you can set it in the SENTRY_DSN environment variable.
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
var dsn = SamplesShared.Dsn;
#endif

#if NET10_0_OR_GREATER
// OpenTelemetry is required for the new .NET 10 Blazor telemetry features
builder.Services.AddOpenTelemetry()
Expand All @@ -19,19 +28,15 @@
tracing.AddSource("Microsoft.AspNetCore.Components.Server.Circuits");
tracing.AddAspNetCoreInstrumentation();
// Add Sentry as an exporter
tracing.AddSentry();
tracing.AddSentryOtlpExporter(dsn);
});
#endif

builder.WebHost.UseSentry(options =>
{
#if !SENTRY_DSN_DEFINED_IN_ENV
// A DSN is required. You can set here in code, in the SENTRY_DSN environment variable or in your appsettings.json
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
options.Dsn = SamplesShared.Dsn;
#endif
options.Dsn = dsn;
#if NET10_0_OR_GREATER
options.UseOpenTelemetry();
options.UseOtlp();
options.AddEventProcessor(new BlazorEventProcessor());
#endif
options.TracesSampleRate = 1.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Sentry.AspNetCore.Blazor.WebAssembly\Sentry.AspNetCore.Blazor.WebAssembly.csproj" />
<ProjectReference Include="..\..\src\Sentry.AspNetCore\Sentry.AspNetCore.csproj" />
<ProjectReference Include="..\..\src\Sentry.OpenTelemetry\Sentry.OpenTelemetry.csproj" />
<ProjectReference Include="..\..\src\Sentry.OpenTelemetry.Exporter\Sentry.OpenTelemetry.Exporter.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="OpenTelemetry" Version="1.18.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.18.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.18.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.18.0" />
</ItemGroup>

</Project>
21 changes: 13 additions & 8 deletions samples/Sentry.Samples.GraphQL.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using GraphQL.Types;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using Sentry.OpenTelemetry;
using Sentry.OpenTelemetry.Exporter;
using Sentry.Samples.GraphQL.Server.Notes;

namespace Sentry.Samples.GraphQL.Server;
Expand All @@ -29,28 +29,33 @@ public static WebApplication BuildWebApplication(string[] args)
{
var builder = WebApplication.CreateBuilder(args);

#if SENTRY_DSN_DEFINED_IN_ENV
var dsn = Environment.GetEnvironmentVariable("SENTRY_DSN")
?? throw new InvalidOperationException("SENTRY_DSN environment variable is not set");
#else
// A DSN is required. You can set here in code, or you can set it in the SENTRY_DSN environment variable.
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
var dsn = SamplesShared.Dsn;
#endif

builder.Services.AddOpenTelemetry()
.WithTracing(tracerProviderBuilder =>
tracerProviderBuilder
.AddSource(GraphQLTelemetryProvider.SourceName) // <-- Ensure telemetry is gathered from graphql
.ConfigureResource(resource => resource.AddService("Sentry.Samples.GraphQL.Server"))
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddSentry() // <-- Ensure telemetry is sent to Sentry
.AddSentryOtlpExporter(dsn) // <-- Ensure telemetry is sent to Sentry
);

builder.WebHost.UseSentry(options =>
{
#if !SENTRY_DSN_DEFINED_IN_ENV
// A DSN is required. You can set here in code, or you can set it in the SENTRY_DSN environment variable.
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
options.Dsn = SamplesShared.Dsn;
#endif
options.Dsn = dsn;

options.TracesSampleRate = 1.0;
options.Debug = true;
options.SendDefaultPii = true;
options.UseOpenTelemetry(); // <-- Configure Sentry to use OpenTelemetry trace information
options.UseOtlp(); // <-- Configure Sentry to use OpenTelemetry trace information
});

builder.Services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.18.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.18.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.18.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.18.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.0" />
</ItemGroup>

Expand All @@ -29,7 +30,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Sentry.AspNetCore\Sentry.AspNetCore.csproj" />
<ProjectReference Include="..\..\src\Sentry.OpenTelemetry\Sentry.OpenTelemetry.csproj" />
<ProjectReference Include="..\..\src\Sentry.OpenTelemetry.Exporter\Sentry.OpenTelemetry.Exporter.csproj" />
<ProjectReference Include="..\..\src\Sentry\Sentry.csproj" />
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions samples/Sentry.Samples.OpenTelemetry.AspNetCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService(Telemetry.ServiceName))
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddSentry() // <-- Configure OpenTelemetry to send trace information to Sentry
.AddSentryOtlpExporter(dsn) // <-- Configure OpenTelemetry to send trace information to Sentry
);

builder.WebHost.UseSentry(options =>
{
options.Dsn = "...Your DSN...";
options.Dsn = dsn;

@ric-oliv ric-oliv Sep 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here in the README we don't have the var dsn from the samples, but not a big deal.
We could add the var dsn = "...Your DSN..." declaration above in the examples, or not. Your call!

options.Debug = builder.Environment.IsDevelopment();
options.TracesSampleRate = 1.0;
options.UseOpenTelemetry(); // <-- Configure Sentry to use OpenTelemetry trace information
options.UseOtlp(); // <-- Configure Sentry to use OpenTelemetry trace information
});
```

Expand All @@ -33,4 +33,4 @@ and/or to downstream services.

If you need to further customize header propagation in your application (e.g. propagating other vendor specific headers)
then you can do so by creating a `CompositeTextMapPropagator` consisting of the custom propagator(s) you need plus the
`SentryPropagator`. You can supply this as an optional parameter to the `AddSentry` method.
`SentryPropagator`. You can supply this as an optional parameter to the `AddSentryOtlpExporter` method.
8 changes: 4 additions & 4 deletions samples/Sentry.Samples.OpenTelemetry.Console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ using var tracerProvider = Sdk.CreateTracerProviderBuilder()
resource.AddService(
serviceName: serviceName,
serviceVersion: serviceVersion))
.AddSentry() // <-- Configure OpenTelemetry to send traces to Sentry
.AddSentryOtlpExporter(dsn) // <-- Configure OpenTelemetry to send traces to Sentry
.Build();

SentrySdk.Init(o =>

@ric-oliv ric-oliv Sep 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match the rest of the readme:

Suggested change
SentrySdk.Init(o =>
SentrySdk.Init(options =>

{
options.Dsn = "...Your DSN...";
options.Dsn = dsn;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about the "var dsn" reference.

options.TracesSampleRate = 1.0;
options.UseOpenTelemetry(); // <-- Configure Sentry to use OpenTelemetry trace information
options.UseOtlp(); // <-- Configure Sentry to use OpenTelemetry trace information
});
```

Expand All @@ -29,4 +29,4 @@ and/or to downstream services.

If you need to further customize header propagation in your application (e.g. propagating other vendor specific headers)
then you can do so by creating a `CompositeTextMapPropagator` consisting of the custom propagator(s) you need plus the
`SentryPropagator`. You can supply this as an optional parameter to the `AddSentry` method.
`SentryPropagator`. You can supply this as an optional parameter to the `AddSentryOtlpExporter` method.
14 changes: 6 additions & 8 deletions src/Sentry.OpenTelemetry/SentryOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace Sentry.OpenTelemetry;
/// </summary>
public static class SentryOptionsExtensions
{
internal const string ObsoleteMessage =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other places we define this variable with more explicit names... Here we could use e.g. ObsoleteUseOpenTelemetry.

"Use UseOtlp from the Sentry.OpenTelemetry.Exporter package instead. " +
"This method will be removed in future versions.";

/// <summary>
/// Enables OpenTelemetry instrumentation with Sentry
/// </summary>
Expand All @@ -28,10 +32,7 @@ public static class SentryOptionsExtensions
/// It's recommended that you set this to <c>true</c> since mixing OpenTelemetry and Sentry traces may yield
/// unexpected results. It is <c>false</c> by default for backward compatibility only.
/// </param>
/// <remarks>
/// This method of initialising the Sentry OpenTelemetry integration will be deprecated in a future major release.
/// We recommend you use the Sentry.OpenTelemetry.Exporter integration instead.
/// </remarks>
[Obsolete(ObsoleteMessage)]
public static void UseOpenTelemetry(this SentryOptions options, TracerProviderBuilder traceProviderBuilder,
TextMapPropagator? defaultTextMapPropagator = null, bool disableSentryTracing = false)
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The obsolete method UseOpenTelemetry calls other obsolete methods without suppressing warning CS0618. With TreatWarningsAsErrors enabled, this could cause a build failure.
Severity: MEDIUM

Suggested Fix

Wrap the calls to the obsolete methods within the UseOpenTelemetry method with #pragma warning disable CS0618 and a corresponding #pragma warning restore CS0618. This will explicitly suppress the compiler warning and prevent a potential build failure, aligning with existing patterns in the codebase.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/Sentry.OpenTelemetry/SentryOptionsExtensions.cs#L38-L43

Potential issue: The project is configured with
`<TreatWarningsAsErrors>true</TreatWarningsAsErrors>`. The `[Obsolete]` method
`UseOpenTelemetry` at lines 38-43 calls other `[Obsolete]` methods. While the C#
compiler sometimes suppresses `CS0618` warnings for calls from one obsolete member to
another, this behavior is not guaranteed and is context-dependent. Given that the
codebase contains numerous explicit `#pragma warning disable CS0618` suppressions for
similar cases, the absence of one here creates a tangible risk of a build failure, which
would prevent the code from being deployed.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C# skips the obsolete warning when the code making the call is itself marked [Obsolete].

Expand All @@ -52,10 +53,7 @@ public static void UseOpenTelemetry(this SentryOptions options, TracerProviderBu
/// It's recommended that you set this to <c>true</c> since mixing OpenTelemetry and Sentry traces may yield
/// unexpected results. It is <c>false</c> by default for backward compatibility only.
/// </param>
/// <remarks>
/// This method of initialising the Sentry OpenTelemetry integration will be deprecated in a future major release.
/// We recommend you use the Sentry.OpenTelemetry.Exporter integration instead.
/// </remarks>
[Obsolete(ObsoleteMessage)]
public static void UseOpenTelemetry(this SentryOptions options, bool disableSentryTracing = false)
{
options.Instrumenter = Instrumenter.OpenTelemetry;
Expand Down
9 changes: 5 additions & 4 deletions src/Sentry.OpenTelemetry/TracerProviderBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace Sentry.OpenTelemetry;
/// </summary>
public static class TracerProviderBuilderExtensions
{
internal const string ObsoleteMessage =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we could use e.g. ObsoleteAddSentry.

"Use AddSentryOtlpExporter from the Sentry.OpenTelemetry.Exporter package instead. " +
"This method will be removed in version 7.0.0.";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"This method will be removed in version 7.0.0.";
"This method will be removed in future versions.";


/// <summary>
/// <para>
/// Ensures OpenTelemetry trace information is sent to Sentry. OpenTelemetry spans will be converted to Sentry spans
Expand All @@ -35,10 +39,7 @@ public static class TracerProviderBuilderExtensions
/// </para>
/// </param>
/// <returns>The supplied <see cref="TracerProviderBuilder"/> for chaining.</returns>
/// <remarks>
/// This method of initialising the Sentry OpenTelemetry integration will be deprecated in a future major release.
/// We recommend you use the Sentry.OpenTelemetry.Exporter integration instead.
/// </remarks>
[Obsolete(ObsoleteMessage)]
public static TracerProviderBuilder AddSentry(this TracerProviderBuilder tracerProviderBuilder,
TextMapPropagator? defaultTextMapPropagator = null)
{
Expand Down
Loading