public async Task ConfigureScope_Async_CallbackNeverInvoked() { var invoked = false; await SentryCore.ConfigureScopeAsync(_ => { invoked = true; return(Task.CompletedTask); }); Assert.False(invoked); }
private static async Task Main(string[] args) { // With the SDK disabled so the callback is never invoked await SentryCore.ConfigureScopeAsync(async scope => { // This could be any async I/O operation, like a DB query await Task.Yield(); scope.SetExtra("Key", "Value"); }); // Enable the SDK SentryCore.Init(o => { // Modifications to event before it goes out. Could replace the event altogether o.BeforeSend = @event => { // Drop an event altogether: if (@event.Tags.ContainsKey("SomeTag")) { return(null); } // Create a totally new event or modify the current one: @event.ServerName = null; // Make sure no ServerName is sent out return(@event); }; }); await SentryCore.ConfigureScopeAsync(async scope => { // This could be any async I/O operation, like a DB query await Task.Yield(); scope.SetExtra("Key", "Value"); }); SentryCore.CaptureException(new Exception("Something went wrong.")); SentryCore.CloseAndFlush(); }
public Task ConfigureScopeAsync(Func <Scope, Task> configureScope) => SentryCore.ConfigureScopeAsync(configureScope);
private static async Task Main(string[] args) { // When the SDK is disabled, no callback is executed: await SentryCore.ConfigureScopeAsync(async scope => { // Never executed: // This could be any async I/O operation, like a DB query await Task.Yield(); scope.SetExtra("Key", "Value"); }); // Enable the SDK using (SentryCore.Init(o => { // Modifications to event before it goes out. Could replace the event altogether o.BeforeSend = @event => { // Drop an event altogether: if (@event.Tags.ContainsKey("SomeTag")) { return(null); } // Create a totally new event or modify the current one: @event.ServerName = null; // Make sure no ServerName is sent out return(@event); }; // Configure the background worker which sends events to sentry: o.Worker(w => { // Poll for events every 100ms w.EmptyQueueDelay = TimeSpan.FromMilliseconds(100); // Wait up to 5 seconds before shutdown while there are events to send. w.ShutdownTimeout = TimeSpan.FromSeconds(5); }); o.Http(h => { // Using a proxy: h.Proxy = null; //new WebProxy("https://localhost:3128"); }); })) { await SentryCore.ConfigureScopeAsync(async scope => { // This could be any async I/O operation, like a DB query await Task.Yield(); scope.SetExtra("Key", "Value"); }); SentryCore.CaptureException(new Exception("Something went wrong.")); // ------------------------- // A custom made client, that could be registered with DI, // would get disposed by the container on app shutdown // Using a different DSN: var adminDsn = new Dsn(AdminDsn); using (var adminClient = new SentryClient(new SentryOptions { Dsn = adminDsn })) { // Make believe web framework middleware var middleware = new AdminPartMiddleware(adminClient, null); var request = new { Path = "/admin" }; // made up request middleware.Invoke(request); } // Dispose the client which flushes any queued events SentryCore.CaptureException( new Exception("Error outside of the admin section: Goes to the default DSN")); } // On Dispose: SDK closed, events queued are flushed/sent to Sentry }