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

[SR] Add session replay envelope and events #3214

Merged
merged 26 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b1ced85
Add sentry replay envelope and event
romtsn Feb 1, 2024
f8419d1
Merge branch 'rz/feat/session-replay-sources' into rz/feat/session-re…
romtsn Feb 13, 2024
a63cac1
WIP
romtsn Feb 15, 2024
fa72057
Add replay envelopes
romtsn Feb 19, 2024
6cfb511
Remove jsonValue
romtsn Feb 19, 2024
0d031d7
Remove
romtsn Feb 19, 2024
07e6b26
Fix json
romtsn Feb 19, 2024
18af924
Finalize replay envelopes
romtsn Feb 20, 2024
64cedfa
Introduce MapObjectReader
romtsn Feb 20, 2024
b8cb924
Add missing test
romtsn Feb 20, 2024
28d341f
Merge branch 'rz/feat/session-replay-envelopes' into rz/feat/session-…
romtsn Feb 20, 2024
1e76fc7
Add test for MapObjectReader
romtsn Feb 22, 2024
13c1971
Add MapObjectWriter change
romtsn Feb 22, 2024
a14e090
Merge branch 'rz/feat/session-replay-envelopes' into rz/feat/session-…
romtsn Feb 22, 2024
86baf7f
Add finals
romtsn Feb 22, 2024
f1ca9f6
Fix test
romtsn Feb 22, 2024
fbbe0d9
Fix test
romtsn Feb 22, 2024
688233f
Merge branch 'rz/feat/session-replay-envelopes' into rz/feat/session-…
romtsn Feb 22, 2024
fd63960
Address review
romtsn Feb 28, 2024
93785cc
Add finals and annotations
romtsn Feb 28, 2024
4db19e0
Merge pull request #3215 from getsentry/rz/feat/session-replay-map-ob…
romtsn Feb 28, 2024
62477b4
Remove public captureReplay method
romtsn Mar 1, 2024
af42fb3
Fix test
romtsn Mar 1, 2024
cd09739
Merge branch 'rz/feat/session-replay-sources' into rz/feat/session-re…
romtsn Mar 1, 2024
4e54c77
api dump
romtsn Mar 1, 2024
fb14ecb
Merge branch 'rz/feat/session-replay' into rz/feat/session-replay-env…
romtsn Mar 4, 2024
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
1 change: 1 addition & 0 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ object Config {
val jsonUnit = "net.javacrumbs.json-unit:json-unit:2.32.0"
val hsqldb = "org.hsqldb:hsqldb:2.6.1"
val javaFaker = "com.github.javafaker:javafaker:1.0.2"
val msgpack = "org.msgpack:msgpack-core:0.9.8"
}

