public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject() { var sut = new SentryThread { Crashed = true, Current = true, Id = 0, Name = "thread11", Stacktrace = new SentryStackTrace { Frames = { new SentryStackFrame { FileName = "test" } } } }; var actual = sut.ToJsonString(); Assert.Equal( "{\"id\":0," + "\"name\":\"thread11\"," + "\"crashed\":true," + "\"current\":true," + "\"stacktrace\":{\"frames\":[{\"filename\":\"test\"}]}}", actual); }
public SentryEvent Process(SentryEvent @event) { _options.LogDebug("Running main event processor on: Event {0}", @event.EventId); if (TimeZoneInfo.Local is { } timeZoneInfo) { @event.Contexts.Device.Timezone = timeZoneInfo; } IDictionary <string, string>?cultureInfoMapped = null; if ([email protected](CultureInfoKey) && CultureInfoToDictionary(CultureInfo.CurrentCulture) is { } currentCultureMap) { cultureInfoMapped = currentCultureMap; @event.Contexts[CultureInfoKey] = currentCultureMap; } if ([email protected](CurrentUiCultureKey) && CultureInfoToDictionary(CultureInfo.CurrentUICulture) is { } currentUiCultureMap && (cultureInfoMapped is null || currentUiCultureMap.Any(p => !cultureInfoMapped.Contains(p)))) { @event.Contexts[CurrentUiCultureKey] = currentUiCultureMap; } #if NETCOREAPP3_0_OR_GREATER @event.Contexts[IsDynamicCodeKey] = new Dictionary <string, bool> { { IsDynamicCodeCompiledKey, RuntimeFeature.IsDynamicCodeCompiled }, { IsDynamicCodeSupportedKey, RuntimeFeature.IsDynamicCodeSupported } }; #endif AddMemoryInfo(@event.Contexts); AddThreadPoolInfo(@event.Contexts); 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 = Release; } if (@event.Exception == null) { var stackTrace = SentryStackTraceFactoryAccessor().Create(@event.Exception); if (stackTrace != null) { var currentThread = Thread.CurrentThread; var thread = new SentryThread { Crashed = false, Current = true, Name = currentThread.Name, Id = currentThread.ManagedThreadId, Stacktrace = stackTrace }; @event.SentryThreads = @event.SentryThreads?.Any() == true ? new List <SentryThread>(@event.SentryThreads) { thread } : new[] { thread }.AsEnumerable(); } } if (_options.ReportAssembliesMode != ReportAssembliesMode.None) { foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { if (assembly.IsDynamic) { continue; } var asmName = assembly.GetName(); if (asmName.Name is null) { continue; } var asmVersion = _options.ReportAssembliesMode switch { ReportAssembliesMode.Version => asmName.Version?.ToString() ?? string.Empty, ReportAssembliesMode.InformationalVersion => assembly.GetVersion() ?? string.Empty, _ => throw new ArgumentOutOfRangeException( $"Report assemblies mode '{_options.ReportAssembliesMode}' is not yet supported") }; if (!string.IsNullOrWhiteSpace(asmVersion)) { @event.Modules[asmName.Name] = asmVersion; } } } // Run enricher to fill in the gaps _enricher.Apply(@event); return(@event); }
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); }
public SentryEvent Process(SentryEvent @event) { _options.DiagnosticLogger?.LogDebug("Running main event processor on: Event {0}", @event.EventId); if (TimeZoneInfo.Local is { } timeZoneInfo) { @event.Contexts.Device.Timezone = timeZoneInfo; } IDictionary <string, string>?cultureInfoMapped = null; if ([email protected](CultureInfoKey) && CultureInfoToDictionary(CultureInfo.CurrentCulture) is { } currentCultureMap) { cultureInfoMapped = currentCultureMap; @event.Contexts[CultureInfoKey] = currentCultureMap; } if ([email protected](CurrentUiCultureKey) && CultureInfoToDictionary(CultureInfo.CurrentUICulture) is { } currentUiCultureMap && (cultureInfoMapped is null || currentUiCultureMap.Any(p => !cultureInfoMapped.Contains(p)))) { @event.Contexts[CurrentUiCultureKey] = currentUiCultureMap; } 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.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(); if (asmName.Name is not null && asmName.Version is not null) { @event.Modules[asmName.Name] = asmName.Version.ToString(); } } } // Run enricher to fill in the gaps _enricher.Apply(@event); return(@event); }