Skip to content

Commit 61e8426

Browse files
authored
Merge 6a4b1ad into a27ecb4
2 parents a27ecb4 + 6a4b1ad commit 61e8426

File tree

6 files changed

+49
-5
lines changed

6 files changed

+49
-5
lines changed

sentry/api/sentry.api

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2762,11 +2762,12 @@ public final class io/sentry/SentryEnvelopeItem {
27622762
}
27632763

27642764
public final class io/sentry/SentryEnvelopeItemHeader : io/sentry/JsonSerializable, io/sentry/JsonUnknown {
2765-
public fun <init> (Lio/sentry/SentryItemType;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
2765+
public fun <init> (Lio/sentry/SentryItemType;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
27662766
public fun getAttachmentType ()Ljava/lang/String;
27672767
public fun getContentType ()Ljava/lang/String;
27682768
public fun getFileName ()Ljava/lang/String;
27692769
public fun getLength ()I
2770+
public fun getPlatform ()Ljava/lang/String;
27702771
public fun getType ()Lio/sentry/SentryItemType;
27712772
public fun getUnknown ()Ljava/util/Map;
27722773
public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V
@@ -2784,6 +2785,7 @@ public final class io/sentry/SentryEnvelopeItemHeader$JsonKeys {
27842785
public static final field CONTENT_TYPE Ljava/lang/String;
27852786
public static final field FILENAME Ljava/lang/String;
27862787
public static final field LENGTH Ljava/lang/String;
2788+
public static final field PLATFORM Ljava/lang/String;
27872789
public static final field TYPE Ljava/lang/String;
27882790
public fun <init> ()V
27892791
}

sentry/src/main/java/io/sentry/SentryEnvelopeItem.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ private static void ensureAttachmentSizeLimit(
302302
SentryItemType.ProfileChunk,
303303
() -> cachedItem.getBytes().length,
304304
"application-json",
305-
traceFile.getName());
305+
traceFile.getName(),
306+
null,
307+
"android");
306308

307309
// avoid method refs on Android due to some issues with older AGP setups
308310
// noinspection Convert2MethodRef

sentry/src/main/java/io/sentry/SentryEnvelopeItemHeader.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public final class SentryEnvelopeItemHeader implements JsonSerializable, JsonUnk
1515

1616
private final @Nullable String contentType;
1717
private final @Nullable String fileName;
18+
private final @Nullable String platform;
1819
private final @NotNull SentryItemType type;
1920
private final int length;
2021
@Nullable private final Callable<Integer> getLength;
@@ -46,19 +47,25 @@ public int getLength() {
4647
return fileName;
4748
}
4849

50+
public @Nullable String getPlatform() {
51+
return platform;
52+
}
53+
4954
@ApiStatus.Internal
5055
public SentryEnvelopeItemHeader(
5156
final @NotNull SentryItemType type,
5257
int length,
5358
final @Nullable String contentType,
5459
final @Nullable String fileName,
55-
final @Nullable String attachmentType) {
60+
final @Nullable String attachmentType,
61+
final @Nullable String platform) {
5662
this.type = Objects.requireNonNull(type, "type is required");
5763
this.contentType = contentType;
5864
this.length = length;
5965
this.fileName = fileName;
6066
this.getLength = null;
6167
this.attachmentType = attachmentType;
68+
this.platform = platform;
6269
}
6370

6471
SentryEnvelopeItemHeader(
@@ -67,12 +74,23 @@ public SentryEnvelopeItemHeader(
6774
final @Nullable String contentType,
6875
final @Nullable String fileName,
6976
final @Nullable String attachmentType) {
77+
this(type, getLength, contentType, fileName, attachmentType, null);
78+
}
79+
80+
SentryEnvelopeItemHeader(
81+
final @NotNull SentryItemType type,
82+
final @Nullable Callable<Integer> getLength,
83+
final @Nullable String contentType,
84+
final @Nullable String fileName,
85+
final @Nullable String attachmentType,
86+
final @Nullable String platform) {
7087
this.type = Objects.requireNonNull(type, "type is required");
7188
this.contentType = contentType;
7289
this.length = -1;
7390
this.fileName = fileName;
7491
this.getLength = getLength;
7592
this.attachmentType = attachmentType;
93+
this.platform = platform;
7694
}
7795

7896
SentryEnvelopeItemHeader(
@@ -100,6 +118,7 @@ public static final class JsonKeys {
100118
public static final String TYPE = "type";
101119
public static final String ATTACHMENT_TYPE = "attachment_type";
102120
public static final String LENGTH = "length";
121+
public static final String PLATFORM = "platform";
103122
}
104123

105124
@Override
@@ -116,6 +135,9 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger
116135
if (attachmentType != null) {
117136
writer.name(JsonKeys.ATTACHMENT_TYPE).value(attachmentType);
118137
}
138+
if (platform != null) {
139+
writer.name(JsonKeys.PLATFORM).value(platform);
140+
}
119141
writer.name(JsonKeys.LENGTH).value(getLength());
120142
if (unknown != null) {
121143
for (String key : unknown.keySet()) {
@@ -138,6 +160,7 @@ public static final class Deserializer implements JsonDeserializer<SentryEnvelop
138160
SentryItemType type = null;
139161
int length = 0;
140162
String attachmentType = null;
163+
String platform = null;
141164
Map<String, Object> unknown = null;
142165

143166
while (reader.peek() == JsonToken.NAME) {
@@ -158,6 +181,9 @@ public static final class Deserializer implements JsonDeserializer<SentryEnvelop
158181
case JsonKeys.ATTACHMENT_TYPE:
159182
attachmentType = reader.nextStringOrNull();
160183
break;
184+
case JsonKeys.PLATFORM:
185+
platform = reader.nextStringOrNull();
186+
break;
161187
default:
162188
if (unknown == null) {
163189
unknown = new HashMap<>();
@@ -170,7 +196,8 @@ public static final class Deserializer implements JsonDeserializer<SentryEnvelop
170196
throw missingRequiredFieldException(JsonKeys.TYPE, logger);
171197
}
172198
SentryEnvelopeItemHeader sentryEnvelopeItemHeader =
173-
new SentryEnvelopeItemHeader(type, length, contentType, fileName, attachmentType);
199+
new SentryEnvelopeItemHeader(
200+
type, length, contentType, fileName, attachmentType, platform);
174201
sentryEnvelopeItemHeader.setUnknown(unknown);
175202
reader.endObject();
176203
return sentryEnvelopeItemHeader;

sentry/src/test/java/io/sentry/SentryEnvelopeItemTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,17 @@ class SentryEnvelopeItemTest {
462462
)
463463
}
464464

465+
@Test
466+
fun `fromProfileChunk sets platform header`() {
467+
val file = File(fixture.pathname)
468+
val profileChunk = mock<ProfileChunk> {
469+
whenever(it.traceFile).thenReturn(file)
470+
}
471+
472+
val chunk = SentryEnvelopeItem.fromProfileChunk(profileChunk, mock())
473+
assertEquals("android", chunk.header.platform)
474+
}
475+
465476
@Test
466477
fun `fromProfileChunk saves file as Base64`() {
467478
val file = File(fixture.pathname)

sentry/src/test/java/io/sentry/protocol/SentryEnvelopeItemHeaderSerializationTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class SentryEnvelopeItemHeaderSerializationTest {
2323
345,
2424
"5def420f-3dac-4d7b-948b-49de6e551aef",
2525
"54cf4644-8610-4ff3-a535-34ac1f367501",
26-
"6f49ad85-a017-4d94-a5d7-6477251da602"
26+
"6f49ad85-a017-4d94-a5d7-6477251da602",
27+
"android"
2728
)
2829
}
2930
private val fixture = Fixture()

sentry/src/test/resources/json/sentry_envelope_item_header.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"filename": "54cf4644-8610-4ff3-a535-34ac1f367501",
44
"type": "event",
55
"attachment_type": "6f49ad85-a017-4d94-a5d7-6477251da602",
6+
"platform": "android",
67
"length": 345
78
}

0 commit comments

Comments
 (0)