Skip to content

Commit c8dd656

Browse files
feat: Added Main to SentryThread (#4807)
Co-authored-by: Stefan Pölz <[email protected]>
1 parent f92236e commit c8dd656

File tree

7 files changed

+33
-10
lines changed

7 files changed

+33
-10
lines changed

CHANGELOG.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Extended `SentryThread` by `Main` to allow indication whether the thread is considered the current main thread ([#4807](https://github.com/getsentry/sentry-dotnet/pull/4807))
8+
39
## 6.0.0
410

511
### BREAKING CHANGES
@@ -45,25 +51,24 @@
4551
- Deliver system breadcrumbs in the main thread on Android ([#4671](https://github.com/getsentry/sentry-dotnet/pull/4671))
4652
- The `Serilog` integration captures _Structured Logs_ (when enabled) independently of captured Events and added Breadcrumbs ([#4691](https://github.com/getsentry/sentry-dotnet/pull/4691))
4753
- Minimum Log-Level for _Structured Logs_, _Breadcrumbs_ and _Events_ in all Logging-Integrations ([#4700](https://github.com/getsentry/sentry-dotnet/pull/4700))
48-
- for `Sentry.Extensions.Logging`, `Sentry.AspNetCore`, `Sentry.Maui` and `Sentry.Google.Cloud.Functions`
49-
- the Logger-Provider for _Breadcrumbs_ and _Events_ ignores Logging-Configuration (e.g. via `appsettings.json`)
50-
- use the intended `SentryLoggingOptions.MinimumBreadcrumbLevel`, `SentryLoggingOptions.MinimumEventLevel`, or add filter functions via `SentryLoggingOptionsExtensions.AddLogEntryFilter`
51-
- the Logger-Provider for _Structured Logs_ respects Logging-Configuration (e.g. via `appsettings.json`)
52-
- when enabled by `SentryOptions.EnableLogs`
54+
- for `Sentry.Extensions.Logging`, `Sentry.AspNetCore`, `Sentry.Maui` and `Sentry.Google.Cloud.Functions`
55+
- the Logger-Provider for _Breadcrumbs_ and _Events_ ignores Logging-Configuration (e.g. via `appsettings.json`)
56+
- use the intended `SentryLoggingOptions.MinimumBreadcrumbLevel`, `SentryLoggingOptions.MinimumEventLevel`, or add filter functions via `SentryLoggingOptionsExtensions.AddLogEntryFilter`
57+
- the Logger-Provider for _Structured Logs_ respects Logging-Configuration (e.g. via `appsettings.json`)
58+
- when enabled by `SentryOptions.EnableLogs`
5359
- Avoid appending `/NODEFAULTLIB:MSVCRT` to NativeAOT linker arguments on Windows when targetting non-Windows platforms (Android, Browser) ([#4760](https://github.com/getsentry/sentry-dotnet/pull/4760))
5460
- The SDK avoids redundant scope sync after transaction finish ([#4623](https://github.com/getsentry/sentry-dotnet/pull/4623))
5561
- sentry-native is now automatically disabled for WASM applications ([#4631](https://github.com/getsentry/sentry-dotnet/pull/4631))
5662
- Remove unnecessary files from SentryCocoaFramework before packing ([#4602](https://github.com/getsentry/sentry-dotnet/pull/4602))
5763

58-
5964
### Dependencies
6065

6166
- Bump Java SDK from v8.24.0 to v8.28.0 ([#4728](https://github.com/getsentry/sentry-dotnet/pull/4728), [#4761](https://github.com/getsentry/sentry-dotnet/pull/4761), [#4791](https://github.com/getsentry/sentry-dotnet/pull/4791))
62-
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#8280)
63-
- [diff](https://github.com/getsentry/sentry-java/compare/8.24.0...8.28.0)
67+
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#8280)
68+
- [diff](https://github.com/getsentry/sentry-java/compare/8.24.0...8.28.0)
6469
- Bump Native SDK from v0.12.0 to v0.12.2 ([#4690](https://github.com/getsentry/sentry-dotnet/pull/4690), [#4737](https://github.com/getsentry/sentry-dotnet/pull/4737), [#4780](https://github.com/getsentry/sentry-dotnet/pull/4780))
65-
- [changelog](https://github.com/getsentry/sentry-native/blob/master/CHANGELOG.md#0122)
66-
- [diff](https://github.com/getsentry/sentry-native/compare/0.12.0...0.12.2)
70+
- [changelog](https://github.com/getsentry/sentry-native/blob/master/CHANGELOG.md#0122)
71+
- [diff](https://github.com/getsentry/sentry-native/compare/0.12.0...0.12.2)
6772
- Bump Cocoa SDK from v8.57.1 to v8.57.3 ([#4704](https://github.com/getsentry/sentry-dotnet/pull/4704), [#4738](https://github.com/getsentry/sentry-dotnet/pull/4738))
6873
- [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#8573)
6974
- [diff](https://github.com/getsentry/sentry-cocoa/compare/8.57.1...8.57.3)

src/Sentry/SentryThread.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public sealed class SentryThread : ISentryJsonSerializable
2929
/// </summary>
3030
public bool? Current { get; set; }
3131

32+
/// <summary>
33+
/// An optional flag to indicate whether the thread was responsible for rendering
34+
/// the user interface. On mobile and desktop platforms this is oftentimes referred to as the
35+
/// "main thread" or "ui thread".
36+
/// </summary>
37+
public bool? Main { get; set; }
38+
3239
/// <summary>
3340
/// Stack trace.
3441
/// </summary>
@@ -44,6 +51,7 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger)
4451
writer.WriteStringIfNotWhiteSpace("name", Name);
4552
writer.WriteBooleanIfNotNull("crashed", Crashed);
4653
writer.WriteBooleanIfNotNull("current", Current);
54+
writer.WriteBooleanIfNotNull("main", Main);
4755
writer.WriteSerializableIfNotNull("stacktrace", Stacktrace, logger);
4856

4957
writer.WriteEndObject();
@@ -58,6 +66,7 @@ public static SentryThread FromJson(JsonElement json)
5866
var name = json.GetPropertyOrNull("name")?.GetString();
5967
var crashed = json.GetPropertyOrNull("crashed")?.GetBoolean();
6068
var current = json.GetPropertyOrNull("current")?.GetBoolean();
69+
var main = json.GetPropertyOrNull("main")?.GetBoolean();
6170
var stacktrace = json.GetPropertyOrNull("stacktrace")?.Pipe(SentryStackTrace.FromJson);
6271

6372
return new SentryThread
@@ -66,6 +75,7 @@ public static SentryThread FromJson(JsonElement json)
6675
Name = name,
6776
Crashed = crashed,
6877
Current = current,
78+
Main = main,
6979
Stacktrace = stacktrace
7080
};
7181
}

test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ namespace Sentry
996996
public bool? Crashed { get; set; }
997997
public bool? Current { get; set; }
998998
public int? Id { get; set; }
999+
public bool? Main { get; set; }
9991000
public string? Name { get; set; }
10001001
public Sentry.SentryStackTrace? Stacktrace { get; set; }
10011002
public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { }

test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ namespace Sentry
996996
public bool? Crashed { get; set; }
997997
public bool? Current { get; set; }
998998
public int? Id { get; set; }
999+
public bool? Main { get; set; }
9991000
public string? Name { get; set; }
10001001
public Sentry.SentryStackTrace? Stacktrace { get; set; }
10011002
public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { }

test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ namespace Sentry
996996
public bool? Crashed { get; set; }
997997
public bool? Current { get; set; }
998998
public int? Id { get; set; }
999+
public bool? Main { get; set; }
9991000
public string? Name { get; set; }
10001001
public Sentry.SentryStackTrace? Stacktrace { get; set; }
10011002
public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { }

test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ namespace Sentry
972972
public bool? Crashed { get; set; }
973973
public bool? Current { get; set; }
974974
public int? Id { get; set; }
975+
public bool? Main { get; set; }
975976
public string? Name { get; set; }
976977
public Sentry.SentryStackTrace? Stacktrace { get; set; }
977978
public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { }

test/Sentry.Tests/Protocol/SentryThreadTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject()
1616
{
1717
Crashed = true,
1818
Current = true,
19+
Main = true,
1920
Id = 0,
2021
Name = "thread11",
2122
Stacktrace = new SentryStackTrace
@@ -35,6 +36,7 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject()
3536
"name": "thread11",
3637
"crashed": true,
3738
"current": true,
39+
"main": true,
3840
"stacktrace": {
3941
"frames": [
4042
{
@@ -62,6 +64,8 @@ public static IEnumerable<object[]> TestCases()
6264
yield return new object[] { (new SentryThread { Name = "some name" }, """{"name":"some name"}""") };
6365
yield return new object[] { (new SentryThread { Crashed = false }, """{"crashed":false}""") };
6466
yield return new object[] { (new SentryThread { Current = false }, """{"current":false}""") };
67+
yield return new object[] { (new SentryThread { Main = false }, """{"main":false}""") };
68+
yield return new object[] { (new SentryThread { Main = true }, """{"main":true}""") };
6569
yield return new object[] { (new SentryThread { Id = 200 }, """{"id":200}""") };
6670
yield return new object[] { (new SentryThread { Stacktrace = new SentryStackTrace { Frames = { new SentryStackFrame { InApp = true } } } },
6771
"""{"stacktrace":{"frames":[{"in_app":true}]}}""") };

0 commit comments

Comments
 (0)