Skip to content

Commit 77a03e2

Browse files
Restore serialization of the Platform name (#1702)
* Revert "Obsolete platform and always write csharp (#1610)" This reverts commit e15413f. * Add comment and adjust changelog
1 parent d39477c commit 77a03e2

23 files changed

+49
-100
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Serialize stack frame addresses as strings. ([#1692](https://github.com/getsentry/sentry-dotnet/pull/1692))
1111
- Improve serialization perf and fix memory leak in `SentryEvent` ([#1693](https://github.com/getsentry/sentry-dotnet/pull/1693))
1212
- Add type checking in contexts TryGetValue ([#1700](https://github.com/getsentry/sentry-dotnet/pull/1700))
13+
- Restore serialization of the `Platform` name ([#1702](https://github.com/getsentry/sentry-dotnet/pull/1702))
1314

1415
### Features
1516

src/Sentry/IEventLike.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.ComponentModel;
43
using System.Linq;
@@ -42,7 +41,11 @@ public interface IEventLike : IHasBreadcrumbs, IHasTags, IHasExtra
4241
/// <summary>
4342
/// The name of the platform.
4443
/// </summary>
45-
[Obsolete("Platform is always csharp, and should not be set by consuming code. This property will be removed in version 4.")]
44+
/// <remarks>
45+
/// In most cases, the platform will be "csharp". However, it may differ if the event
46+
/// was generated from another embeded SDK. For example, when targeting net6.0-android,
47+
/// events generated by the Sentry Android SDK will have the platform "java".
48+
/// </remarks>
4649
public string? Platform { get; set; }
4750

4851
/// <summary>

src/Sentry/Internal/Enricher.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public void Apply(IEventLike eventLike)
5555
eventLike.Sdk.AddPackage("nuget:" + SdkVersion.Instance.Name, SdkVersion.Instance.Version);
5656
}
5757

58+
// Platform
59+
eventLike.Platform ??= Sentry.Constants.Platform;
60+
5861
// Release
5962
eventLike.Release ??= ReleaseLocator.Resolve(_options);
6063

src/Sentry/Scope.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ public User User
127127
}
128128

129129
/// <inheritdoc />
130-
[Obsolete("Platform is always csharp, and should not be set by consuming code. This property will be removed in version 4.")]
131-
public string? Platform { get; set; } = Constants.Platform;
130+
public string? Platform { get; set; }
132131

133132
/// <inheritdoc />
134133
public string? Release { get; set; }
@@ -361,6 +360,7 @@ public void Apply(IEventLike other)
361360
Request.CopyTo(other.Request);
362361
User.CopyTo(other.User);
363362

363+
other.Platform ??= Platform;
364364
other.Release ??= Release;
365365
other.Environment ??= Environment;
366366
other.TransactionName ??= TransactionName;

src/Sentry/SentryEvent.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public sealed class SentryEvent : IEventLike, IJsonSerializable
6363
public string? Logger { get; set; }
6464

6565
/// <inheritdoc />
66-
[Obsolete("Platform is always csharp, and should not be set by consuming code. This property will be removed in version 4.")]
67-
public string? Platform { get; set; } = Constants.Platform;
66+
public string? Platform { get; set; }
6867

6968
/// <summary>
7069
/// Identifies the host SDK from which the event was recorded.
@@ -203,6 +202,7 @@ internal SentryEvent(
203202
Exception = exception;
204203
Timestamp = timestamp ?? DateTimeOffset.UtcNow;
205204
EventId = eventId != default ? eventId : SentryId.Create();
205+
Platform = Constants.Platform;
206206
}
207207

208208
/// <inheritdoc />
@@ -231,7 +231,7 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger)
231231
writer.WriteString("timestamp", Timestamp);
232232
writer.WriteSerializableIfNotNull("logentry", Message, logger);
233233
writer.WriteStringIfNotWhiteSpace("logger", Logger);
234-
writer.WriteString("platform", Constants.Platform);
234+
writer.WriteStringIfNotWhiteSpace("platform", Platform);
235235
writer.WriteStringIfNotWhiteSpace("server_name", ServerName);
236236
writer.WriteStringIfNotWhiteSpace("release", Release);
237237
writer.WriteSerializableIfNotNull("exception", SentryExceptionValues, logger);
@@ -273,6 +273,7 @@ internal static SentryEvent FromJson(JsonElement json, Exception? exception)
273273
var timestamp = json.GetPropertyOrNull("timestamp")?.GetDateTimeOffset();
274274
var message = json.GetPropertyOrNull("logentry")?.Pipe(SentryMessage.FromJson);
275275
var logger = json.GetPropertyOrNull("logger")?.GetString();
276+
var platform = json.GetPropertyOrNull("platform")?.GetString();
276277
var serverName = json.GetPropertyOrNull("server_name")?.GetString();
277278
var release = json.GetPropertyOrNull("release")?.GetString();
278279
var exceptionValues = json.GetPropertyOrNull("exception")?.GetPropertyOrNull("values")?.EnumerateArray().Select(SentryException.FromJson).ToList().Pipe(v => new SentryValues<SentryException>(v));
@@ -297,6 +298,7 @@ internal static SentryEvent FromJson(JsonElement json, Exception? exception)
297298
_modules = modules?.WhereNotNullValue().ToDictionary(),
298299
Message = message,
299300
Logger = logger,
301+
Platform = platform,
300302
ServerName = serverName,
301303
Release = release,
302304
SentryExceptionValues = exceptionValues,

src/Sentry/Transaction.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public SentryId TraceId
5353
public bool? IsParentSampled { get; set; }
5454

5555
/// <inheritdoc />
56-
[Obsolete("Platform is always csharp, and should not be set by consuming code. This property will be removed in version 4.")]
5756
public string? Platform { get; set; } = Constants.Platform;
5857

5958
/// <inheritdoc />
@@ -211,6 +210,7 @@ public Transaction(ITransaction tracer)
211210
SpanId = tracer.SpanId;
212211
TraceId = tracer.TraceId;
213212
Operation = tracer.Operation;
213+
Platform = tracer.Platform;
214214
Release = tracer.Release;
215215
StartTimestamp = tracer.StartTimestamp;
216216
EndTimestamp = tracer.EndTimestamp;
@@ -259,7 +259,7 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger)
259259
writer.WriteString("type", "transaction");
260260
writer.WriteSerializable("event_id", EventId, logger);
261261
writer.WriteStringIfNotWhiteSpace("level", Level?.ToString().ToLowerInvariant());
262-
writer.WriteString("platform", Constants.Platform);
262+
writer.WriteStringIfNotWhiteSpace("platform", Platform);
263263
writer.WriteStringIfNotWhiteSpace("release", Release);
264264
writer.WriteStringIfNotWhiteSpace("transaction", Name);
265265
writer.WriteString("start_timestamp", StartTimestamp);
@@ -288,6 +288,7 @@ public static Transaction FromJson(JsonElement json)
288288
var startTimestamp = json.GetProperty("start_timestamp").GetDateTimeOffset();
289289
var endTimestamp = json.GetPropertyOrNull("timestamp")?.GetDateTimeOffset();
290290
var level = json.GetPropertyOrNull("level")?.GetString()?.ParseEnum<SentryLevel>();
291+
var platform = json.GetPropertyOrNull("platform")?.GetString();
291292
var release = json.GetPropertyOrNull("release")?.GetString();
292293
var request = json.GetPropertyOrNull("request")?.Pipe(Request.FromJson);
293294
var contexts = json.GetPropertyOrNull("contexts")?.Pipe(Contexts.FromJson);
@@ -309,6 +310,7 @@ public static Transaction FromJson(JsonElement json)
309310
StartTimestamp = startTimestamp,
310311
EndTimestamp = endTimestamp,
311312
Level = level,
313+
Platform = platform,
312314
Release = release,
313315
_request = request,
314316
Contexts = contexts ?? new(),

src/Sentry/TransactionTracer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public SentryId TraceId
4545
public bool? IsParentSampled { get; set; }
4646

4747
/// <inheritdoc />
48-
[Obsolete("Platform is always csharp, and should not be set by consuming code. This property will be removed in version 4.")]
4948
public string? Platform { get; set; } = Constants.Platform;
5049

5150
/// <inheritdoc />

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEf.Core3_1.verified.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Type: Exception,
77
Message: my exception
88
},
9+
Platform: csharp,
910
SentryExceptions: [
1011
{
1112
Type: System.Exception,
@@ -24,6 +25,7 @@
2425
{
2526
Source: {
2627
Name: my transaction,
28+
Platform: csharp,
2729
Operation: my operation,
2830
Description: ,
2931
Status: UnknownError,

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEf.DotNet5_0.verified.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Type: Exception,
77
Message: my exception
88
},
9+
Platform: csharp,
910
SentryExceptions: [
1011
{
1112
Type: System.Exception,
@@ -24,6 +25,7 @@
2425
{
2526
Source: {
2627
Name: my transaction,
28+
Platform: csharp,
2729
Operation: my operation,
2830
Description: ,
2931
Status: UnknownError,

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEf.DotNet6_0.verified.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Type: Exception,
77
Message: my exception
88
},
9+
Platform: csharp,
910
SentryExceptions: [
1011
{
1112
Type: System.Exception,
@@ -24,6 +25,7 @@
2425
{
2526
Source: {
2627
Name: my transaction,
28+
Platform: csharp,
2729
Operation: my operation,
2830
Description: ,
2931
Status: UnknownError,

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsEf.Net4_8.verified.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Type: Exception,
77
Message: my exception
88
},
9+
Platform: csharp,
910
SentryExceptions: [
1011
{
1112
Type: System.Exception,
@@ -24,6 +25,7 @@
2425
{
2526
Source: {
2627
Name: my transaction,
28+
Platform: csharp,
2729
Operation: my operation,
2830
Description: ,
2931
Status: UnknownError,

test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.RecordsSql.verified.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Type: Exception,
77
Message: my exception
88
},
9+
Platform: csharp,
910
SentryExceptions: [
1011
{
1112
Type: System.Exception,
@@ -24,6 +25,7 @@
2425
{
2526
Source: {
2627
Name: my transaction,
28+
Platform: csharp,
2729
Operation: my operation,
2830
Description: ,
2931
Status: UnknownError,

test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ namespace Sentry
153153
string? Environment { get; set; }
154154
System.Collections.Generic.IReadOnlyList<string> Fingerprint { get; set; }
155155
Sentry.SentryLevel? Level { get; set; }
156-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
157-
" will be removed in version 4.")]
158156
string? Platform { get; set; }
159157
string? Release { get; set; }
160158
Sentry.Request Request { get; set; }
@@ -309,8 +307,6 @@ namespace Sentry
309307
public System.Collections.Generic.IReadOnlyDictionary<string, object?> Extra { get; }
310308
public System.Collections.Generic.IReadOnlyList<string> Fingerprint { get; set; }
311309
public Sentry.SentryLevel? Level { get; set; }
312-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
313-
" will be removed in version 4.")]
314310
public string? Platform { get; set; }
315311
public string? Release { get; set; }
316312
public Sentry.Request Request { get; set; }
@@ -390,8 +386,6 @@ namespace Sentry
390386
public string? Logger { get; set; }
391387
public Sentry.SentryMessage? Message { get; set; }
392388
public System.Collections.Generic.IDictionary<string, string> Modules { get; }
393-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
394-
" will be removed in version 4.")]
395389
public string? Platform { get; set; }
396390
public string? Release { get; set; }
397391
public Sentry.Request Request { get; set; }
@@ -813,8 +807,6 @@ namespace Sentry
813807
public string Name { get; }
814808
public string Operation { get; }
815809
public Sentry.SpanId? ParentSpanId { get; }
816-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
817-
" will be removed in version 4.")]
818810
public string? Platform { get; set; }
819811
public string? Release { get; set; }
820812
public Sentry.Request Request { get; set; }
@@ -868,8 +860,6 @@ namespace Sentry
868860
public string Name { get; set; }
869861
public string Operation { get; set; }
870862
public Sentry.SpanId? ParentSpanId { get; }
871-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
872-
" will be removed in version 4.")]
873863
public string? Platform { get; set; }
874864
public string? Release { get; set; }
875865
public Sentry.Request Request { get; set; }

test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ namespace Sentry
153153
string? Environment { get; set; }
154154
System.Collections.Generic.IReadOnlyList<string> Fingerprint { get; set; }
155155
Sentry.SentryLevel? Level { get; set; }
156-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
157-
" will be removed in version 4.")]
158156
string? Platform { get; set; }
159157
string? Release { get; set; }
160158
Sentry.Request Request { get; set; }
@@ -309,8 +307,6 @@ namespace Sentry
309307
public System.Collections.Generic.IReadOnlyDictionary<string, object?> Extra { get; }
310308
public System.Collections.Generic.IReadOnlyList<string> Fingerprint { get; set; }
311309
public Sentry.SentryLevel? Level { get; set; }
312-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
313-
" will be removed in version 4.")]
314310
public string? Platform { get; set; }
315311
public string? Release { get; set; }
316312
public Sentry.Request Request { get; set; }
@@ -390,8 +386,6 @@ namespace Sentry
390386
public string? Logger { get; set; }
391387
public Sentry.SentryMessage? Message { get; set; }
392388
public System.Collections.Generic.IDictionary<string, string> Modules { get; }
393-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
394-
" will be removed in version 4.")]
395389
public string? Platform { get; set; }
396390
public string? Release { get; set; }
397391
public Sentry.Request Request { get; set; }
@@ -813,8 +807,6 @@ namespace Sentry
813807
public string Name { get; }
814808
public string Operation { get; }
815809
public Sentry.SpanId? ParentSpanId { get; }
816-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
817-
" will be removed in version 4.")]
818810
public string? Platform { get; set; }
819811
public string? Release { get; set; }
820812
public Sentry.Request Request { get; set; }
@@ -868,8 +860,6 @@ namespace Sentry
868860
public string Name { get; set; }
869861
public string Operation { get; set; }
870862
public Sentry.SpanId? ParentSpanId { get; }
871-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
872-
" will be removed in version 4.")]
873863
public string? Platform { get; set; }
874864
public string? Release { get; set; }
875865
public Sentry.Request Request { get; set; }

