public void ConfigureScope_Sync_CallbackNeverInvoked() { var invoked = false; SentryCore.ConfigureScope(_ => invoked = true); Assert.False(invoked); }
public void PushScope_NullArgument_NoOp() { var scopeGuard = SentryCore.PushScope(null as object); Assert.False(SentryCore.IsEnabled); scopeGuard.Dispose(); }
public void PushScope_Parameterless_NoOp() { var scopeGuard = SentryCore.PushScope(); Assert.False(SentryCore.IsEnabled); scopeGuard.Dispose(); }
public void Init_DsnInstance_EnablesSdk() { var dsn = new Dsn(DsnSamples.ValidDsnWithoutSecret); SentryCore.Init(dsn); Assert.True(SentryCore.IsEnabled); }
/// <summary> /// Adds Sentry's services to the <see cref="IServiceCollection"/> /// </summary> /// <param name="services">The services.</param> /// <param name="configureOptions">The configure options.</param> /// <returns></returns> public static IServiceCollection AddSentry( this IServiceCollection services, Action <SentryOptions> configureOptions) { services .AddSingleton <IRequestPayloadExtractor, FormRequestPayloadExtractor>() // Last .AddSingleton <IRequestPayloadExtractor, DefaultRequestPayloadExtractor>() .TryAddSingleton(p => { if (configureOptions != null && !SentryCore.IsEnabled) { var aspnetOptions = p.GetService <SentryAspNetCoreOptions>(); var options = p.GetService <SentryOptions>(); options = options ?? new SentryOptions(); aspnetOptions.InitSdk?.Invoke(options); configureOptions?.Invoke(options); var lifetime = p.GetRequiredService <IApplicationLifetime>(); var disposable = SentryCore.Init(options); lifetime.ApplicationStopped.Register(() => disposable.Dispose()); } // TODO: SDK interface not accepting 'Integrations' // SentryCore.ConfigureScope(s => s.Sdk.AddIntegration(Constants.IntegrationName)); // TODO: Need to fetch the created client and hub now to register in DI return(HubAdapter.Instance as IHub); }); return(services); }
static void Main() { SentryCore.Init("https://[email protected]/id"); // The following exception is captured and sent to Sentry throw null; }
public void AddBreadcrumb( string message, string type, string category = null, IDictionary <string, string> data = null, BreadcrumbLevel level = default) => SentryCore.AddBreadcrumb(message, type, category, data, level);
public void Init_MultipleCalls_ReplacesHubWithLatest() { var first = SentryCore.Init(ValidDsnWithSecret); SentryCore.AddBreadcrumb("test", "type"); var called = false; SentryCore.ConfigureScope(p => { called = true; Assert.Single(p.Breadcrumbs); }); Assert.True(called); called = false; var second = SentryCore.Init(ValidDsnWithSecret); SentryCore.ConfigureScope(p => { called = true; Assert.Empty(p.Breadcrumbs); }); Assert.True(called); first.Dispose(); second.Dispose(); }
public void Disposable_MultipleCalls_NoOp() { var disposable = SentryCore.Init(); disposable.Dispose(); disposable.Dispose(); Assert.False(SentryCore.IsEnabled); }
public async Task ConfigureScope_Async_CallbackNeverInvoked() { var invoked = false; await SentryCore.ConfigureScopeAsync(_ => { invoked = true; return(Task.CompletedTask); }); Assert.False(invoked); }
public void Init_DisableDsnEnvironmentVariable_DisablesSdk() { EnvironmentVariableGuard.WithVariable( DsnEnvironmentVariable, DisableSdkDsnValue, () => { using (SentryCore.Init()) Assert.False(SentryCore.IsEnabled); }); }
public void Init_ValidDsnEnvironmentVariable_EnablesSdk() { EnvironmentVariableGuard.WithVariable( DsnEnvironmentVariable, ValidDsnWithSecret, () => { using (SentryCore.Init()) Assert.True(SentryCore.IsEnabled); }); }
public void CaptureEvent_Func_NoOp() { var invoked = false; SentryCore.CaptureEvent(() => { invoked = true; return(null); }); Assert.False(invoked); }
public void Init_ValidDsnEnvironmentVariable_EnablesSdk() { EnvironmentVariableGuard.WithVariable( Sentry.Internals.Constants.DsnEnvironmentVariable, DsnSamples.ValidDsnWithSecret, () => { SentryCore.Init(); Assert.True(SentryCore.IsEnabled); }); }
public void Init_DisableDsnEnvironmentVariable_DisablesSdk() { EnvironmentVariableGuard.WithVariable( Sentry.Internals.Constants.DsnEnvironmentVariable, Sentry.Internals.Constants.DisableSdkDsnValue, () => { SentryCore.Init(); Assert.False(SentryCore.IsEnabled); }); }
public void EnabledClient_AddBreadcrumb() { for (int i = 0; i < BreadcrumbsCount; i++) { SentryCore.AddBreadcrumb( Message, Type, Category, Data, Level); } }
public void Init_InvalidDsnEnvironmentVariable_Throws() { EnvironmentVariableGuard.WithVariable( Sentry.Internals.Constants.DsnEnvironmentVariable, // If the variable was set, to non empty string but value is broken, better crash than silently disable DsnSamples.InvalidDsn, () => { var ex = Assert.Throws <ArgumentException>(() => SentryCore.Init()); Assert.Equal("Invalid DSN: A Project Id is required.", ex.Message); }); }
static void Main() { SentryCore.Init("https://[email protected]/id"); // Initialize SDK try { App(); } finally { SentryCore.CloseAndFlush(); } }
public void AddBreadcrumb( ISystemClock clock, string message, string type = null, string category = null, IDictionary <string, string> data = null, BreadcrumbLevel level = default) => SentryCore.AddBreadcrumb( clock: clock, message: message, type: type, data: data, category: category, level: level);
public void EnabledSdk_PushScope_AddBreadcrumb_PopScope() { using (SentryCore.PushScope()) { for (int i = 0; i < BreadcrumbsCount; i++) { SentryCore.AddBreadcrumb( Message, Type, Category, Data, Level); } } }
public void Dispose_DisposingFirst_DoesntAffectSecond() { var first = SentryCore.Init(ValidDsnWithSecret); var second = SentryCore.Init(ValidDsnWithSecret); SentryCore.AddBreadcrumb("test", "type"); first.Dispose(); var called = false; SentryCore.ConfigureScope(p => { called = true; Assert.Single(p.Breadcrumbs); }); Assert.True(called); second.Dispose(); }
public void Invoke(dynamic request) { using (SentryCore.PushScope()) { SentryCore.AddBreadcrumb(request.Path, "request-path"); // Change the SentryClient in case the request is to the admin part: if (request.Path.StartsWith("/admin")) { // Within this scope, the _adminClient will be used instead of whatever // client was defined before this point: SentryCore.BindClient(_adminClient); } SentryCore.CaptureException(new Exception("Error at the admin section")); // Else it uses the default client _middleware?.Invoke(request); } // Scope is disposed. }
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(); }
internal SentryLoggerProvider( ISentryScopeManager scopeManager, SentryLoggingOptions options) { Debug.Assert(options != null); Debug.Assert(scopeManager != null); _options = options; // SDK is being initialized through this integration // Lifetime is owned by this instance: if (_options.InitializeSdk) { _sdk = SentryCore.Init(_options.InitSdk); } // Creates a scope so that Integration added below can be dropped when the logger is disposed _scope = scopeManager.PushScope(); // TODO: SDK interface not accepting 'Integrations' // scopeManager.ConfigureScope(s => s.Sdk.AddIntegration(Constants.IntegrationName)); }
public void EnabledSdk() => _sdk = SentryCore.Init(Constants.ValidDsn);
public Guid CaptureEvent(SentryEvent evt, Scope scope) => SentryCore.CaptureEvent(evt, scope);
public Guid CaptureException(Exception exception) => SentryCore.CaptureException(exception);
public Guid CaptureEvent(SentryEvent evt) => SentryCore.CaptureEvent(evt);
public void BindClient(ISentryClient client) => SentryCore.BindClient(client);
public IDisposable PushScope <TState>(TState state) => SentryCore.PushScope(state);