diff --git a/samples/Sentry.Samples.AspNetCore.Blazor.Server/Program.cs b/samples/Sentry.Samples.AspNetCore.Blazor.Server/Program.cs index 5192452051..dda6c4779c 100644 --- a/samples/Sentry.Samples.AspNetCore.Blazor.Server/Program.cs +++ b/samples/Sentry.Samples.AspNetCore.Blazor.Server/Program.cs @@ -2,7 +2,7 @@ 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); @@ -10,6 +10,15 @@ 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() @@ -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; diff --git a/samples/Sentry.Samples.AspNetCore.Blazor.Server/Sentry.Samples.AspNetCore.Blazor.Server.csproj b/samples/Sentry.Samples.AspNetCore.Blazor.Server/Sentry.Samples.AspNetCore.Blazor.Server.csproj index 7dac418922..d547b02518 100644 --- a/samples/Sentry.Samples.AspNetCore.Blazor.Server/Sentry.Samples.AspNetCore.Blazor.Server.csproj +++ b/samples/Sentry.Samples.AspNetCore.Blazor.Server/Sentry.Samples.AspNetCore.Blazor.Server.csproj @@ -18,13 +18,14 @@ - + + diff --git a/samples/Sentry.Samples.GraphQL.Server/Program.cs b/samples/Sentry.Samples.GraphQL.Server/Program.cs index ab38e073b6..5eb4f9f537 100644 --- a/samples/Sentry.Samples.GraphQL.Server/Program.cs +++ b/samples/Sentry.Samples.GraphQL.Server/Program.cs @@ -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; @@ -29,6 +29,15 @@ 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 @@ -36,21 +45,17 @@ public static WebApplication BuildWebApplication(string[] args) .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 diff --git a/samples/Sentry.Samples.GraphQL.Server/Sentry.Samples.GraphQL.Server.csproj b/samples/Sentry.Samples.GraphQL.Server/Sentry.Samples.GraphQL.Server.csproj index 86170f0edc..baabb06778 100644 --- a/samples/Sentry.Samples.GraphQL.Server/Sentry.Samples.GraphQL.Server.csproj +++ b/samples/Sentry.Samples.GraphQL.Server/Sentry.Samples.GraphQL.Server.csproj @@ -17,6 +17,7 @@ + @@ -29,7 +30,7 @@ - + diff --git a/samples/Sentry.Samples.OpenTelemetry.AspNetCore/README.md b/samples/Sentry.Samples.OpenTelemetry.AspNetCore/README.md index e97237ae1c..2fdcb82755 100644 --- a/samples/Sentry.Samples.OpenTelemetry.AspNetCore/README.md +++ b/samples/Sentry.Samples.OpenTelemetry.AspNetCore/README.md @@ -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; 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 }); ``` @@ -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. diff --git a/samples/Sentry.Samples.OpenTelemetry.Console/README.md b/samples/Sentry.Samples.OpenTelemetry.Console/README.md index 78558b0b7a..0bc3ede1e8 100644 --- a/samples/Sentry.Samples.OpenTelemetry.Console/README.md +++ b/samples/Sentry.Samples.OpenTelemetry.Console/README.md @@ -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 => { - options.Dsn = "...Your DSN..."; + options.Dsn = dsn; options.TracesSampleRate = 1.0; - options.UseOpenTelemetry(); // <-- Configure Sentry to use OpenTelemetry trace information + options.UseOtlp(); // <-- Configure Sentry to use OpenTelemetry trace information }); ``` @@ -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. diff --git a/src/Sentry.OpenTelemetry/SentryOptionsExtensions.cs b/src/Sentry.OpenTelemetry/SentryOptionsExtensions.cs index e6bacbfd8a..8d237870ee 100644 --- a/src/Sentry.OpenTelemetry/SentryOptionsExtensions.cs +++ b/src/Sentry.OpenTelemetry/SentryOptionsExtensions.cs @@ -8,6 +8,10 @@ namespace Sentry.OpenTelemetry; /// public static class SentryOptionsExtensions { + internal const string ObsoleteMessage = + "Use UseOtlp from the Sentry.OpenTelemetry.Exporter package instead. " + + "This method will be removed in future versions."; + /// /// Enables OpenTelemetry instrumentation with Sentry /// @@ -28,10 +32,7 @@ public static class SentryOptionsExtensions /// It's recommended that you set this to true since mixing OpenTelemetry and Sentry traces may yield /// unexpected results. It is false by default for backward compatibility only. /// - /// - /// 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. - /// + [Obsolete(ObsoleteMessage)] public static void UseOpenTelemetry(this SentryOptions options, TracerProviderBuilder traceProviderBuilder, TextMapPropagator? defaultTextMapPropagator = null, bool disableSentryTracing = false) { @@ -52,10 +53,7 @@ public static void UseOpenTelemetry(this SentryOptions options, TracerProviderBu /// It's recommended that you set this to true since mixing OpenTelemetry and Sentry traces may yield /// unexpected results. It is false by default for backward compatibility only. /// - /// - /// 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. - /// + [Obsolete(ObsoleteMessage)] public static void UseOpenTelemetry(this SentryOptions options, bool disableSentryTracing = false) { options.Instrumenter = Instrumenter.OpenTelemetry; diff --git a/src/Sentry.OpenTelemetry/TracerProviderBuilderExtensions.cs b/src/Sentry.OpenTelemetry/TracerProviderBuilderExtensions.cs index 573942131f..2c382a2803 100644 --- a/src/Sentry.OpenTelemetry/TracerProviderBuilderExtensions.cs +++ b/src/Sentry.OpenTelemetry/TracerProviderBuilderExtensions.cs @@ -11,6 +11,10 @@ namespace Sentry.OpenTelemetry; /// public static class TracerProviderBuilderExtensions { + internal const string ObsoleteMessage = + "Use AddSentryOtlpExporter from the Sentry.OpenTelemetry.Exporter package instead. " + + "This method will be removed in version 7.0.0."; + /// /// /// Ensures OpenTelemetry trace information is sent to Sentry. OpenTelemetry spans will be converted to Sentry spans @@ -35,10 +39,7 @@ public static class TracerProviderBuilderExtensions /// /// /// The supplied for chaining. - /// - /// 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. - /// + [Obsolete(ObsoleteMessage)] public static TracerProviderBuilder AddSentry(this TracerProviderBuilder tracerProviderBuilder, TextMapPropagator? defaultTextMapPropagator = null) {