private static SentryEvent BeforeSend(SentryEvent sentryEvent) { if (sentryEvent.HasUser() == false) { sentryEvent.User = _user; } return(sentryEvent); }
public SentryEvent Process(SentryEvent @event) { _options.DiagnosticLogger?.LogDebug("Running main event processor on: Event {0}", @event.EventId); if ([email protected](Runtime.Type) && Runtime != null) { @event.Contexts[Runtime.Type] = Runtime; } if ([email protected](OperatingSystem.Type)) { // RuntimeInformation.OSDescription is throwing on Mono 5.12 if (!PlatformAbstractions.Runtime.Current.IsMono()) { @event.Contexts.OperatingSystem.RawDescription = RuntimeInformation.OSDescription; } } if (TimeZoneInfo.Local is { } timeZoneInfo) { @event.Contexts.Device.Timezone = timeZoneInfo; } const string currentUiCultureKey = "CurrentUICulture"; if ([email protected](currentUiCultureKey) && CultureInfoToDictionary(CultureInfo.CurrentUICulture) is { } currentUiCultureMap) { @event.Contexts[currentUiCultureKey] = currentUiCultureMap; } const string cultureInfoKey = "CurrentCulture"; if ([email protected](cultureInfoKey) && CultureInfoToDictionary(CultureInfo.CurrentCulture) is { } currentCultureMap) { @event.Contexts[cultureInfoKey] = currentCultureMap; } @event.Platform = Protocol.Constants.Platform; if (@event.Sdk != null) { // SDK Name/Version might have be already set by an outer package // e.g: ASP.NET Core can set itself as the SDK if (@event.Sdk.Version == null && @event.Sdk.Name == null) { @event.Sdk.Name = Constants.SdkName; @event.Sdk.Version = NameAndVersion.Version; } if (NameAndVersion.Version != null) { @event.Sdk.AddPackage(ProtocolPackageName, NameAndVersion.Version); } } // Report local user if opt-in PII, no user was already set to event and feature not opted-out: if (_options.SendDefaultPii && _options.IsEnvironmentUser && [email protected]()) { @event.User.Username = Environment.UserName; } if (@event.ServerName == null) { // Value set on the options take precedence over device name. if (!string.IsNullOrEmpty(_options.ServerName)) { @event.ServerName = _options.ServerName; } else if (_options.SendDefaultPii) { @event.ServerName = Environment.MachineName; } } if (@event.Level == null) { @event.Level = SentryLevel.Error; } if (@event.Release == null) { @event.Release = _options.Release ?? Release; } if (@event.Environment == null) { @event.Environment = _options.Environment ?? EnvironmentLocator.Locate(); } if (@event.Exception == null) { var stackTrace = SentryStackTraceFactoryAccessor().Create(@event.Exception); if (stackTrace != null) { var thread = new SentryThread { Crashed = false, Current = true, Name = Thread.CurrentThread.Name, Id = Thread.CurrentThread.ManagedThreadId, Stacktrace = stackTrace }; @event.SentryThreads = @event.SentryThreads?.Any() == true ? new List <SentryThread>(@event.SentryThreads) { thread } : new[] { thread }.AsEnumerable(); } } if (_options.ReportAssemblies) { foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { if (assembly.IsDynamic) { continue; } var asmName = assembly.GetName(); @event.Modules[asmName.Name] = asmName.Version.ToString(); } } return(@event); }