Skip to content

feat(otel): mark span processor based OpenTelemetry setup methods as obsolete - #5586

Open
jamescrosswell wants to merge 2 commits into
mainfrom
obsolete-potel-init
Open

jamescrosswell wants to merge 2 commits into
mainfrom
obsolete-potel-init

Conversation

@jamescrosswell

Copy link
Copy Markdown
Collaborator

Marks the span-processor based ("POTEL") OpenTelemetry setup methods in Sentry.OpenTelemetry as [Obsolete], ahead of removing them in 7.0.0:

  • TracerProviderBuilder.AddSentry(...) → use AddSentryOtlpExporter(dsn)
  • SentryOptions.UseOpenTelemetry(...) (both overloads) → use UseOtlp()

The replacements live in the Sentry.OpenTelemetry.Exporter package, added in #4899. Obsolete warnings name that package so users know where to find the new methods.

The GraphQL.Server and AspNetCore.Blazor.Server samples still used the old methods, so they now use OTLP. The OpenTelemetry sample READMEs had outdated snippets too, and those are fixed.

Closes #4932

🤖 Generated with Claude Code

…lete

AddSentry and UseOpenTelemetry will be removed in 7.0.0 in favour of
AddSentryOtlpExporter/UseOtlp from Sentry.OpenTelemetry.Exporter. Samples
still using them are migrated to OTLP.

Closes #4932

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Comment thread src/Sentry.OpenTelemetry/SentryOptionsExtensions.cs Outdated
Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com>
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.76%. Comparing base (cba98c9) to head (0ddd862).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5586   +/-   ##
=======================================
  Coverage   74.76%   74.76%           
=======================================
  Files         515      515           
  Lines       18963    18963           
  Branches     3694     3694           
=======================================
  Hits        14177    14177           
  Misses       3908     3908           
  Partials      878      878           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jamescrosswell
jamescrosswell marked this pull request as ready for review September 17, 2026 03:10
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Sep 17, 2026
[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].

{
internal const string ObsoleteMessage =
"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.";

.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 =>

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!

SentrySdk.Init(o =>
{
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.

/// </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.

/// </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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mark POTEL init overloads as obsolete prior to phasing these out

2 participants