示例#1
0
        public void PushScope_NullArgument_NoOp()
        {
            var scopeGuard = SentrySdk.PushScope(null as object);

            Assert.False(SentrySdk.IsEnabled);
            scopeGuard.Dispose();
        }
示例#2
0
        public void PushScope_Parameterless_NoOp()
        {
            var scopeGuard = SentrySdk.PushScope();

            Assert.False(SentrySdk.IsEnabled);
            scopeGuard.Dispose();
        }
示例#3
0
        private async Task HandleCommandAsync(SocketMessage messageParam)
        {
            if (!(messageParam is SocketUserMessage message))
            {
                return;
            }

            int argPos = 0;

            if (message.HasCharPrefix('%', ref argPos) && !message.Author.IsBot)
            {
                var context = new SocketCommandContext(Client, message);
                using (SentrySdk.PushScope())
                {
                    SentrySdk.ConfigureScope(scope =>
                    {
                        scope.User = new Sentry.Protocol.User
                        {
                            Id       = message.Author.Id.ToString(),
                            Username = message.Author.Username + "#" + message.Author.Discriminator,
                        };
                        scope.SetExtra("message", message.Content);
                    });

                    Log.Debug("Executing command {Command}", message.Content);
                    await _commands.ExecuteAsync(context, argPos, _services);
                }
            }
        }
        private static async Task App()
        {
            SentrySdk.ConfigureScope(scope => scope.AddTag("Initial scope data."));

            SentrySdk.WithClientAndScope((client, scope) =>
            {
                // Create heavy event stuff
                var evt = new SentryEvent("Entrypoint event.");
                scope.AddTag("Some scope change done in the callback");
                return(client.CaptureEvent(evt, scope));
            });

            // TODO: how does it behave with .ConfigureAwait(false);
            var task = Task.Run(() =>
            {
                // If no scope is pushed here, it'd be mutating the outer scope
                SentrySdk.PushScope(); // New scope, clone of the parent

                // Should it be ConfigureNewScope instead and bundle operations?
                SentrySdk.ConfigureScope(scope => scope.AddTag("First TPL task adding to scope"));

                // Simply send event
                SentrySdk.CaptureEvent(new SentryEvent("First Event from TPL"));
            });

            await task;

            // here we shouldn't see side-effect from the TPL task
            SentrySdk.CaptureEvent(new SentryEvent("Final event from main thread"));

            throw new Exception("Error in the app");
        }
示例#5
0
        public static IDisposable WithScope(Action <Scope> configureScope)
        {
            var scope = SentrySdk.PushScope();

            SentrySdk.ConfigureScope(configureScope);
            return(scope);
        }
示例#6
0
        public async Task Invoke(IDictionary <string, object> environment)
        {
            using (SentrySdk.PushScope())
            {
                SentrySdk.ConfigureScope(scope =>
                {
                    // Gets called if an event is sent out within this request.
                    // By a logger.LogError or FirstChanceException
                    scope.AddEventProcessor(@event =>
                    {
                        ApplyContext(@event, environment);
                        return(@event);
                    });
                });
                try
                {
                    await _next(environment);
                }
                catch (Exception ex)
                {
                    // An exception thrown in the ExceptionHandler will end up here.
                    var evt = new SentryEvent(ex);
                    ApplyContext(evt, environment);
                    SentrySdk.CaptureEvent(evt);

                    throw;
                }
            }
        }
示例#7
0
 public void EnabledSdk_PushScope_AddBreadcrumb_PopScope()
 {
     using (SentrySdk.PushScope())
     {
         for (int i = 0; i < BreadcrumbsCount; i++)
         {
             SentrySdk.AddBreadcrumb(
                 Message,
                 Category,
                 Type,
                 Data,
                 Level);
         }
     }
 }
示例#8
0
 public void Handle(Null _)
 {
     _application.UnhandledException += (_, args) =>
     {
         using (SentrySdk.PushScope())
         {
             SentrySdk.ConfigureScope(s => s.SetTag("UnhandledException", "true"));
             SentrySdk.CaptureException(args.Exception);
             if (!args.Handled)                     // Not handled yet
             {
                 // App might crash so make sure we flush this event.
                 SentrySdk.FlushAsync(TimeSpan.FromSeconds(2)).Wait();
             }
         }
     };
 }
