Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -2762,11 +2762,12 @@ public final class io/sentry/SentryEnvelopeItem {
}

public final class io/sentry/SentryEnvelopeItemHeader : io/sentry/JsonSerializable, io/sentry/JsonUnknown {
public fun <init> (Lio/sentry/SentryItemType;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public fun <init> (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
Expand All @@ -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 <init> ()V
}
Expand Down
4 changes: 3 additions & 1 deletion sentry/src/main/java/io/sentry/SentryEnvelopeItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ private static void ensureAttachmentSizeLimit(
SentryItemType.ProfileChunk,
() -> cachedItem.getBytes().length,
"application-json",
traceFile.getName());
traceFile.getName(),
null,
"android");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if/how hybrid SDKs are using this, but should this always be "android"?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The platform in the chunk item-type header should always match the platform in the chunk item-type payload.

So maybe instead of hard coding android, using profileChunk.getPlatform() could be better ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markushi i did it this way so the other item headers are not changed. Also, the same code creates and sends the envelopes of the jvm world, so it cannot be set always to "android"
Regarding hybrid, we will see, but they shouldn't use our captureProfileChunk method, so it should be fine
@viglia 👍


// avoid method refs on Android due to some issues with older AGP setups
// noinspection Convert2MethodRef
Expand Down
31 changes: 29 additions & 2 deletions sentry/src/main/java/io/sentry/SentryEnvelopeItemHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> getLength;
Expand Down Expand Up @@ -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(
Expand All @@ -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<Integer> 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(
Expand Down Expand Up @@ -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
Expand All @@ -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()) {
Expand All @@ -138,6 +160,7 @@ public static final class Deserializer implements JsonDeserializer<SentryEnvelop
SentryItemType type = null;
int length = 0;
String attachmentType = null;
String platform = null;
Map<String, Object> unknown = null;

while (reader.peek() == JsonToken.NAME) {
Expand All @@ -158,6 +181,9 @@ public static final class Deserializer implements JsonDeserializer<SentryEnvelop
case JsonKeys.ATTACHMENT_TYPE:
attachmentType = reader.nextStringOrNull();
break;
case JsonKeys.PLATFORM:
platform = reader.nextStringOrNull();
break;
default:
if (unknown == null) {
unknown = new HashMap<>();
Expand All @@ -170,7 +196,8 @@ public static final class Deserializer implements JsonDeserializer<SentryEnvelop
throw missingRequiredFieldException(JsonKeys.TYPE, logger);
}
SentryEnvelopeItemHeader sentryEnvelopeItemHeader =
new SentryEnvelopeItemHeader(type, length, contentType, fileName, attachmentType);
new SentryEnvelopeItemHeader(
type, length, contentType, fileName, attachmentType, platform);
sentryEnvelopeItemHeader.setUnknown(unknown);
reader.endObject();
return sentryEnvelopeItemHeader;
Expand Down
11 changes: 11 additions & 0 deletions sentry/src/test/java/io/sentry/SentryEnvelopeItemTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,17 @@ class SentryEnvelopeItemTest {
)
}

@Test
fun `fromProfileChunk sets platform header`() {
val file = File(fixture.pathname)
val profileChunk = mock<ProfileChunk> {
whenever(it.traceFile).thenReturn(file)
}

val chunk = SentryEnvelopeItem.fromProfileChunk(profileChunk, mock())
assertEquals("android", chunk.header.platform)
}

@Test
fun `fromProfileChunk saves file as Base64`() {
val file = File(fixture.pathname)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"filename": "54cf4644-8610-4ff3-a535-34ac1f367501",
"type": "event",
"attachment_type": "6f49ad85-a017-4d94-a5d7-6477251da602",
"platform": "android",
"length": 345
}
Loading