Skip to content

Serialize preContext and postContext in SentryStackFrame #4482

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

Merged
merged 4 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -5848,6 +5848,8 @@ public final class io/sentry/protocol/SentryStackFrame$JsonKeys {
public static final field NATIVE Ljava/lang/String;
public static final field PACKAGE Ljava/lang/String;
public static final field PLATFORM Ljava/lang/String;
public static final field POST_CONTEXT Ljava/lang/String;
public static final field PRE_CONTEXT Ljava/lang/String;
public static final field RAW_FUNCTION Ljava/lang/String;
public static final field SYMBOL Ljava/lang/String;
public static final field SYMBOL_ADDR Ljava/lang/String;
Expand Down
15 changes: 15 additions & 0 deletions sentry/src/main/java/io/sentry/protocol/SentryStackFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ public static final class JsonKeys {
public static final String RAW_FUNCTION = "raw_function";
public static final String SYMBOL = "symbol";
public static final String LOCK = "lock";
public static final String PRE_CONTEXT = "pre_context";
public static final String POST_CONTEXT = "post_context";
}

@Override
Expand Down Expand Up @@ -411,6 +413,12 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger
if (lock != null) {
writer.name(JsonKeys.LOCK).value(logger, lock);
}
if (preContext != null && !preContext.isEmpty()) {
writer.name(JsonKeys.PRE_CONTEXT).value(logger, preContext);
}
if (postContext != null && !postContext.isEmpty()) {
writer.name(JsonKeys.POST_CONTEXT).value(logger, postContext);
}
if (unknown != null) {
for (String key : unknown.keySet()) {
Object value = unknown.get(key);
Expand All @@ -421,6 +429,7 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger
writer.endObject();
}

@SuppressWarnings("unchecked")
public static final class Deserializer implements JsonDeserializer<SentryStackFrame> {
@Override
public @NotNull SentryStackFrame deserialize(
Expand Down Expand Up @@ -485,6 +494,12 @@ public static final class Deserializer implements JsonDeserializer<SentryStackFr
case JsonKeys.LOCK:
sentryStackFrame.lock = reader.nextOrNull(logger, new SentryLockReason.Deserializer());
break;
case JsonKeys.PRE_CONTEXT:
sentryStackFrame.preContext = (List<String>) reader.nextObjectOrNull();
break;
case JsonKeys.POST_CONTEXT:
sentryStackFrame.postContext = (List<String>) reader.nextObjectOrNull();
break;
default:
if (unknown == null) {
unknown = new ConcurrentHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ class SentryStackFrameSerializationTest {
type = SentryLockReason.BLOCKED
threadId = 11
}
preContext = listOf<String>(
"f46ad4c7-a286-4936-a56c-825088227c88",
"feeda7f3-1530-45c2-b8d8-5d201aaf6ce0"
)
postContext = listOf<String>(
"2153c99d-2f17-45f1-a173-69e08cc6a219",
"0a959b53-6bdf-45d1-93ca-936281d7897a",
"4e6085a3-1e44-4aa2-b3d9-9b79dca970ed"
)
}
}
private val fixture = Fixture()
Expand Down
11 changes: 10 additions & 1 deletion sentry/src/test/resources/json/sentry_stack_frame.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,14 @@
"package_name": "java.lang",
"class_name": "Object",
"thread_id": 11
}
},
"pre_context": [
"f46ad4c7-a286-4936-a56c-825088227c88",
"feeda7f3-1530-45c2-b8d8-5d201aaf6ce0"
],
"post_context": [
"2153c99d-2f17-45f1-a173-69e08cc6a219",
"0a959b53-6bdf-45d1-93ca-936281d7897a",
"4e6085a3-1e44-4aa2-b3d9-9b79dca970ed"
]
}
Loading