@@ -71,29 +71,36 @@ public class Program
7171
7272 public static void Main ( string [ ] args )
7373 {
74- SentrySdk . Init ( options =>
75- {
76- // A Sentry Data Source Name (DSN) is required.
77- // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
78- // You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
79- options . Dsn = "https://a20910d51f605d94e956163ffbf9dd5a@o4506241219428352.ingest.sentry.io/4506279162019840" ;
80-
81- // When debug is enabled, the Sentry client will emit detailed debugging information to the console.
82- // This might be helpful, or might interfere with the normal operation of your application.
83- // We enable it here for demonstration purposes when first trying Sentry.
84- // You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
85- options . Debug = false ;
86-
87- // This option is recommended. It enables Sentry's "Release Health" feature.
88- options . AutoSessionTracking = true ;
74+ var disableSentry = Environment . GetEnvironmentVariable ( "DISABLE_SENTRY" ) ;
75+ var sentryDisabled = ! string . IsNullOrEmpty ( disableSentry ) &&
76+ ( disableSentry . ToLower ( ) == "true" || disableSentry == "1" ) ;
8977
90- // This option is recommended for client applications only. It ensures all threads use the same global scope.
91- // If you're writing a background service of any kind, you should remove this.
92- options . IsGlobalModeEnabled = false ;
93-
94- // This option will enable Sentry's tracing features. You still need to start transactions and spans.
95- //options.EnableTracing = true;
96- } ) ;
78+ if ( ! sentryDisabled )
79+ {
80+ SentrySdk . Init ( options =>
81+ {
82+ // A Sentry Data Source Name (DSN) is required.
83+ // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
84+ // You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
85+ options . Dsn = "https://a20910d51f605d94e956163ffbf9dd5a@o4506241219428352.ingest.sentry.io/4506279162019840" ;
86+
87+ // When debug is enabled, the Sentry client will emit detailed debugging information to the console.
88+ // This might be helpful, or might interfere with the normal operation of your application.
89+ // We enable it here for demonstration purposes when first trying Sentry.
90+ // You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
91+ options . Debug = false ;
92+
93+ // This option is recommended. It enables Sentry's "Release Health" feature.
94+ options . AutoSessionTracking = true ;
95+
96+ // This option is recommended for client applications only. It ensures all threads use the same global scope.
97+ // If you're writing a background service of any kind, you should remove this.
98+ options . IsGlobalModeEnabled = false ;
99+
100+ // This option will enable Sentry's tracing features. You still need to start transactions and spans.
101+ //options.EnableTracing = true;
102+ } ) ;
103+ }
97104
98105 var host = BuildWebHost ( args ) ;
99106 InitializeSettings ( host , args ) . Wait ( ) ;
@@ -518,17 +525,23 @@ private static IWebHost BuildWebHost(string[] args)
518525 {
519526 string numberString = match . Groups [ 1 ] . Value ;
520527 int number = int . Parse ( numberString ) ;
521- SentrySdk . ConfigureScope ( scope =>
528+ var disableSentry = Environment . GetEnvironmentVariable ( "DISABLE_SENTRY" ) ;
529+ var sentryDisabled = ! string . IsNullOrEmpty ( disableSentry ) &&
530+ ( disableSentry . ToLower ( ) == "true" || disableSentry == "1" ) ;
531+ if ( ! sentryDisabled )
522532 {
523- scope . SetTag ( "customerNo" , number . ToString ( ) ) ;
524- Console . WriteLine ( "customerNo: " + number ) ;
525- scope . SetTag ( "osVersion" , Environment . OSVersion . ToString ( ) ) ;
526- Console . WriteLine ( "osVersion: " + Environment . OSVersion ) ;
527- scope . SetTag ( "osArchitecture" , RuntimeInformation . OSArchitecture . ToString ( ) ) ;
528- Console . WriteLine ( "osArchitecture: " + RuntimeInformation . OSArchitecture ) ;
529- scope . SetTag ( "osName" , RuntimeInformation . OSDescription ) ;
530- Console . WriteLine ( "osName: " + RuntimeInformation . OSDescription ) ;
531- } ) ;
533+ SentrySdk . ConfigureScope ( scope =>
534+ {
535+ scope . SetTag ( "customerNo" , number . ToString ( ) ) ;
536+ Console . WriteLine ( "customerNo: " + number ) ;
537+ scope . SetTag ( "osVersion" , Environment . OSVersion . ToString ( ) ) ;
538+ Console . WriteLine ( "osVersion: " + Environment . OSVersion ) ;
539+ scope . SetTag ( "osArchitecture" , RuntimeInformation . OSArchitecture . ToString ( ) ) ;
540+ Console . WriteLine ( "osArchitecture: " + RuntimeInformation . OSArchitecture ) ;
541+ scope . SetTag ( "osName" , RuntimeInformation . OSDescription ) ;
542+ Console . WriteLine ( "osName: " + RuntimeInformation . OSDescription ) ;
543+ } ) ;
544+ }
532545 }
533546
534547 using var dbContext = contextFactory . CreateDbContext ( [ _defaultConnectionString ] ) ;
0 commit comments