private SentryEvent PrepareEvent(SentryEvent @event) { var scope = ScopeManagement.GetCurrent(); // TODO: Consider multiple events being sent with the same scope: // Wherever this code will end up, it should evaluate only once if (scope.States != null) { foreach (var state in scope.States) { if (state is string scopeString) { @event.SetTag("scope", scopeString); } else if (state is IEnumerable <KeyValuePair <string, string> > keyValStringString) { @event.SetTags(keyValStringString); } else if (state is IEnumerable <KeyValuePair <string, object> > keyValStringObject) { @event.SetTags(keyValStringObject.Select(k => new KeyValuePair <string, string>(k.Key, k.Value.ToString()))); } else { // TODO: possible callback invocation here @event.SetExtra("State of unknown type", state.GetType().ToString()); } } } @event = _options.BeforeSend?.Invoke(@event); return(@event); }
public void Process_AppliesDefaultTags(IDictionary <string, string> eventTags, IDictionary <string, string> defaultTags, IDictionary <string, string> expectedTags) { //Arrange var evt = new SentryEvent(); // Any scoped tags for this event? if (eventTags != null) { evt.SetTags(eventTags); } foreach (var defaultTag in defaultTags) { _fixture.SentryOptions.DefaultTags[defaultTag.Key] = defaultTag.Value; } var sut = _fixture.GetSut(); //Act _ = sut.Process(evt); //Assert foreach (var expectedTag in expectedTags) { Assert.Equal(expectedTag.Value, evt.Tags[expectedTag.Key]); } }
public static void Error(string message, Exception exception, IEnumerable <KeyValuePair <string, string> > extraTags = null) { SentryEvent sentryEvent = new SentryEvent(exception) { Message = message, Level = Sentry.Protocol.SentryLevel.Error, }; if (extraTags != null) { sentryEvent.SetTags(extraTags); } SentrySdk.CaptureEvent(sentryEvent); }