test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ namespace Sentry
153153
string? Environment { get; set; }
154154
System.Collections.Generic.IReadOnlyList<string> Fingerprint { get; set; }
155155
Sentry.SentryLevel? Level { get; set; }
156-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
157-
" will be removed in version 4.")]
158156
string? Platform { get; set; }
159157
string? Release { get; set; }
160158
Sentry.Request Request { get; set; }
@@ -309,8 +307,6 @@ namespace Sentry
309307
public System.Collections.Generic.IReadOnlyDictionary<string, object?> Extra { get; }
310308
public System.Collections.Generic.IReadOnlyList<string> Fingerprint { get; set; }
311309
public Sentry.SentryLevel? Level { get; set; }
312-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
313-
" will be removed in version 4.")]
314310
public string? Platform { get; set; }
315311
public string? Release { get; set; }
316312
public Sentry.Request Request { get; set; }
@@ -390,8 +386,6 @@ namespace Sentry
390386
public string? Logger { get; set; }
391387
public Sentry.SentryMessage? Message { get; set; }
392388
public System.Collections.Generic.IDictionary<string, string> Modules { get; }
393-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
394-
" will be removed in version 4.")]
395389
public string? Platform { get; set; }
396390
public string? Release { get; set; }
397391
public Sentry.Request Request { get; set; }
@@ -813,8 +807,6 @@ namespace Sentry
813807
public string Name { get; }
814808
public string Operation { get; }
815809
public Sentry.SpanId? ParentSpanId { get; }
816-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
817-
" will be removed in version 4.")]
818810
public string? Platform { get; set; }
819811
public string? Release { get; set; }
820812
public Sentry.Request Request { get; set; }
@@ -868,8 +860,6 @@ namespace Sentry
868860
public string Name { get; set; }
869861
public string Operation { get; set; }
870862
public Sentry.SpanId? ParentSpanId { get; }
871-
[System.Obsolete("Platform is always csharp, and should not be set by consuming code. This property" +
872-
" will be removed in version 4.")]
873863
public string? Platform { get; set; }
874864
public string? Release { get; set; }
875865
public Sentry.Request Request { get; set; }

0 commit comments

Comments
 (0)