Exemplo n.º 1
0
        public void ConfigureScope_Sync_CallbackNeverInvoked()
        {
            var invoked = false;

            SentryCore.ConfigureScope(_ => invoked = true);
            Assert.False(invoked);
        }
Exemplo n.º 2
0
        public void PushScope_NullArgument_NoOp()
        {
            var scopeGuard = SentryCore.PushScope(null as object);

            Assert.False(SentryCore.IsEnabled);
            scopeGuard.Dispose();
        }
Exemplo n.º 3
0
        public void PushScope_Parameterless_NoOp()
        {
            var scopeGuard = SentryCore.PushScope();

            Assert.False(SentryCore.IsEnabled);
            scopeGuard.Dispose();
        }
Exemplo n.º 4
0
        public void Init_DsnInstance_EnablesSdk()
        {
            var dsn = new Dsn(DsnSamples.ValidDsnWithoutSecret);

            SentryCore.Init(dsn);
            Assert.True(SentryCore.IsEnabled);
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
    static void Main()
    {
        SentryCore.Init("https://[email protected]/id");

        // The following exception is captured and sent to Sentry
        throw null;
    }
Exemplo n.º 7
0
 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);
Exemplo n.º 8
0
        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();
        }
Exemplo n.º 9
0
        public void Disposable_MultipleCalls_NoOp()
        {
            var disposable = SentryCore.Init();

            disposable.Dispose();
            disposable.Dispose();
            Assert.False(SentryCore.IsEnabled);
        }
Exemplo n.º 10
0
        public async Task ConfigureScope_Async_CallbackNeverInvoked()
        {
            var invoked = false;
            await SentryCore.ConfigureScopeAsync(_ =>
            {
                invoked = true;
                return(Task.CompletedTask);
            });

            Assert.False(invoked);
        }
Exemplo n.º 11
0
 public void Init_DisableDsnEnvironmentVariable_DisablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         DisableSdkDsnValue,
         () =>
     {
         using (SentryCore.Init())
             Assert.False(SentryCore.IsEnabled);
     });
 }
Exemplo n.º 12
0
 public void Init_ValidDsnEnvironmentVariable_EnablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         ValidDsnWithSecret,
         () =>
     {
         using (SentryCore.Init())
             Assert.True(SentryCore.IsEnabled);
     });
 }
Exemplo n.º 13
0
        public void CaptureEvent_Func_NoOp()
        {
            var invoked = false;

            SentryCore.CaptureEvent(() =>
            {
                invoked = true;
                return(null);
            });
            Assert.False(invoked);
        }
Exemplo n.º 14
0
 public void Init_ValidDsnEnvironmentVariable_EnablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         Sentry.Internals.Constants.DsnEnvironmentVariable,
         DsnSamples.ValidDsnWithSecret,
         () =>
     {
         SentryCore.Init();
         Assert.True(SentryCore.IsEnabled);
     });
 }
Exemplo n.º 15
0
 public void Init_DisableDsnEnvironmentVariable_DisablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         Sentry.Internals.Constants.DsnEnvironmentVariable,
         Sentry.Internals.Constants.DisableSdkDsnValue,
         () =>
     {
         SentryCore.Init();
         Assert.False(SentryCore.IsEnabled);
     });
 }
Exemplo n.º 16
0
 public void EnabledClient_AddBreadcrumb()
 {
     for (int i = 0; i < BreadcrumbsCount; i++)
     {
         SentryCore.AddBreadcrumb(
             Message,
             Type,
             Category,
             Data,
             Level);
     }
 }
Exemplo n.º 17
0
 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);
     });
 }
Exemplo n.º 18
0
        static void Main()
        {
            SentryCore.Init("https://[email protected]/id"); // Initialize SDK

            try
            {
                App();
            }
            finally
            {
                SentryCore.CloseAndFlush();
            }
        }
Exemplo n.º 19
0
 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);
Exemplo n.º 20
0
 public void EnabledSdk_PushScope_AddBreadcrumb_PopScope()
 {
     using (SentryCore.PushScope())
     {
         for (int i = 0; i < BreadcrumbsCount; i++)
         {
             SentryCore.AddBreadcrumb(
                 Message,
                 Type,
                 Category,
                 Data,
                 Level);
         }
     }
 }
Exemplo n.º 21
0
        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();
        }
Exemplo n.º 22
0
            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.
            }
Exemplo n.º 23
0
        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));
        }
Exemplo n.º 25
0
 public void EnabledSdk() => _sdk = SentryCore.Init(Constants.ValidDsn);
Exemplo n.º 26
0
 public Guid CaptureEvent(SentryEvent evt, Scope scope)
 => SentryCore.CaptureEvent(evt, scope);
Exemplo n.º 27
0
 public Guid CaptureException(Exception exception)
 => SentryCore.CaptureException(exception);
Exemplo n.º 28
0
 public Guid CaptureEvent(SentryEvent evt)
 => SentryCore.CaptureEvent(evt);
Exemplo n.º 29
0
 public void BindClient(ISentryClient client)
 => SentryCore.BindClient(client);
Exemplo n.º 30
0
 public IDisposable PushScope <TState>(TState state)
 => SentryCore.PushScope(state);