Skip to content

Commit

Permalink
Merge pull request #3214 from getsentry/rz/feat/session-replay-envelopes
Browse files Browse the repository at this point in the history
[SR] Add session replay envelope and events
  • Loading branch information
romtsn committed Mar 4, 2024
2 parents 64f70c5 + fb14ecb commit 79151e9
Show file tree
Hide file tree
Showing 101 changed files with 3,833 additions and 303 deletions.
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

0 comments on commit 79151e9

Please sign in to comment.