From 61c8d80abb339b6ed87466e712d5a8d06aa97fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Andra=C5=A1ec?= Date: Tue, 17 Sep 2024 11:44:51 +0200 Subject: [PATCH] Add support for `feedback` envelope header item type (#3687) --- CHANGELOG.md | 4 + sentry/api/sentry.api | 7 ++ .../main/java/io/sentry/SentryItemType.java | 3 +- .../SentryItemTypeSerializationTest.kt | 74 +++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 sentry/src/test/java/io/sentry/protocol/SentryItemTypeSerializationTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 2835d1525b..4bf79a0739 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Features + +- Add support for `feedback` envelope header item type ([#3687](https://github.com/getsentry/sentry-java/pull/3687)) + ### Fixes - Avoid stopping appStartProfiler after application creation ([#3630](https://github.com/getsentry/sentry-java/pull/3630)) diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index e53d175081..3cf11a434d 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -2247,6 +2247,7 @@ public final class io/sentry/SentryItemType : java/lang/Enum, io/sentry/JsonSeri public static final field CheckIn Lio/sentry/SentryItemType; public static final field ClientReport Lio/sentry/SentryItemType; public static final field Event Lio/sentry/SentryItemType; + public static final field Feedback Lio/sentry/SentryItemType; public static final field Profile Lio/sentry/SentryItemType; public static final field ReplayEvent Lio/sentry/SentryItemType; public static final field ReplayRecording Lio/sentry/SentryItemType; @@ -2264,6 +2265,12 @@ public final class io/sentry/SentryItemType : java/lang/Enum, io/sentry/JsonSeri public static fun values ()[Lio/sentry/SentryItemType; } +public final class io/sentry/SentryItemType$Deserializer : io/sentry/JsonDeserializer { + public fun ()V + public fun deserialize (Lio/sentry/ObjectReader;Lio/sentry/ILogger;)Lio/sentry/SentryItemType; + public synthetic fun deserialize (Lio/sentry/ObjectReader;Lio/sentry/ILogger;)Ljava/lang/Object; +} + public final class io/sentry/SentryLevel : java/lang/Enum, io/sentry/JsonSerializable { public static final field DEBUG Lio/sentry/SentryLevel; public static final field ERROR Lio/sentry/SentryLevel; diff --git a/sentry/src/main/java/io/sentry/SentryItemType.java b/sentry/src/main/java/io/sentry/SentryItemType.java index f37b972454..128b0888ba 100644 --- a/sentry/src/main/java/io/sentry/SentryItemType.java +++ b/sentry/src/main/java/io/sentry/SentryItemType.java @@ -21,6 +21,7 @@ public enum SentryItemType implements JsonSerializable { ReplayVideo("replay_video"), CheckIn("check_in"), Statsd("statsd"), + Feedback("feedback"), Unknown("__unknown__"); // DataCategory.Unknown private final String itemType; @@ -62,7 +63,7 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger writer.value(itemType); } - static final class Deserializer implements JsonDeserializer { + public static final class Deserializer implements JsonDeserializer { @Override public @NotNull SentryItemType deserialize( diff --git a/sentry/src/test/java/io/sentry/protocol/SentryItemTypeSerializationTest.kt b/sentry/src/test/java/io/sentry/protocol/SentryItemTypeSerializationTest.kt new file mode 100644 index 0000000000..c50a12b80d --- /dev/null +++ b/sentry/src/test/java/io/sentry/protocol/SentryItemTypeSerializationTest.kt @@ -0,0 +1,74 @@ +package io.sentry.protocol + +import io.sentry.ILogger +import io.sentry.JsonObjectReader +import io.sentry.JsonObjectWriter +import io.sentry.SentryItemType +import org.junit.Test +import org.mockito.kotlin.mock +import java.io.StringReader +import java.io.StringWriter +import kotlin.test.assertEquals + +class SentryItemTypeSerializationTest { + + class Fixture { + val logger = mock() + } + private val fixture = Fixture() + + @Test + fun serialize() { + assertEquals(serialize(SentryItemType.Session), json("session")) + assertEquals(serialize(SentryItemType.Event), json("event")) + assertEquals(serialize(SentryItemType.UserFeedback), json("user_report")) + assertEquals(serialize(SentryItemType.Attachment), json("attachment")) + assertEquals(serialize(SentryItemType.Transaction), json("transaction")) + assertEquals(serialize(SentryItemType.Profile), json("profile")) + assertEquals(serialize(SentryItemType.ClientReport), json("client_report")) + assertEquals(serialize(SentryItemType.ReplayEvent), json("replay_event")) + assertEquals(serialize(SentryItemType.ReplayRecording), json("replay_recording")) + assertEquals(serialize(SentryItemType.ReplayVideo), json("replay_video")) + assertEquals(serialize(SentryItemType.CheckIn), json("check_in")) + assertEquals(serialize(SentryItemType.Statsd), json("statsd")) + assertEquals(serialize(SentryItemType.Feedback), json("feedback")) + } + + @Test + fun deserialize() { + assertEquals(deserialize(json("session")), SentryItemType.Session) + assertEquals(deserialize(json("event")), SentryItemType.Event) + assertEquals(deserialize(json("user_report")), SentryItemType.UserFeedback) + assertEquals(deserialize(json("attachment")), SentryItemType.Attachment) + assertEquals(deserialize(json("transaction")), SentryItemType.Transaction) + assertEquals(deserialize(json("profile")), SentryItemType.Profile) + assertEquals(deserialize(json("client_report")), SentryItemType.ClientReport) + assertEquals(deserialize(json("replay_event")), SentryItemType.ReplayEvent) + assertEquals(deserialize(json("replay_recording")), SentryItemType.ReplayRecording) + assertEquals(deserialize(json("replay_video")), SentryItemType.ReplayVideo) + assertEquals(deserialize(json("check_in")), SentryItemType.CheckIn) + assertEquals(deserialize(json("statsd")), SentryItemType.Statsd) + assertEquals(deserialize(json("feedback")), SentryItemType.Feedback) + } + + private fun json(type: String): String { + return "{\"type\":\"${type}\"}" + } + + private fun serialize(src: SentryItemType): String { + val wrt = StringWriter() + val jsonWrt = JsonObjectWriter(wrt, 100) + jsonWrt.beginObject() + jsonWrt.name("type") + src.serialize(jsonWrt, fixture.logger) + jsonWrt.endObject() + return wrt.toString() + } + + private fun deserialize(json: String): SentryItemType { + val reader = JsonObjectReader(StringReader(json)) + reader.beginObject() + reader.nextName() + return SentryItemType.Deserializer().deserialize(reader, fixture.logger) + } +}