Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for feedback envelope header item type #3687

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <init> ()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;
Expand Down
3 changes: 2 additions & 1 deletion sentry/src/main/java/io/sentry/SentryItemType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger
writer.value(itemType);
}

static final class Deserializer implements JsonDeserializer<SentryItemType> {
public static final class Deserializer implements JsonDeserializer<SentryItemType> {
denrase marked this conversation as resolved.
Show resolved Hide resolved

@Override
public @NotNull SentryItemType deserialize(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ILogger>()
}
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)
}
}
Loading