object QualityPlugins {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.sentry.SentryBaseEvent;
import io.sentry.SentryEvent;
import io.sentry.SentryLevel;
import io.sentry.SentryReplayEvent;
import io.sentry.android.core.internal.util.AndroidMainThreadChecker;
import io.sentry.android.core.performance.AppStartMetrics;
import io.sentry.android.core.performance.TimeSpan;
Expand Down Expand Up @@ -256,4 +257,17 @@ private void setSideLoadedInfo(final @NotNull SentryBaseEvent event) {

return transaction;
}

@Override
public @NotNull SentryReplayEvent process(
final @NotNull SentryReplayEvent event, final @NotNull Hint hint) {
final boolean applyScopeData = shouldApplyScopeData(event, hint);
if (applyScopeData) {
processNonCachedEvent(event, hint);
}

setCommons(event, false, applyScopeData);

return event;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import io.sentry.Sentry
import io.sentry.SentryEnvelope
import io.sentry.SentryEvent
import io.sentry.SentryOptions
import io.sentry.SentryReplayEvent
import io.sentry.Session
import io.sentry.TraceContext
import io.sentry.UserFeedback
Expand Down Expand Up @@ -141,6 +142,14 @@ class SessionTrackingIntegrationTest {
TODO("Not yet implemented")
}

override fun captureReplayEvent(
event: SentryReplayEvent,
scope: IScope?,
hint: Hint?
): SentryId {
TODO("Not yet implemented")
}

override fun captureUserFeedback(userFeedback: UserFeedback) {
TODO("Not yet implemented")
}
Expand Down
553 changes: 444 additions & 109 deletions sentry/api/sentry.api

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sentry/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
testImplementation(Config.TestLibs.mockitoInline)
testImplementation(Config.TestLibs.awaitility)
testImplementation(Config.TestLibs.javaFaker)
testImplementation(Config.TestLibs.msgpack)
testImplementation(projects.sentryTestSupport)
}

Expand Down
7 changes: 3 additions & 4 deletions sentry/src/main/java/io/sentry/Breadcrumb.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public static Breadcrumb fromMap(
switch (entry.getKey()) {
case JsonKeys.TIMESTAMP:
if (value instanceof String) {
Date deserializedDate =
JsonObjectReader.dateOrNull((String) value, options.getLogger());
Date deserializedDate = ObjectReader.dateOrNull((String) value, options.getLogger());
if (deserializedDate != null) {
timestamp = deserializedDate;
}
Expand Down Expand Up @@ -700,8 +699,8 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger
public static final class Deserializer implements JsonDeserializer<Breadcrumb> {
@SuppressWarnings("unchecked")
@Override
public @NotNull Breadcrumb deserialize(
@NotNull JsonObjectReader reader, @NotNull ILogger logger) throws Exception {
public @NotNull Breadcrumb deserialize(@NotNull ObjectReader reader, @NotNull ILogger logger)
throws Exception {
reader.beginObject();
@NotNull Date timestamp = DateUtils.getCurrentDateTime();
String message = null;
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/CheckIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger

public static final class Deserializer implements JsonDeserializer<CheckIn> {
@Override
public @NotNull CheckIn deserialize(@NotNull JsonObjectReader reader, @NotNull ILogger logger)
public @NotNull CheckIn deserialize(@NotNull ObjectReader reader, @NotNull ILogger logger)
throws Exception {
SentryId sentryId = null;
MonitorConfig monitorConfig = null;
Expand Down
1 change: 1 addition & 0 deletions sentry/src/main/java/io/sentry/DataCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum DataCategory {
Monitor("monitor"),
Profile("profile"),
Transaction("transaction"),
Replay("replay"),
Security("security"),
UserReport("user_report"),
Unknown("unknown");
Expand Down
12 changes: 12 additions & 0 deletions sentry/src/main/java/io/sentry/EventProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,16 @@ default SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) {
default SentryTransaction process(@NotNull SentryTransaction transaction, @NotNull Hint hint) {
return transaction;
}

/**
* May mutate or drop a SentryEvent
*
* @param event the SentryEvent
* @param hint the Hint
* @return the event itself, a mutated SentryEvent or null
*/
@Nullable
default SentryReplayEvent process(@NotNull SentryReplayEvent event, @NotNull Hint hint) {
return event;
}
}
11 changes: 10 additions & 1 deletion sentry/src/main/java/io/sentry/Hint.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public final class Hint {
private final @NotNull List<Attachment> attachments = new ArrayList<>();
private @Nullable Attachment screenshot = null;
private @Nullable Attachment viewHierarchy = null;

private @Nullable Attachment threadDump = null;
private @Nullable ReplayRecording replayRecording = null;

public static @NotNull Hint withAttachment(@Nullable Attachment attachment) {
@NotNull final Hint hint = new Hint();
Expand Down Expand Up @@ -136,6 +136,15 @@ public void setThreadDump(final @Nullable Attachment threadDump) {
return threadDump;
}

@Nullable
public ReplayRecording getReplayRecording() {
return replayRecording;
}

public void setReplayRecording(final @Nullable ReplayRecording replayRecording) {
this.replayRecording = replayRecording;
}

private boolean isCastablePrimitive(@Nullable Object hintValue, @NotNull Class<?> clazz) {
Class<?> nonPrimitiveClass = PRIMITIVE_MAPPINGS.get(clazz.getCanonicalName());
return hintValue != null
Expand Down
22 changes: 22 additions & 0 deletions sentry/src/main/java/io/sentry/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,28 @@ private IScope buildLocalScope(
return sentryId;
}

@Override
public @NotNull SentryId captureReplay(
final @NotNull SentryReplayEvent replay, final @Nullable Hint hint) {
SentryId sentryId = SentryId.EMPTY_ID;
if (!isEnabled()) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"Instance is disabled and this 'captureReplay' call is a no-op.");
} else {
try {
final @NotNull StackItem item = stack.peek();
sentryId = item.getClient().captureReplayEvent(replay, item.getScope(), hint);
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Error while capturing replay", e);
}
}
this.lastEventId = sentryId;
return sentryId;
}

@ApiStatus.Internal
@Override
public @Nullable RateLimiter getRateLimiter() {
Expand Down
6 changes: 6 additions & 0 deletions sentry/src/main/java/io/sentry/HubAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ public void reportFullyDisplayed() {
return Sentry.captureCheckIn(checkIn);
}

@Override
public @NotNull SentryId captureReplay(
final @NotNull SentryReplayEvent replay, final @Nullable Hint hint) {
return Sentry.getCurrentHub().captureReplay(replay, hint);
}

@ApiStatus.Internal
@Override
public @Nullable RateLimiter getRateLimiter() {
Expand Down
3 changes: 3 additions & 0 deletions sentry/src/main/java/io/sentry/IHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,9 @@ TransactionContext continueTrace(
@NotNull
SentryId captureCheckIn(final @NotNull CheckIn checkIn);

@NotNull
SentryId captureReplay(@NotNull SentryReplayEvent replay, @Nullable Hint hint);

@ApiStatus.Internal
@Nullable
RateLimiter getRateLimiter();
Expand Down
4 changes: 4 additions & 0 deletions sentry/src/main/java/io/sentry/ISentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public interface ISentryClient {
return captureException(throwable, scope, null);
}

@NotNull
SentryId captureReplayEvent(
@NotNull SentryReplayEvent event, @Nullable IScope scope, @Nullable Hint hint);

/**
* Captures a manually created user feedback and sends it to Sentry.
*
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/JsonDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
@ApiStatus.Internal
public interface JsonDeserializer<T> {
@NotNull
T deserialize(@NotNull JsonObjectReader reader, @NotNull ILogger logger) throws Exception;
T deserialize(@NotNull ObjectReader reader, @NotNull ILogger logger) throws Exception;
}
Loading
Loading