示例#9
0
        public void PushScope_Recursively()
        {
            PushScope(Depth).Dispose();

            IDisposable PushScope(int i)
            {
                if (i == 0)
                {
                    return(DisabledHub.Instance);
                }
                using (SentrySdk.PushScope())
                {
                    return(PushScope(i - 1));
                }
            }
        }
示例#10
0
 public override void OnAwake()
 {
     ConsoleSystem.IsOutputToFile = false;
     Task.Run(() =>
     {
         using (SentrySdk.PushScope("SteamPlayer"))
         {
             try
             {
                 new SteamPlayer(_username, _password, _ip, _port, _quitAfterConnected).Connect();
             }
             catch (Exception e)
             {
                 SentrySdk.CaptureException(e);
             }
         }
     });
 }
示例#11
0
            public void Invoke(string request)
            {
                using (SentrySdk.PushScope())
                {
                    SentrySdk.AddBreadcrumb(request, "request-path");

                    // Change the SentryClient in case the request is to the admin part:
                    if (request.StartsWith("/admin"))
                    {
                        // Within this scope, the _adminClient will be used instead of whatever
                        // client was defined before this point:
                        SentrySdk.BindClient(_adminClient);
                    }

                    SentrySdk.CaptureException(new Exception("Error at the admin section"));
                    // Else it uses the default client
                } // Scope is disposed.
            }
示例#12
0
        private async Task HandleCommandAsync(SocketMessage incomingMessage)
        {
            if (!(incomingMessage is SocketUserMessage message))
            {
                return;
            }
            if (message.Source != MessageSource.User)
            {
                return;
            }

            int argPos = 0;

            if (!(incomingMessage.Channel is SocketDMChannel))
            {
                if (!message.HasStringPrefix(_config["prefix"], ref argPos) && !message.HasMentionPrefix(_client.CurrentUser, ref argPos))
                {
                    return;
                }
            }

            using (SentrySdk.PushScope())
            {
                var context = new SocketCommandContext(_client, message);

                SentrySdk.ConfigureScope(s =>
                {
                    s.User = new User {
                        Id = message.Author.Id.ToString(), Username = message.Author.ToString()
                    };
                    s.SetTag("Guild", context.Guild?.Name ?? "Private Message");
                    s.SetTag("Channel", context.Channel?.Name ?? "N/A");
                });

                await _commandService.ExecuteAsync(context, argPos, _services);
            }
        }
        public static string[] GetRolesFromClaims(IEnumerable <Claim> claims)
        {
            var claimsArray = claims as Claim[] ?? claims.ToArray();

            var realmAccessClaim = claimsArray.SingleOrDefault(x => x.Type == "realm_access");

            if (realmAccessClaim == null)
            {
                return(null);
            }

            if (realmAccessClaim.ValueType != "JSON")
            {
                using (SentrySdk.PushScope())
                {
                    SentrySdk.ConfigureScope(s => { s.SetTags(claimsArray.Select(x => new KeyValuePair <string, string>(x.Type, x.Value))); });

                    SentrySdk.CaptureMessage($"Expected the 'realm_access' claim to be type JSON but it was '{realmAccessClaim.ValueType}'", Sentry.Protocol.SentryLevel.Warning);
                }

                return(null);
            }

            if (realmAccessClaim.Value == null)
            {
                using (SentrySdk.PushScope())
                {
                    SentrySdk.ConfigureScope(s => { s.SetTags(claimsArray.Select(x => new KeyValuePair <string, string>(x.Type, x.Value))); });

                    SentrySdk.CaptureMessage($"Expected the 'realm_access' value to be non-null", Sentry.Protocol.SentryLevel.Warning);
                }

                return(null);
            }

            return(JsonConvert.DeserializeObject <RealmAccessJson>(realmAccessClaim.Value)?.Roles);
        }
示例#14
0
 public void PushScope_MultiCallParameterless_SameDisposableInstance() => Assert.Same(SentrySdk.PushScope(), SentrySdk.PushScope());
示例#15
0
        public void PushScope_MultiCallState_SameDisposableInstance()
        {
            var state = new object();

            Assert.Same(SentrySdk.PushScope(state), SentrySdk.PushScope(state));
        }
示例#16
0
 public void PushScope_InstanceOf_DisabledClient()
 {
     Assert.Same(DisabledHub.Instance, SentrySdk.PushScope());
 }