Skip to content

Commit e56c1d1

Browse files
authored
Serialize preContext and postContext in SentryStackFrame (#4482)
1 parent 4152701 commit e56c1d1

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
SentryUserFeedbackDialog.Builder(context).create().show()
2020
```
21+
- Serialize `preContext` and `postContext` in `SentryStackFrame` ([#4482](https://github.com/getsentry/sentry-java/pull/4482))
2122

2223
## 8.13.3
2324

sentry/api/sentry.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5903,6 +5903,8 @@ public final class io/sentry/protocol/SentryStackFrame$JsonKeys {
59035903
public static final field NATIVE Ljava/lang/String;
59045904
public static final field PACKAGE Ljava/lang/String;
59055905
public static final field PLATFORM Ljava/lang/String;
5906+
public static final field POST_CONTEXT Ljava/lang/String;
5907+
public static final field PRE_CONTEXT Ljava/lang/String;
59065908
public static final field RAW_FUNCTION Ljava/lang/String;
59075909
public static final field SYMBOL Ljava/lang/String;
59085910
public static final field SYMBOL_ADDR Ljava/lang/String;

sentry/src/main/java/io/sentry/protocol/SentryStackFrame.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ public static final class JsonKeys {
351351
public static final String RAW_FUNCTION = "raw_function";
352352
public static final String SYMBOL = "symbol";
353353
public static final String LOCK = "lock";
354+
public static final String PRE_CONTEXT = "pre_context";
355+
public static final String POST_CONTEXT = "post_context";
354356
}
355357

356358
@Override
@@ -411,6 +413,12 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger
411413
if (lock != null) {
412414
writer.name(JsonKeys.LOCK).value(logger, lock);
413415
}
416+
if (preContext != null && !preContext.isEmpty()) {
417+
writer.name(JsonKeys.PRE_CONTEXT).value(logger, preContext);
418+
}
419+
if (postContext != null && !postContext.isEmpty()) {
420+
writer.name(JsonKeys.POST_CONTEXT).value(logger, postContext);
421+
}
414422
if (unknown != null) {
415423
for (String key : unknown.keySet()) {
416424
Object value = unknown.get(key);
@@ -421,6 +429,7 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger
421429
writer.endObject();
422430
}
423431

432+
@SuppressWarnings("unchecked")
424433
public static final class Deserializer implements JsonDeserializer<SentryStackFrame> {
425434
@Override
426435
public @NotNull SentryStackFrame deserialize(
@@ -485,6 +494,12 @@ public static final class Deserializer implements JsonDeserializer<SentryStackFr
485494
case JsonKeys.LOCK:
486495
sentryStackFrame.lock = reader.nextOrNull(logger, new SentryLockReason.Deserializer());
487496
break;
497+
case JsonKeys.PRE_CONTEXT:
498+
sentryStackFrame.preContext = (List<String>) reader.nextObjectOrNull();
499+
break;
500+
case JsonKeys.POST_CONTEXT:
501+
sentryStackFrame.postContext = (List<String>) reader.nextObjectOrNull();
502+
break;
488503
default:
489504
if (unknown == null) {
490505
unknown = new ConcurrentHashMap<>();

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ class SentryStackFrameSerializationTest {
4242
type = SentryLockReason.BLOCKED
4343
threadId = 11
4444
}
45+
preContext = listOf<String>(
46+
"f46ad4c7-a286-4936-a56c-825088227c88",
47+
"feeda7f3-1530-45c2-b8d8-5d201aaf6ce0"
48+
)
49+
postContext = listOf<String>(
50+
"2153c99d-2f17-45f1-a173-69e08cc6a219",
51+
"0a959b53-6bdf-45d1-93ca-936281d7897a",
52+
"4e6085a3-1e44-4aa2-b3d9-9b79dca970ed"
53+
)
4554
}
4655
}
4756
private val fixture = Fixture()

sentry/src/test/resources/json/sentry_stack_frame.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,14 @@
2222
"package_name": "java.lang",
2323
"class_name": "Object",
2424
"thread_id": 11
25-
}
25+
},
26+
"pre_context": [
27+
"f46ad4c7-a286-4936-a56c-825088227c88",
28+
"feeda7f3-1530-45c2-b8d8-5d201aaf6ce0"
29+
],
30+
"post_context": [
31+
"2153c99d-2f17-45f1-a173-69e08cc6a219",
32+
"0a959b53-6bdf-45d1-93ca-936281d7897a",
33+
"4e6085a3-1e44-4aa2-b3d9-9b79dca970ed"
34+
]
2635
}

0 commit comments

Comments
 (0)