diff --git a/CHANGELOG.md b/CHANGELOG.md index 792816b4edd..760b600d506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,11 @@ - Do not override user-defined `SentryOptions` ([#4262](https://github.com/getsentry/sentry-java/pull/4262)) - Session Replay: Change bitmap config to `ARGB_8888` for screenshots ([#4282](https://github.com/getsentry/sentry-java/pull/4282)) +### Internal + +- Added `platform` to SentryEnvelopeItemHeader ([#4287](https://github.com/getsentry/sentry-java/pull/4287)) + - Set `android` platform to ProfileChunk envelope item header + ### Dependencies - Bump Native SDK from v0.8.1 to v0.8.2 ([#4267](https://github.com/getsentry/sentry-java/pull/4267)) diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index ebc10beb0cd..8ea97a7430c 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -2762,11 +2762,12 @@ public final class io/sentry/SentryEnvelopeItem { } public final class io/sentry/SentryEnvelopeItemHeader : io/sentry/JsonSerializable, io/sentry/JsonUnknown { - public fun (Lio/sentry/SentryItemType;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public fun (Lio/sentry/SentryItemType;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V public fun getAttachmentType ()Ljava/lang/String; public fun getContentType ()Ljava/lang/String; public fun getFileName ()Ljava/lang/String; public fun getLength ()I + public fun getPlatform ()Ljava/lang/String; public fun getType ()Lio/sentry/SentryItemType; public fun getUnknown ()Ljava/util/Map; public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V @@ -2784,6 +2785,7 @@ public final class io/sentry/SentryEnvelopeItemHeader$JsonKeys { public static final field CONTENT_TYPE Ljava/lang/String; public static final field FILENAME Ljava/lang/String; public static final field LENGTH Ljava/lang/String; + public static final field PLATFORM Ljava/lang/String; public static final field TYPE Ljava/lang/String; public fun ()V } diff --git a/sentry/src/main/java/io/sentry/SentryEnvelopeItem.java b/sentry/src/main/java/io/sentry/SentryEnvelopeItem.java index 62892e3ed44..9a76d118a92 100644 --- a/sentry/src/main/java/io/sentry/SentryEnvelopeItem.java +++ b/sentry/src/main/java/io/sentry/SentryEnvelopeItem.java @@ -302,7 +302,9 @@ private static void ensureAttachmentSizeLimit( SentryItemType.ProfileChunk, () -> cachedItem.getBytes().length, "application-json", - traceFile.getName()); + traceFile.getName(), + null, + profileChunk.getPlatform()); // avoid method refs on Android due to some issues with older AGP setups // noinspection Convert2MethodRef diff --git a/sentry/src/main/java/io/sentry/SentryEnvelopeItemHeader.java b/sentry/src/main/java/io/sentry/SentryEnvelopeItemHeader.java index 6903d9b1bb9..b999ddca416 100644 --- a/sentry/src/main/java/io/sentry/SentryEnvelopeItemHeader.java +++ b/sentry/src/main/java/io/sentry/SentryEnvelopeItemHeader.java @@ -15,6 +15,7 @@ public final class SentryEnvelopeItemHeader implements JsonSerializable, JsonUnk private final @Nullable String contentType; private final @Nullable String fileName; + private final @Nullable String platform; private final @NotNull SentryItemType type; private final int length; @Nullable private final Callable getLength; @@ -46,19 +47,25 @@ public int getLength() { return fileName; } + public @Nullable String getPlatform() { + return platform; + } + @ApiStatus.Internal public SentryEnvelopeItemHeader( final @NotNull SentryItemType type, int length, final @Nullable String contentType, final @Nullable String fileName, - final @Nullable String attachmentType) { + final @Nullable String attachmentType, + final @Nullable String platform) { this.type = Objects.requireNonNull(type, "type is required"); this.contentType = contentType; this.length = length; this.fileName = fileName; this.getLength = null; this.attachmentType = attachmentType; + this.platform = platform; } SentryEnvelopeItemHeader( @@ -67,12 +74,23 @@ public SentryEnvelopeItemHeader( final @Nullable String contentType, final @Nullable String fileName, final @Nullable String attachmentType) { + this(type, getLength, contentType, fileName, attachmentType, null); + } + + SentryEnvelopeItemHeader( + final @NotNull SentryItemType type, + final @Nullable Callable getLength, + final @Nullable String contentType, + final @Nullable String fileName, + final @Nullable String attachmentType, + final @Nullable String platform) { this.type = Objects.requireNonNull(type, "type is required"); this.contentType = contentType; this.length = -1; this.fileName = fileName; this.getLength = getLength; this.attachmentType = attachmentType; + this.platform = platform; } SentryEnvelopeItemHeader( @@ -100,6 +118,7 @@ public static final class JsonKeys { public static final String TYPE = "type"; public static final String ATTACHMENT_TYPE = "attachment_type"; public static final String LENGTH = "length"; + public static final String PLATFORM = "platform"; } @Override @@ -116,6 +135,9 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger if (attachmentType != null) { writer.name(JsonKeys.ATTACHMENT_TYPE).value(attachmentType); } + if (platform != null) { + writer.name(JsonKeys.PLATFORM).value(platform); + } writer.name(JsonKeys.LENGTH).value(getLength()); if (unknown != null) { for (String key : unknown.keySet()) { @@ -138,6 +160,7 @@ public static final class Deserializer implements JsonDeserializer unknown = null; while (reader.peek() == JsonToken.NAME) { @@ -158,6 +181,9 @@ public static final class Deserializer implements JsonDeserializer(); @@ -170,7 +196,8 @@ public static final class Deserializer implements JsonDeserializer { + whenever(it.traceFile).thenReturn(file) + whenever(it.platform).thenReturn("chunk platform") + } + + val chunk = SentryEnvelopeItem.fromProfileChunk(profileChunk, mock()) + assertEquals("chunk platform", chunk.header.platform) + } + @Test fun `fromProfileChunk saves file as Base64`() { val file = File(fixture.pathname) diff --git a/sentry/src/test/java/io/sentry/protocol/SentryEnvelopeItemHeaderSerializationTest.kt b/sentry/src/test/java/io/sentry/protocol/SentryEnvelopeItemHeaderSerializationTest.kt index 5456b27e8a4..3e303be2d28 100644 --- a/sentry/src/test/java/io/sentry/protocol/SentryEnvelopeItemHeaderSerializationTest.kt +++ b/sentry/src/test/java/io/sentry/protocol/SentryEnvelopeItemHeaderSerializationTest.kt @@ -23,7 +23,8 @@ class SentryEnvelopeItemHeaderSerializationTest { 345, "5def420f-3dac-4d7b-948b-49de6e551aef", "54cf4644-8610-4ff3-a535-34ac1f367501", - "6f49ad85-a017-4d94-a5d7-6477251da602" + "6f49ad85-a017-4d94-a5d7-6477251da602", + "android" ) } private val fixture = Fixture() diff --git a/sentry/src/test/resources/json/sentry_envelope_item_header.json b/sentry/src/test/resources/json/sentry_envelope_item_header.json index e4e8e173ca8..a3130fc1b38 100644 --- a/sentry/src/test/resources/json/sentry_envelope_item_header.json +++ b/sentry/src/test/resources/json/sentry_envelope_item_header.json @@ -3,5 +3,6 @@ "filename": "54cf4644-8610-4ff3-a535-34ac1f367501", "type": "event", "attachment_type": "6f49ad85-a017-4d94-a5d7-6477251da602", + "platform": "android", "length": 345 }