From e5d1482dc6b481f8a7ff76f22695927982640b16 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Mon, 9 Jun 2025 20:43:15 +1200 Subject: [PATCH 1/4] chore: Remove DSN from samples Replaces #4238 To avoid SDK users accidentally using the DSN used internally to maintain the Sentry SDK, the DSN has been removed from all of the sample projects. SDK maintainers can either set this as an environment variable or, as with other SDK users, set it manually in the `samples/SamplesShared.cs` file (although changes to that file should never be checked in). #skip-changelog --- .gitignore | 1 + Directory.Build.props | 5 +++ samples/Directory.Build.targets | 40 +++++++++++++++++++ samples/SamplesShared.cs | 23 +++++++++++ .../Sentry.Samples.Android/MainActivity.cs | 12 +++++- .../Program.cs | 7 +++- .../Program.cs | 6 ++- .../Program.cs | 6 ++- .../Sentry.Samples.AspNetCore.Grpc/Program.cs | 7 ++++ .../appsettings.json | 2 +- .../Sentry.Samples.AspNetCore.Mvc/Program.cs | 7 ++++ .../appsettings.json | 2 +- .../Program.cs | 8 +++- .../appsettings.json | 2 +- .../Program.cs | 6 ++- .../LambdaEntryPoint.cs | 9 ++++- .../appsettings.json | 2 +- .../Program.cs | 5 ++- .../Sentry.Samples.Console.Basic/Program.cs | 6 ++- .../Program.cs | 6 ++- .../Program.cs | 6 ++- .../Sentry.Samples.Console.Native/Program.cs | 6 ++- .../Program.cs | 6 ++- .../Sentry.Samples.EntityFramework/Program.cs | 6 ++- samples/Sentry.Samples.GenericHost/Program.cs | 8 ++++ .../appsettings.json | 2 +- .../Function.cs | 2 + .../appsettings.json | 2 +- .../Program.cs | 8 ++-- .../Sentry.Samples.GraphQL.Server/Program.cs | 6 ++- samples/Sentry.Samples.Hangfire/Program.cs | 2 + .../Sentry.Samples.Hangfire/appsettings.json | 2 +- samples/Sentry.Samples.Ios/AppDelegate.cs | 11 ++++- samples/Sentry.Samples.Log4Net/app.config | 2 +- samples/Sentry.Samples.ME.Logging/Program.cs | 6 ++- .../Sentry.Samples.MacCatalyst/AppDelegate.cs | 13 +++++- samples/Sentry.Samples.MacOS/AppDelegate.cs | 6 ++- samples/Sentry.Samples.Maui/MauiProgram.cs | 15 +++++-- samples/Sentry.Samples.NLog/NLog.config | 3 +- samples/Sentry.Samples.NLog/Program.cs | 14 +++---- .../Program.cs | 8 ++-- .../Program.cs | 6 ++- samples/Sentry.Samples.Serilog/Program.cs | 6 ++- src/Sentry/Internal/SettingLocator.cs | 17 +++++++- ...reSentryWebHostBuilder.IntegrationTests.cs | 10 ++++- test/Sentry.NLog.Tests/SentryTargetTests.cs | 5 ++- .../Internals/SettingLocatorTests.cs | 10 ++++- ...tryGraphQlHttpFailedRequestHandlerTests.cs | 2 +- .../SentryHttpFailedRequestHandlerTests.cs | 2 +- test/Sentry.Tests/SentrySdkTests.cs | 5 ++- 50 files changed, 290 insertions(+), 69 deletions(-) create mode 100644 samples/SamplesShared.cs diff --git a/.gitignore b/.gitignore index f8d880a8e7..23c230d87a 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ test/**/*.apk /tools/ *.log .sentry-native +**/EnvironmentVariables.g.cs # Download cache for Cocoa SDK modules/sentry-cocoa diff --git a/Directory.Build.props b/Directory.Build.props index f4b108ce6e..0387cff596 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -67,6 +67,11 @@ $(DefineConstants);CI_BUILD + + + $(DefineConstants);SENTRY_DSN_DEFINED_IN_ENV + + diff --git a/samples/Directory.Build.targets b/samples/Directory.Build.targets index 59c5962462..d8a727cf4f 100644 --- a/samples/Directory.Build.targets +++ b/samples/Directory.Build.targets @@ -7,4 +7,44 @@ + + + + + + + + + + + + + + + + + + diff --git a/samples/SamplesShared.cs b/samples/SamplesShared.cs new file mode 100644 index 0000000000..7a640a410d --- /dev/null +++ b/samples/SamplesShared.cs @@ -0,0 +1,23 @@ +namespace Sentry.Samples; + +public static class SamplesShared +{ +#if !SENTRY_DSN_DEFINED_IN_ENV + /// + /// + /// You must specify a DSN. See https://docs.sentry.io/product/sentry-basics/dsn-explainer/ + /// + /// + /// On mobile platforms (iOS, Android or MacCatalyst), this should be done in code. + /// + /// + /// On other platforms you can set this in code and it is also possible to set this via an environment variable or + /// via configuration bindings (e.g. in an app.config or an appsettings.json file). + /// + /// +#if !CI_BUILD + #error Sign up for a free Sentry Account and enter your DSN here +#endif + public const string Dsn = "ENTER_YOUR_DSN_HERE"; +#endif +} diff --git a/samples/Sentry.Samples.Android/MainActivity.cs b/samples/Sentry.Samples.Android/MainActivity.cs index e098254833..5fc26de941 100644 --- a/samples/Sentry.Samples.Android/MainActivity.cs +++ b/samples/Sentry.Samples.Android/MainActivity.cs @@ -9,7 +9,17 @@ protected override void OnCreate(Bundle? savedInstanceState) { SentrySdk.Init(options => { - options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; +#if !SENTRY_DSN_DEFINED_IN_ENV + // You must specify a DSN. On mobile platforms, this should be done in code here. + // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/ + options.Dsn = SamplesShared.Dsn; +#else + // To make things easier for the SDK maintainers our samples check for a SENTRY_DSN environment variable + // and write this (as a constant) into an EnvironmentVariables class. Generally, you won't want to do + // this in your own mobile projects though - you should set the DSN in code as above + options.Dsn = EnvironmentVariables.Dsn; +#endif + options.SendDefaultPii = true; // adds the user's IP address automatically // Android specific .NET features are under the Android properties: diff --git a/samples/Sentry.Samples.AspNetCore.Basic/Program.cs b/samples/Sentry.Samples.AspNetCore.Basic/Program.cs index a5757beb4f..e4767ad918 100644 --- a/samples/Sentry.Samples.AspNetCore.Basic/Program.cs +++ b/samples/Sentry.Samples.AspNetCore.Basic/Program.cs @@ -2,8 +2,11 @@ builder.WebHost.UseSentry(options => { - // A DSN is required. You can set it here, or in configuration, or in an environment variable. - options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; +#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 // Enable Sentry performance monitoring options.TracesSampleRate = 1.0; diff --git a/samples/Sentry.Samples.AspNetCore.Blazor.Server/Program.cs b/samples/Sentry.Samples.AspNetCore.Blazor.Server/Program.cs index 56f7712796..1dadefa78c 100644 --- a/samples/Sentry.Samples.AspNetCore.Blazor.Server/Program.cs +++ b/samples/Sentry.Samples.AspNetCore.Blazor.Server/Program.cs @@ -6,7 +6,11 @@ builder.Services.AddServerSideBlazor(); builder.WebHost.UseSentry(options => { - options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; +#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.TracesSampleRate = 1.0; options.Debug = true; }); diff --git a/samples/Sentry.Samples.AspNetCore.Blazor.Wasm/Program.cs b/samples/Sentry.Samples.AspNetCore.Blazor.Wasm/Program.cs index a102863568..77092780bd 100644 --- a/samples/Sentry.Samples.AspNetCore.Blazor.Wasm/Program.cs +++ b/samples/Sentry.Samples.AspNetCore.Blazor.Wasm/Program.cs @@ -6,7 +6,11 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.UseSentry(options => { - options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; +#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.Debug = true; }); diff --git a/samples/Sentry.Samples.AspNetCore.Grpc/Program.cs b/samples/Sentry.Samples.AspNetCore.Grpc/Program.cs index b8b0223932..cdd26f9eb0 100644 --- a/samples/Sentry.Samples.AspNetCore.Grpc/Program.cs +++ b/samples/Sentry.Samples.AspNetCore.Grpc/Program.cs @@ -31,6 +31,13 @@ public static IWebHost BuildWebHost(string[] args) => builder.AddGrpc(); builder.AddSentryOptions(options => { +#if !SENTRY_DSN_DEFINED_IN_ENV + // A DSN is required. You can set here in code, via the SENTRY_DSN environment variable or in your + // appsettings.json file. + // See https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/#configure + options.Dsn = SamplesShared.Dsn; +#endif + // The parameter 'options' here has values populated through the configuration system. // That includes 'appsettings.json', environment variables and anything else // defined on the ConfigurationBuilder. diff --git a/samples/Sentry.Samples.AspNetCore.Grpc/appsettings.json b/samples/Sentry.Samples.AspNetCore.Grpc/appsettings.json index 9f71ea4fe0..39d46b6bf1 100644 --- a/samples/Sentry.Samples.AspNetCore.Grpc/appsettings.json +++ b/samples/Sentry.Samples.AspNetCore.Grpc/appsettings.json @@ -3,7 +3,7 @@ // All Sentry settings can also be configured via code or environment variables: "Sentry": { // The DSN can also be set via environment variable - "Dsn": "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537", + //"Dsn": "TODO: Configure your DSN here and uncomment this line", // Opt-in for payload submission "MaxRequestBodySize": "Always", // Sends Cookies, User Id when one is logged on and user IP address to sentry. It's turned off by default. diff --git a/samples/Sentry.Samples.AspNetCore.Mvc/Program.cs b/samples/Sentry.Samples.AspNetCore.Mvc/Program.cs index 968e11cbc2..f119daa5ac 100644 --- a/samples/Sentry.Samples.AspNetCore.Mvc/Program.cs +++ b/samples/Sentry.Samples.AspNetCore.Mvc/Program.cs @@ -11,6 +11,13 @@ // See: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-8.0 builder.WebHost.UseSentry(options => { +#if !SENTRY_DSN_DEFINED_IN_ENV + // A DSN is required. You can set here in code, via the SENTRY_DSN environment variable or in your + // appsettings.json file. + // See https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/#configure + options.Dsn = SamplesShared.Dsn; +#endif + // Tracks the release which sent the event and enables more features: https://docs.sentry.io/learn/releases/ // If not explicitly set here, the SDK attempts to read it from: AssemblyInformationalVersionAttribute and AssemblyVersion // TeamCity: %build.vcs.number%, VSTS: BUILD_SOURCEVERSION, Travis-CI: TRAVIS_COMMIT, AppVeyor: APPVEYOR_REPO_COMMIT, CircleCI: CIRCLE_SHA1 diff --git a/samples/Sentry.Samples.AspNetCore.Mvc/appsettings.json b/samples/Sentry.Samples.AspNetCore.Mvc/appsettings.json index 43799f65ea..ab7be6a3ac 100644 --- a/samples/Sentry.Samples.AspNetCore.Mvc/appsettings.json +++ b/samples/Sentry.Samples.AspNetCore.Mvc/appsettings.json @@ -3,7 +3,7 @@ // All Sentry settings can also be configured via code or environment variables: "Sentry": { // The DSN can also be set via environment variable - "Dsn": "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537", + //"Dsn": "TODO: Configure your DSN here and uncomment this line", // Opt-in for payload submission "MaxRequestBodySize": "Always", // Sends Cookies, User Id when one is logged on and user IP address to sentry. It's turned off by default. diff --git a/samples/Sentry.Samples.AspNetCore.Serilog/Program.cs b/samples/Sentry.Samples.AspNetCore.Serilog/Program.cs index f78d2381f6..6aa5d6b535 100644 --- a/samples/Sentry.Samples.AspNetCore.Serilog/Program.cs +++ b/samples/Sentry.Samples.AspNetCore.Serilog/Program.cs @@ -25,10 +25,14 @@ public static WebApplication BuildWebApp(string[] args) })); // Add Sentry integration - // It can be defined via configuration (including `appsettings.json`, as we do here) + // It can be defined via configuration (including `appsettings.json`) // or coded explicitly, via parameter like: // .UseSentry("dsn") or .UseSentry(o => o.Dsn = ""; o.Release = "1.0"; ...) - builder.WebHost.UseSentry(); +#if !SENTRY_DSN_DEFINED_IN_ENV + builder.WebHost.UseSentry(SamplesShared.Dsn); +#else + builder.WebHost.UseSentry(EnvironmentVariables.Dsn); +#endif // The App: var webApplication = builder.Build(); diff --git a/samples/Sentry.Samples.AspNetCore.Serilog/appsettings.json b/samples/Sentry.Samples.AspNetCore.Serilog/appsettings.json index 5622bda313..4c79a92f2b 100644 --- a/samples/Sentry.Samples.AspNetCore.Serilog/appsettings.json +++ b/samples/Sentry.Samples.AspNetCore.Serilog/appsettings.json @@ -3,7 +3,7 @@ // All Sentry settings can also be configured via code or environment variables: "Sentry": { // The DSN can also be set via environment variable - "Dsn": "https://b887218a80114d26a9b1a51c5f88e0b4@o447951.ingest.sentry.io/6601807", + //"Dsn": "TODO: Configure your DSN here and uncomment this line", // Enable Sentry tracing features "EnableTracing": true, // Opt-in for payload submission diff --git a/samples/Sentry.Samples.AspNetCore.WebAPI.Profiling/Program.cs b/samples/Sentry.Samples.AspNetCore.WebAPI.Profiling/Program.cs index 07b0147102..673b3d7f57 100644 --- a/samples/Sentry.Samples.AspNetCore.WebAPI.Profiling/Program.cs +++ b/samples/Sentry.Samples.AspNetCore.WebAPI.Profiling/Program.cs @@ -2,7 +2,11 @@ builder.WebHost.UseSentry(o => { - o.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; +#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/ + o.Dsn = SamplesShared.Dsn; +#endif o.AddProfilingIntegration(); o.ProfilesSampleRate = 0.1; o.TracesSampleRate = 1.0; diff --git a/samples/Sentry.Samples.Aws.Lambda.AspNetCoreServer/LambdaEntryPoint.cs b/samples/Sentry.Samples.Aws.Lambda.AspNetCoreServer/LambdaEntryPoint.cs index 8ccf6592b6..a2ac2301a2 100644 --- a/samples/Sentry.Samples.Aws.Lambda.AspNetCoreServer/LambdaEntryPoint.cs +++ b/samples/Sentry.Samples.Aws.Lambda.AspNetCoreServer/LambdaEntryPoint.cs @@ -4,8 +4,15 @@ public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFu protected override void Init(IWebHostBuilder builder) { builder - // Add Sentry (configuration was done via appsettings.json but could be done programatically): +#if !SENTRY_DSN_DEFINED_IN_ENV + // A DSN is required. You can set it here in code, via the SENTRY_DSN environment variable or in your + // appsettings.json file. + // See https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/#configure + .UseSentry(SamplesShared.Dsn) +#else .UseSentry() +#endif + // Add Sentry (configuration was done via appsettings.json but could be done programatically): .UseStartup(); } } diff --git a/samples/Sentry.Samples.Aws.Lambda.AspNetCoreServer/appsettings.json b/samples/Sentry.Samples.Aws.Lambda.AspNetCoreServer/appsettings.json index 3dc9e1058b..b28a5bad3d 100644 --- a/samples/Sentry.Samples.Aws.Lambda.AspNetCoreServer/appsettings.json +++ b/samples/Sentry.Samples.Aws.Lambda.AspNetCoreServer/appsettings.json @@ -9,7 +9,7 @@ }, "Sentry": { "NOTE1": "Add your own DSN below see the sample event in YOUR Sentry dashboard.", - "Dsn": "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537", + //"Dsn": "TODO: Configure your DSN here and uncomment this line", "EnableTracing": true, "NOTE2": "Many Sentry ASP.NET Core options are demonstrated in the other samples in this repository.", diff --git a/samples/Sentry.Samples.Azure.Functions.Worker/Program.cs b/samples/Sentry.Samples.Azure.Functions.Worker/Program.cs index 5398d09a6e..efc8943223 100644 --- a/samples/Sentry.Samples.Azure.Functions.Worker/Program.cs +++ b/samples/Sentry.Samples.Azure.Functions.Worker/Program.cs @@ -6,7 +6,10 @@ { builder.UseSentry(host, options => { - options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; +#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. + options.Dsn = SamplesShared.Dsn; +#endif options.TracesSampleRate = 1.0; options.Debug = true; }); diff --git a/samples/Sentry.Samples.Console.Basic/Program.cs b/samples/Sentry.Samples.Console.Basic/Program.cs index be18640323..39027fa0ee 100644 --- a/samples/Sentry.Samples.Console.Basic/Program.cs +++ b/samples/Sentry.Samples.Console.Basic/Program.cs @@ -14,9 +14,11 @@ // Initialize the Sentry SDK. (It is not necessary to dispose it.) SentrySdk.Init(options => { - // You can set here in code, or you can set it in the SENTRY_DSN environment variable. +#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 = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; + options.Dsn = SamplesShared.Dsn; +#endif // When debug is enabled, the Sentry client will emit detailed debugging information to the console. // This might be helpful, or might interfere with the normal operation of your application. diff --git a/samples/Sentry.Samples.Console.Customized/Program.cs b/samples/Sentry.Samples.Console.Customized/Program.cs index dac1d9062a..0ccfad7b04 100644 --- a/samples/Sentry.Samples.Console.Customized/Program.cs +++ b/samples/Sentry.Samples.Console.Customized/Program.cs @@ -17,9 +17,11 @@ await SentrySdk.ConfigureScopeAsync(async scope => // Enable the SDK using (SentrySdk.Init(options => { - // You can set here in code, or you can set it in the SENTRY_DSN environment variable. +#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 = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; + options.Dsn = SamplesShared.Dsn; +#endif // Send stack trace for events that were not created from an exception // e.g: CaptureMessage, log.LogDebug, log.LogInformation ... diff --git a/samples/Sentry.Samples.Console.HeapDump/Program.cs b/samples/Sentry.Samples.Console.HeapDump/Program.cs index ef5138c405..17983665fb 100644 --- a/samples/Sentry.Samples.Console.HeapDump/Program.cs +++ b/samples/Sentry.Samples.Console.HeapDump/Program.cs @@ -14,9 +14,11 @@ // Initialize the Sentry SDK. (It is not necessary to dispose it.) SentrySdk.Init(options => { - // You can set here in code, or you can set it in the SENTRY_DSN environment variable. +#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 = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; + options.Dsn = SamplesShared.Dsn; +#endif // When debug is enabled, the Sentry client will emit detailed debugging information to the console. // This might be helpful, or might interfere with the normal operation of your application. diff --git a/samples/Sentry.Samples.Console.Native/Program.cs b/samples/Sentry.Samples.Console.Native/Program.cs index 416e2e3a75..3ffa459bcd 100644 --- a/samples/Sentry.Samples.Console.Native/Program.cs +++ b/samples/Sentry.Samples.Console.Native/Program.cs @@ -5,9 +5,11 @@ // Initialize the Sentry SDK. (It is not necessary to dispose it.) SentrySdk.Init(options => { - // You can set here in code, or you can set it in the SENTRY_DSN environment variable. +#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 = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; + options.Dsn = SamplesShared.Dsn; +#endif // When debug is enabled, the Sentry client will emit detailed debugging information to the console. // This might be helpful, or might interfere with the normal operation of your application. diff --git a/samples/Sentry.Samples.Console.Profiling/Program.cs b/samples/Sentry.Samples.Console.Profiling/Program.cs index 7c0b1528f4..3c1de15f38 100644 --- a/samples/Sentry.Samples.Console.Profiling/Program.cs +++ b/samples/Sentry.Samples.Console.Profiling/Program.cs @@ -7,9 +7,11 @@ private static void Main() // Enable the SDK using (SentrySdk.Init(options => { - // You can set here in code, or you can set it in the SENTRY_DSN environment variable. +#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 = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; + options.Dsn = SamplesShared.Dsn; +#endif options.Debug = true; // options.AutoSessionTracking = true; diff --git a/samples/Sentry.Samples.EntityFramework/Program.cs b/samples/Sentry.Samples.EntityFramework/Program.cs index 5a4bd44343..6a2b8a09cc 100644 --- a/samples/Sentry.Samples.EntityFramework/Program.cs +++ b/samples/Sentry.Samples.EntityFramework/Program.cs @@ -4,9 +4,11 @@ using var _ = SentrySdk.Init(options => { - // You can set here in code, or you can set it in the SENTRY_DSN environment variable. +#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 = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; + options.Dsn = SamplesShared.Dsn; +#endif options.Debug = true; // To see SDK logs on the console options.TracesSampleRate = 1.0; diff --git a/samples/Sentry.Samples.GenericHost/Program.cs b/samples/Sentry.Samples.GenericHost/Program.cs index de97965a84..5bad8f3641 100644 --- a/samples/Sentry.Samples.GenericHost/Program.cs +++ b/samples/Sentry.Samples.GenericHost/Program.cs @@ -6,7 +6,15 @@ var builder = Host.CreateApplicationBuilder(); builder.Logging.AddConfiguration(builder.Configuration); + +#if !SENTRY_DSN_DEFINED_IN_ENV +// A DSN is required. You can set it here in code, via the SENTRY_DSN environment variable or in your +// appsettings.json file. +// See https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/#configure +builder.Logging.AddSentry(SamplesShared.Dsn); +#else builder.Logging.AddSentry(); +#endif builder.Services.AddHostedService(); diff --git a/samples/Sentry.Samples.GenericHost/appsettings.json b/samples/Sentry.Samples.GenericHost/appsettings.json index 57bd768397..256a4dc806 100644 --- a/samples/Sentry.Samples.GenericHost/appsettings.json +++ b/samples/Sentry.Samples.GenericHost/appsettings.json @@ -5,7 +5,7 @@ } }, "Sentry": { - "Dsn": "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537", + //"Dsn": "TODO: Configure your DSN here and uncomment this line", "MinimumBreadcrumbLevel": "Debug", "MinimumEventLevel": "Warning", "SendDefaultPii": true // Send user name and machine name diff --git a/samples/Sentry.Samples.Google.Cloud.Functions/Function.cs b/samples/Sentry.Samples.Google.Cloud.Functions/Function.cs index c8abddd5c4..ae8635b9f3 100644 --- a/samples/Sentry.Samples.Google.Cloud.Functions/Function.cs +++ b/samples/Sentry.Samples.Google.Cloud.Functions/Function.cs @@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; +// Note to run this sample you'll need to specify a Sentry DSN, either by configuring it in the +// appsettings.json file or by setting the SENTRY_DSN environment variable. [assembly: FunctionsStartup(typeof(SentryStartup))] public class Function : IHttpFunction diff --git a/samples/Sentry.Samples.Google.Cloud.Functions/appsettings.json b/samples/Sentry.Samples.Google.Cloud.Functions/appsettings.json index de1f1b3b6a..0f384e48c8 100644 --- a/samples/Sentry.Samples.Google.Cloud.Functions/appsettings.json +++ b/samples/Sentry.Samples.Google.Cloud.Functions/appsettings.json @@ -1,6 +1,6 @@ { "Sentry": { - "Dsn": "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537", + //"Dsn": "TODO: Configure your DSN here and uncomment this line", "MaxRequestBodySize": "Always", "SendDefaultPii": true, "EnableTracing": true diff --git a/samples/Sentry.Samples.GraphQL.Client.Http/Program.cs b/samples/Sentry.Samples.GraphQL.Client.Http/Program.cs index 659294bf97..36a085fcb2 100644 --- a/samples/Sentry.Samples.GraphQL.Client.Http/Program.cs +++ b/samples/Sentry.Samples.GraphQL.Client.Http/Program.cs @@ -11,9 +11,11 @@ SentrySdk.Init(options => { - // 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 = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; +#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.CaptureFailedRequests = true; options.SendDefaultPii = true; diff --git a/samples/Sentry.Samples.GraphQL.Server/Program.cs b/samples/Sentry.Samples.GraphQL.Server/Program.cs index 2f63a90370..ab38e073b6 100644 --- a/samples/Sentry.Samples.GraphQL.Server/Program.cs +++ b/samples/Sentry.Samples.GraphQL.Server/Program.cs @@ -41,9 +41,11 @@ public static WebApplication BuildWebApplication(string[] args) builder.WebHost.UseSentry(options => { - // You can set here in code, or you can set it in the SENTRY_DSN environment variable. +#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 = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; + options.Dsn = SamplesShared.Dsn; +#endif options.TracesSampleRate = 1.0; options.Debug = true; diff --git a/samples/Sentry.Samples.Hangfire/Program.cs b/samples/Sentry.Samples.Hangfire/Program.cs index 8fae35e0ef..f73f0fc113 100644 --- a/samples/Sentry.Samples.Hangfire/Program.cs +++ b/samples/Sentry.Samples.Hangfire/Program.cs @@ -14,6 +14,8 @@ public static void Main(string[] args) .UseSimpleAssemblyNameTypeSerializer() .UseRecommendedSerializerSettings() .UseMemoryStorage(new MemoryStorageOptions()) + // Note to run this sample you'll need to specify a Sentry DSN, either by configuring it in the + // appsettings.json file or by setting the SENTRY_DSN environment variable. .UseSentry() // <- Add Sentry to automatically send check-ins ); diff --git a/samples/Sentry.Samples.Hangfire/appsettings.json b/samples/Sentry.Samples.Hangfire/appsettings.json index ebcd904504..d5e353d5b7 100644 --- a/samples/Sentry.Samples.Hangfire/appsettings.json +++ b/samples/Sentry.Samples.Hangfire/appsettings.json @@ -3,7 +3,7 @@ // All Sentry settings can also be configured via code or environment variables: "Sentry": { // The DSN can also be set via environment variable - "Dsn": "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537", + // "Dsn": "TODO: Configure your DSN here and uncomment this line", // Opt-in for payload submission "MaxRequestBodySize": "Always", // Sends Cookies, User Id when one is logged on and user IP address to sentry. It's turned off by default. diff --git a/samples/Sentry.Samples.Ios/AppDelegate.cs b/samples/Sentry.Samples.Ios/AppDelegate.cs index 70340fdd98..ca6fe1c396 100644 --- a/samples/Sentry.Samples.Ios/AppDelegate.cs +++ b/samples/Sentry.Samples.Ios/AppDelegate.cs @@ -16,7 +16,16 @@ public override bool FinishedLaunching(UIApplication application, NSDictionary l // Init the Sentry SDK SentrySdk.Init(options => { - options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; +#if !SENTRY_DSN_DEFINED_IN_ENV + // You must specify a DSN. On mobile platforms, this should be done in code here. + // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/ + options.Dsn = SamplesShared.Dsn; +#else + // To make things easier for the SDK maintainers our samples check for a SENTRY_DSN environment variable + // and write this (as a constant) into an EnvironmentVariables class. Generally, you won't want to do + // this in your own mobile projects though - you should set the DSN in code as above + options.Dsn = EnvironmentVariables.Dsn; +#endif options.Debug = true; options.SampleRate = 1.0F; options.TracesSampleRate = 1.0; diff --git a/samples/Sentry.Samples.Log4Net/app.config b/samples/Sentry.Samples.Log4Net/app.config index 70bc16f3c4..613a0bed0e 100644 --- a/samples/Sentry.Samples.Log4Net/app.config +++ b/samples/Sentry.Samples.Log4Net/app.config @@ -14,7 +14,7 @@ - + diff --git a/samples/Sentry.Samples.ME.Logging/Program.cs b/samples/Sentry.Samples.ME.Logging/Program.cs index e782f184bc..809db165b4 100644 --- a/samples/Sentry.Samples.ME.Logging/Program.cs +++ b/samples/Sentry.Samples.ME.Logging/Program.cs @@ -6,7 +6,11 @@ builder.AddConsole(); builder.AddSentry(options => { - options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; +#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 // Set to true to SDK debugging to see the internal messages through the logging library. options.Debug = false; diff --git a/samples/Sentry.Samples.MacCatalyst/AppDelegate.cs b/samples/Sentry.Samples.MacCatalyst/AppDelegate.cs index cb34e563df..044ae0c169 100644 --- a/samples/Sentry.Samples.MacCatalyst/AppDelegate.cs +++ b/samples/Sentry.Samples.MacCatalyst/AppDelegate.cs @@ -1,3 +1,5 @@ +using System.Diagnostics; + namespace Sentry.Samples.MacCatalyst; [Register("AppDelegate")] @@ -14,7 +16,16 @@ public override bool FinishedLaunching(UIApplication application, NSDictionary l // Init the Sentry SDK SentrySdk.Init(options => { - options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; +#if !SENTRY_DSN_DEFINED_IN_ENV + // You must specify a DSN. On mobile platforms, this should be done in code here. + // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/ + options.Dsn = SamplesShared.Dsn; +#else + // To make things easier for the SDK maintainers our samples check for a SENTRY_DSN environment variable + // and write this (as a constant) into an EnvironmentVariables class. Generally, you won't want to do + // this in your own mobile projects though - you should set the DSN in code as above + options.Dsn = EnvironmentVariables.Dsn; +#endif options.Debug = true; }); diff --git a/samples/Sentry.Samples.MacOS/AppDelegate.cs b/samples/Sentry.Samples.MacOS/AppDelegate.cs index 0477dd9eeb..8aba349817 100644 --- a/samples/Sentry.Samples.MacOS/AppDelegate.cs +++ b/samples/Sentry.Samples.MacOS/AppDelegate.cs @@ -8,7 +8,11 @@ public override void DidFinishLaunching(NSNotification notification) // Init the Sentry SDK SentrySdk.Init(options => { - options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; +#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.Debug = true; options.TracesSampleRate = 1.0; }); diff --git a/samples/Sentry.Samples.Maui/MauiProgram.cs b/samples/Sentry.Samples.Maui/MauiProgram.cs index 925cf0dc70..625632ecc2 100644 --- a/samples/Sentry.Samples.Maui/MauiProgram.cs +++ b/samples/Sentry.Samples.Maui/MauiProgram.cs @@ -13,9 +13,18 @@ public static MauiApp CreateMauiApp() // This adds Sentry to your Maui application .UseSentry(options => { - // The DSN is the only required option. - options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; - +#if !SENTRY_DSN_DEFINED_IN_ENV + // You must specify a DSN. On mobile platforms, this should be done in code here. + // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/ + options.Dsn = SamplesShared.Dsn; +#else + // To make things easier for the SDK maintainers we have a custom build target that writes the + // SENTRY_DSN environment variable into an EnvironmentVariables class that is available for mobile + // targets. This allows us to share one DSN defined in the ENV across desktop and mobile samples. + // Generally, you won't want to do this in your own mobile projects though - you should set the DSN + // in code as above + options.Dsn = EnvironmentVariables.Dsn; +#endif // By default, we will send the last 100 breadcrumbs with each event. // If you want to see everything we can capture from MAUI, you may wish to use a larger value. options.MaxBreadcrumbs = 1000; diff --git a/samples/Sentry.Samples.NLog/NLog.config b/samples/Sentry.Samples.NLog/NLog.config index 736a16aba4..5022aa23bb 100644 --- a/samples/Sentry.Samples.NLog/NLog.config +++ b/samples/Sentry.Samples.NLog/NLog.config @@ -10,11 +10,10 @@ - { - // If DSN is not set, the SDK will look for an environment variable called SENTRY_DSN. If - // nothing is found, SDK is disabled. - options.Dsn = DsnSample; - +#if !SENTRY_DSN_DEFINED_IN_ENV + // A DSN is required. You can set here in code, in the SENTRY_DSN environment variable or in the + // NLog.config file. + // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/ + options.Dsn = SamplesShared.Dsn; +#endif options.Layout = "${message}"; options.BreadcrumbLayout = "${logger}: ${message}"; // Optionally specify a separate format for breadcrumbs diff --git a/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs b/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs index 3cb706852c..e53d2b20b2 100644 --- a/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs +++ b/samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.cs @@ -26,9 +26,11 @@ builder.WebHost.UseSentry(options => { - // You can set here in code, or you can set it in the SENTRY_DSN environment variable, or the config. - // // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/ - options.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; +#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.Debug = builder.Environment.IsDevelopment(); options.SendDefaultPii = true; diff --git a/samples/Sentry.Samples.OpenTelemetry.Console/Program.cs b/samples/Sentry.Samples.OpenTelemetry.Console/Program.cs index 7ed49ee2bd..0ce193ad13 100644 --- a/samples/Sentry.Samples.OpenTelemetry.Console/Program.cs +++ b/samples/Sentry.Samples.OpenTelemetry.Console/Program.cs @@ -14,9 +14,11 @@ SentrySdk.Init(options => { - // You can set here in code, or you can set it in the SENTRY_DSN environment variable. +#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 = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; + options.Dsn = SamplesShared.Dsn; +#endif options.Debug = true; options.TracesSampleRate = 1.0; diff --git a/samples/Sentry.Samples.Serilog/Program.cs b/samples/Sentry.Samples.Serilog/Program.cs index 83818af586..59ed09548d 100644 --- a/samples/Sentry.Samples.Serilog/Program.cs +++ b/samples/Sentry.Samples.Serilog/Program.cs @@ -14,9 +14,11 @@ private static void Main() // Other overloads exist, for example, configure the SDK with only the DSN or no parameters at all. .WriteTo.Sentry(options => { - // You can set here in code, or you can set it in the SENTRY_DSN environment variable. +#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 = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537"; + options.Dsn = SamplesShared.Dsn; +#endif // Debug and higher are stored as breadcrumbs (default os Information) options.MinimumBreadcrumbLevel = LogEventLevel.Debug; diff --git a/src/Sentry/Internal/SettingLocator.cs b/src/Sentry/Internal/SettingLocator.cs index 2dc494e53c..4555ac7333 100644 --- a/src/Sentry/Internal/SettingLocator.cs +++ b/src/Sentry/Internal/SettingLocator.cs @@ -1,3 +1,4 @@ +using Sentry.Extensibility; using Sentry.Internal.Extensions; namespace Sentry.Internal; @@ -36,11 +37,23 @@ public string GetDsn() if (!string.IsNullOrEmpty(_options.Dsn)) { + _options.LogDebug("DSN read from options: {0}", _options.Dsn); return _options.Dsn; } - var dsn = GetEnvironmentVariable(Constants.DsnEnvironmentVariable) - ?? AssemblyForAttributes?.GetCustomAttribute()?.Dsn; + var dsn = GetEnvironmentVariable(Constants.DsnEnvironmentVariable); + if (dsn is not null) + { + _options.LogDebug("DSN read from environment variable: {0}", dsn); + } + + dsn ??= AssemblyForAttributes?.GetCustomAttribute()?.Dsn; + if (dsn is not null) + { + _options.LogDebug("DSN read from assembly attribute: {0}", dsn); + } + + _options.LogDebug("AssemblyForAttributes is {0}", AssemblyForAttributes?.FullName); // If there has been no DSN provided (`null`) and none has been found in the environment we consider this a // failed configuration and throw diff --git a/test/Sentry.AspNetCore.Tests/AspNetCoreSentryWebHostBuilder.IntegrationTests.cs b/test/Sentry.AspNetCore.Tests/AspNetCoreSentryWebHostBuilder.IntegrationTests.cs index 06fe8cf76b..455bf8c0a2 100644 --- a/test/Sentry.AspNetCore.Tests/AspNetCoreSentryWebHostBuilder.IntegrationTests.cs +++ b/test/Sentry.AspNetCore.Tests/AspNetCoreSentryWebHostBuilder.IntegrationTests.cs @@ -26,15 +26,21 @@ public void UseSentry_ValidDsnString_EnablesSdk() } } - [Fact] + [SkippableFact] public void UseSentry_NoDsnProvided_ThrowsException() { +#if SENTRY_DSN_DEFINED_IN_ENV + Skip.If(true, "This test only works when the DSN is not configured as an environment variable."); +#endif Assert.Throws(() => _webHostBuilder.UseSentry().Build()); } - [Fact] + [SkippableFact] public void UseSentry_DisableDsnString_DisabledSdk() { +#if SENTRY_DSN_DEFINED_IN_ENV + Skip.If(true, "This test only works when the DSN is not configured as an environment variable."); +#endif _ = _webHostBuilder.UseSentry(Sentry.SentryConstants.DisableSdkDsnValue) .Build(); diff --git a/test/Sentry.NLog.Tests/SentryTargetTests.cs b/test/Sentry.NLog.Tests/SentryTargetTests.cs index 6b87025326..f0ef530a68 100644 --- a/test/Sentry.NLog.Tests/SentryTargetTests.cs +++ b/test/Sentry.NLog.Tests/SentryTargetTests.cs @@ -476,9 +476,12 @@ void Continuation(Exception _) await hub.Received().FlushAsync(Arg.Any()); } - [Fact] + [SkippableFact] public void InitializeTarget_InitializesSdk() { +#if SENTRY_DSN_DEFINED_IN_ENV + Skip.If(true, "This test only works when the DSN is not configured as an environment variable."); +#endif _fixture.Options.Dsn = Sentry.SentryConstants.DisableSdkDsnValue; _fixture.SdkDisposeHandle = null; _fixture.Options.InitializeSdk = true; diff --git a/test/Sentry.Tests/Internals/SettingLocatorTests.cs b/test/Sentry.Tests/Internals/SettingLocatorTests.cs index 7fb1270fc4..9491a410a9 100644 --- a/test/Sentry.Tests/Internals/SettingLocatorTests.cs +++ b/test/Sentry.Tests/Internals/SettingLocatorTests.cs @@ -82,9 +82,12 @@ public void CanUseOtherAssembly() Assert.Same(expected, actual); } - [Fact] + [SkippableFact] public void GetDsn_WithEmptyString_DoesNotThrow() { +#if SENTRY_DSN_DEFINED_IN_ENV + Skip.If(true, "This test only works when the DSN is not configured as an environment variable."); +#endif var options = new SentryOptions { Dsn = DisableSdkDsnValue }; var dsn = options.SettingLocator.GetDsn(); @@ -163,9 +166,12 @@ public void GetDsn_DsnIsNonEmptyString_IgnoresAttribute() Assert.Equal(validDsn1, options.Dsn); } - [Fact] + [SkippableFact] public void GetDsn_WithNoValueAnywhere_ThrowsException() { +#if SENTRY_DSN_DEFINED_IN_ENV + Skip.If(true, "This test only works when the DSN is not configured as an environment variable."); +#endif var options = new SentryOptions(); Assert.Throws(() => options.SettingLocator.GetDsn()); diff --git a/test/Sentry.Tests/SentryGraphQlHttpFailedRequestHandlerTests.cs b/test/Sentry.Tests/SentryGraphQlHttpFailedRequestHandlerTests.cs index 65af1ae103..0b361d2e29 100644 --- a/test/Sentry.Tests/SentryGraphQlHttpFailedRequestHandlerTests.cs +++ b/test/Sentry.Tests/SentryGraphQlHttpFailedRequestHandlerTests.cs @@ -44,7 +44,7 @@ public void HandleResponse_RequestsToSentryDsn_DontCapture() var options = new SentryOptions { CaptureFailedRequests = true, - Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537" + Dsn = ValidDsn }; var sut = new SentryGraphQLHttpFailedRequestHandler(hub, options); diff --git a/test/Sentry.Tests/SentryHttpFailedRequestHandlerTests.cs b/test/Sentry.Tests/SentryHttpFailedRequestHandlerTests.cs index 4e81fac3c6..17a5e600f1 100644 --- a/test/Sentry.Tests/SentryHttpFailedRequestHandlerTests.cs +++ b/test/Sentry.Tests/SentryHttpFailedRequestHandlerTests.cs @@ -65,7 +65,7 @@ public void HandleResponse_RequestsToSentryDsn_DontCapture() var options = new SentryOptions { CaptureFailedRequests = true, - Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537" + Dsn = ValidDsn }; var sut = GetSut(options); diff --git a/test/Sentry.Tests/SentrySdkTests.cs b/test/Sentry.Tests/SentrySdkTests.cs index ca2723df61..49ca287d59 100644 --- a/test/Sentry.Tests/SentrySdkTests.cs +++ b/test/Sentry.Tests/SentrySdkTests.cs @@ -132,9 +132,12 @@ public void Init_EmptyDsn_DisabledSdk() } } - [Fact] + [SkippableFact] public void Init_EmptyDsn_LogsWarning() { +#if SENTRY_DSN_DEFINED_IN_ENV + Skip.If(true, "This test only works when the DSN is not configured as an environment variable."); +#endif var options = new SentryOptions { Dsn = SentryConstants.DisableSdkDsnValue, From 68cd68798d5e92102e120eb74dcb5487eefcbcec Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Mon, 9 Jun 2025 08:55:48 +0000 Subject: [PATCH 2/4] Format code --- samples/SamplesShared.cs | 2 +- samples/Sentry.Samples.Ios/AppDelegate.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/SamplesShared.cs b/samples/SamplesShared.cs index 7a640a410d..14afcb5f14 100644 --- a/samples/SamplesShared.cs +++ b/samples/SamplesShared.cs @@ -16,7 +16,7 @@ public static class SamplesShared /// /// #if !CI_BUILD - #error Sign up for a free Sentry Account and enter your DSN here +#error Sign up for a free Sentry Account and enter your DSN here #endif public const string Dsn = "ENTER_YOUR_DSN_HERE"; #endif diff --git a/samples/Sentry.Samples.Ios/AppDelegate.cs b/samples/Sentry.Samples.Ios/AppDelegate.cs index ca6fe1c396..37e2a48509 100644 --- a/samples/Sentry.Samples.Ios/AppDelegate.cs +++ b/samples/Sentry.Samples.Ios/AppDelegate.cs @@ -17,9 +17,9 @@ public override bool FinishedLaunching(UIApplication application, NSDictionary l SentrySdk.Init(options => { #if !SENTRY_DSN_DEFINED_IN_ENV - // You must specify a DSN. On mobile platforms, this should be done in code here. - // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/ - options.Dsn = SamplesShared.Dsn; + // You must specify a DSN. On mobile platforms, this should be done in code here. + // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/ + options.Dsn = SamplesShared.Dsn; #else // To make things easier for the SDK maintainers our samples check for a SENTRY_DSN environment variable // and write this (as a constant) into an EnvironmentVariables class. Generally, you won't want to do From 9d1ecfdc92454c1d25f58347bd95940a653a2c14 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Tue, 10 Jun 2025 09:52:54 +1200 Subject: [PATCH 3/4] Update samples/Sentry.Samples.Google.Cloud.Functions/Function.cs Co-authored-by: Bruno Garcia --- samples/Sentry.Samples.Google.Cloud.Functions/Function.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Sentry.Samples.Google.Cloud.Functions/Function.cs b/samples/Sentry.Samples.Google.Cloud.Functions/Function.cs index ae8635b9f3..db9dfc30c2 100644 --- a/samples/Sentry.Samples.Google.Cloud.Functions/Function.cs +++ b/samples/Sentry.Samples.Google.Cloud.Functions/Function.cs @@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -// Note to run this sample you'll need to specify a Sentry DSN, either by configuring it in the +// NOTE: to run this sample you'll need to specify a Sentry DSN, either by configuring it in the // appsettings.json file or by setting the SENTRY_DSN environment variable. [assembly: FunctionsStartup(typeof(SentryStartup))] From 3e65c0853a85a75c6c5af59543a4805869b57e77 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Tue, 10 Jun 2025 09:56:05 +1200 Subject: [PATCH 4/4] Big notes --- samples/Sentry.Samples.Google.Cloud.Functions/Function.cs | 2 ++ samples/Sentry.Samples.Hangfire/Program.cs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/samples/Sentry.Samples.Google.Cloud.Functions/Function.cs b/samples/Sentry.Samples.Google.Cloud.Functions/Function.cs index db9dfc30c2..7c151d6ee8 100644 --- a/samples/Sentry.Samples.Google.Cloud.Functions/Function.cs +++ b/samples/Sentry.Samples.Google.Cloud.Functions/Function.cs @@ -3,8 +3,10 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; +// ********************************************************************************************* // NOTE: to run this sample you'll need to specify a Sentry DSN, either by configuring it in the // appsettings.json file or by setting the SENTRY_DSN environment variable. +// ********************************************************************************************* [assembly: FunctionsStartup(typeof(SentryStartup))] public class Function : IHttpFunction diff --git a/samples/Sentry.Samples.Hangfire/Program.cs b/samples/Sentry.Samples.Hangfire/Program.cs index f73f0fc113..de5ebb2ca6 100644 --- a/samples/Sentry.Samples.Hangfire/Program.cs +++ b/samples/Sentry.Samples.Hangfire/Program.cs @@ -14,8 +14,10 @@ public static void Main(string[] args) .UseSimpleAssemblyNameTypeSerializer() .UseRecommendedSerializerSettings() .UseMemoryStorage(new MemoryStorageOptions()) - // Note to run this sample you'll need to specify a Sentry DSN, either by configuring it in the + // ********************************************************************************************* + // NOTE: to run this sample you'll need to specify a Sentry DSN, either by configuring it in the // appsettings.json file or by setting the SENTRY_DSN environment variable. + // ********************************************************************************************* .UseSentry() // <- Add Sentry to automatically send check-ins );