From cb7ae0cb38abe53d840d2fa0c86296f4868def70 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sat, 12 Feb 2022 01:55:54 +1100 Subject: [PATCH] Avoid calls the Thread.CurrentThread where possible (#1466) Co-authored-by: Bruno Garcia --- CHANGELOG.md | 1 + src/Sentry/Internal/MainExceptionProcessor.cs | 2 +- src/Sentry/Internal/MainSentryEventProcessor.cs | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96defa3b72..be7f98faac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Reduced the logger noise from EF when not using Performance Monitoring ([#1441](https://github.com/getsentry/sentry-dotnet/pull/1441)) - Create CachingTransport directories in constructor to avoid DirectoryNotFoundException ([#1432](https://github.com/getsentry/sentry-dotnet/pull/1432)) - UnobservedTaskException is now considered as Unhandled ([#1447](https://github.com/getsentry/sentry-dotnet/pull/1447)) +- Avoid calls the Thread.CurrentThread where possible ([#1466](https://github.com/getsentry/sentry-dotnet/pull/1466)) - Rename thread pool protocol keys to snake case ([#1472](https://github.com/getsentry/sentry-dotnet/pull/1472)) - Treat IOException as a network issue ([#1476](https://github.com/getsentry/sentry-dotnet/pull/1476)) - Fix incorrect sdk name in envelope header ([#1474](https://github.com/getsentry/sentry-dotnet/pull/1474)) diff --git a/src/Sentry/Internal/MainExceptionProcessor.cs b/src/Sentry/Internal/MainExceptionProcessor.cs index 9c5a7237db..00095d8005 100644 --- a/src/Sentry/Internal/MainExceptionProcessor.cs +++ b/src/Sentry/Internal/MainExceptionProcessor.cs @@ -103,7 +103,7 @@ internal IEnumerable CreateSentryException(Exception exception) Type = exception.GetType()?.FullName, Module = exception.GetType()?.Assembly?.FullName, Value = exception.Message, - ThreadId = Thread.CurrentThread.ManagedThreadId, + ThreadId = Environment.CurrentManagedThreadId, Mechanism = GetMechanism(exception) }; diff --git a/src/Sentry/Internal/MainSentryEventProcessor.cs b/src/Sentry/Internal/MainSentryEventProcessor.cs index b53d7da102..a756abfc44 100644 --- a/src/Sentry/Internal/MainSentryEventProcessor.cs +++ b/src/Sentry/Internal/MainSentryEventProcessor.cs @@ -98,12 +98,13 @@ public SentryEvent Process(SentryEvent @event) var stackTrace = SentryStackTraceFactoryAccessor().Create(@event.Exception); if (stackTrace != null) { + var currentThread = Thread.CurrentThread; var thread = new SentryThread { Crashed = false, Current = true, - Name = Thread.CurrentThread.Name, - Id = Environment.CurrentManagedThreadId, + Name = currentThread.Name, + Id = currentThread.ManagedThreadId, Stacktrace = stackTrace };