Skip to content

Commit f13c41f

Browse files
authored
Merge 7a58bce into d217708
2 parents d217708 + 7a58bce commit f13c41f

File tree

16 files changed

+261
-4
lines changed

16 files changed

+261
-4
lines changed

CHANGELOG.md

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

55
### Features
66

7+
- Add session replay id to Sentry Logs ([#4740](https://github.com/getsentry/sentry-java/pull/4740))
78
- Move SentryLogs out of experimental ([#4710](https://github.com/getsentry/sentry-java/pull/4710))
89
- Add support for w3c traceparent header ([#4671](https://github.com/getsentry/sentry-java/pull/4671))
910
- This feature is disabled by default. If enabled, outgoing requests will include the w3c `traceparent` header.

sentry-android-core/src/main/java/io/sentry/android/core/AndroidContinuousProfiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ private void start() {
208208

209209
isRunning = true;
210210

211-
if (profilerId == SentryId.EMPTY_ID) {
211+
if (profilerId.equals(SentryId.EMPTY_ID)) {
212212
profilerId = new SentryId();
213213
}
214214

215-
if (chunkId == SentryId.EMPTY_ID) {
215+
if (chunkId.equals(SentryId.EMPTY_ID)) {
216216
chunkId = new SentryId();
217217
}
218218

sentry-android-replay/src/main/java/io/sentry/android/replay/capture/BufferCaptureStrategy.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import io.sentry.SentryLevel.ERROR
1010
import io.sentry.SentryLevel.INFO
1111
import io.sentry.SentryOptions
1212
import io.sentry.SentryReplayEvent.ReplayType.BUFFER
13+
import io.sentry.SentryReplayEvent.ReplayType.SESSION
1314
import io.sentry.android.replay.ReplayCache
1415
import io.sentry.android.replay.ScreenshotRecorderConfig
1516
import io.sentry.android.replay.capture.CaptureStrategy.Companion.rotateEvents
@@ -82,7 +83,10 @@ internal class BufferCaptureStrategy(
8283

8384
// write replayId to scope right away, so it gets picked up by the event that caused buffer
8485
// to flush
85-
scopes?.configureScope { it.replayId = currentReplayId }
86+
scopes?.configureScope {
87+
it.replayId = currentReplayId
88+
it.replayType = replayType
89+
}
8690

8791
if (isTerminating) {
8892
this.isTerminating.set(true)
@@ -152,6 +156,8 @@ internal class BufferCaptureStrategy(
152156
replayId = currentReplayId,
153157
replayType = BUFFER,
154158
)
159+
// The type on the scope should change, as logs read it
160+
scopes?.configureScope { it.replayType = SESSION }
155161
return captureStrategy
156162
}
157163

sentry-android-replay/src/main/java/io/sentry/android/replay/capture/SessionCaptureStrategy.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ internal class SessionCaptureStrategy(
3333
// tagged with the replay that might never be sent when we're recording in buffer mode
3434
scopes?.configureScope {
3535
it.replayId = currentReplayId
36+
it.replayType = this.replayType
3637
screenAtStart = it.screen?.substringAfterLast('.')
3738
}
3839
}
@@ -57,7 +58,10 @@ internal class SessionCaptureStrategy(
5758
currentSegment = -1
5859
FileUtils.deleteRecursively(replayCacheDir)
5960
}
60-
scopes?.configureScope { it.replayId = SentryId.EMPTY_ID }
61+
scopes?.configureScope {
62+
it.replayId = SentryId.EMPTY_ID
63+
it.replayType = null
64+
}
6165
super.stop()
6266
}
6367

sentry-android-replay/src/test/java/io/sentry/android/replay/capture/BufferCaptureStrategyTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import java.io.File
2525
import kotlin.test.Test
2626
import kotlin.test.assertEquals
2727
import kotlin.test.assertFalse
28+
import kotlin.test.assertNull
2829
import kotlin.test.assertTrue
2930
import org.awaitility.kotlin.await
3031
import org.junit.Rule
@@ -139,6 +140,8 @@ class BufferCaptureStrategyTest {
139140
assertEquals(SentryId.EMPTY_ID, fixture.scope.replayId)
140141
assertEquals(replayId, strategy.currentReplayId)
141142
assertEquals(0, strategy.currentSegment)
143+
assertNull(fixture.scope.replayType)
144+
assertEquals(ReplayType.BUFFER, strategy.replayType)
142145
}
143146

144147
@Test
@@ -239,10 +242,15 @@ class BufferCaptureStrategyTest {
239242
fun `convert converts to session strategy and sets replayId to scope`() {
240243
val strategy = fixture.getSut()
241244
strategy.start()
245+
assertNull(fixture.scope.replayType)
246+
assertEquals(ReplayType.BUFFER, strategy.replayType)
242247

243248
val converted = strategy.convert()
244249
assertTrue(converted is SessionCaptureStrategy)
245250
assertEquals(strategy.currentReplayId, fixture.scope.replayId)
251+
// Type of strategy is kept buffer, but type on the scope is updated to session
252+
assertEquals(ReplayType.BUFFER, strategy.replayType)
253+
assertEquals(ReplayType.SESSION, fixture.scope.replayType)
246254
}
247255

248256
@Test
@@ -330,6 +338,7 @@ class BufferCaptureStrategyTest {
330338
strategy.captureReplay(false) {}
331339

332340
assertEquals(SentryId.EMPTY_ID, fixture.scope.replayId)
341+
assertNull(fixture.scope.replayType)
333342
}
334343

335344
@Test
@@ -346,6 +355,7 @@ class BufferCaptureStrategyTest {
346355
// buffered + current = 2
347356
verify(fixture.scopes, times(2)).captureReplay(any(), any())
348357
assertEquals(strategy.currentReplayId, fixture.scope.replayId)
358+
assertEquals(ReplayType.BUFFER, fixture.scope.replayType)
349359
assertTrue(called)
350360
}
351361

sentry-android-replay/src/test/java/io/sentry/android/replay/capture/SessionCaptureStrategyTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ class SessionCaptureStrategyTest {
139139

140140
assertEquals(replayId, fixture.scope.replayId)
141141
assertEquals(replayId, strategy.currentReplayId)
142+
assertEquals(ReplayType.SESSION, fixture.scope.replayType)
143+
assertEquals(ReplayType.SESSION, strategy.replayType)
142144
assertEquals(0, strategy.currentSegment)
143145
}
144146

@@ -200,6 +202,8 @@ class SessionCaptureStrategyTest {
200202
.captureReplay(argThat { event -> event is SentryReplayEvent && event.segmentId == 0 }, any())
201203
assertEquals(SentryId.EMPTY_ID, fixture.scope.replayId)
202204
assertEquals(SentryId.EMPTY_ID, strategy.currentReplayId)
205+
assertNull(fixture.scope.replayType)
206+
assertEquals(ReplayType.SESSION, strategy.replayType)
203207
assertEquals(-1, strategy.currentSegment)
204208
assertFalse(currentReplay.exists())
205209
verify(fixture.replayCache).close()

sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/MainActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.sentry.ISpan;
1212
import io.sentry.MeasurementUnit;
1313
import io.sentry.Sentry;
14+
import io.sentry.SentryLogLevel;
1415
import io.sentry.instrumentation.file.SentryFileOutputStream;
1516
import io.sentry.protocol.Feedback;
1617
import io.sentry.protocol.User;
@@ -304,7 +305,10 @@ public void run() {
304305
Sentry.replay().enableDebugMaskingOverlay();
305306
});
306307

308+
Sentry.logger().log(SentryLogLevel.INFO, "Creating content view");
307309
setContentView(binding.getRoot());
310+
311+
Sentry.logger().log(SentryLogLevel.INFO, "MainActivity created");
308312
}
309313

310314
private void stackOverflow() {

sentry/api/sentry.api

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ public final class io/sentry/CombinedScopeView : io/sentry/IScope {
285285
public fun getOptions ()Lio/sentry/SentryOptions;
286286
public fun getPropagationContext ()Lio/sentry/PropagationContext;
287287
public fun getReplayId ()Lio/sentry/protocol/SentryId;
288+
public fun getReplayType ()Lio/sentry/SentryReplayEvent$ReplayType;
288289
public fun getRequest ()Lio/sentry/protocol/Request;
289290
public fun getScreen ()Ljava/lang/String;
290291
public fun getSession ()Lio/sentry/Session;
@@ -311,6 +312,7 @@ public final class io/sentry/CombinedScopeView : io/sentry/IScope {
311312
public fun setLevel (Lio/sentry/SentryLevel;)V
312313
public fun setPropagationContext (Lio/sentry/PropagationContext;)V
313314
public fun setReplayId (Lio/sentry/protocol/SentryId;)V
315+
public fun setReplayType (Lio/sentry/SentryReplayEvent$ReplayType;)V
314316
public fun setRequest (Lio/sentry/protocol/Request;)V
315317
public fun setScreen (Ljava/lang/String;)V
316318
public fun setSpanContext (Ljava/lang/Throwable;Lio/sentry/ISpan;Ljava/lang/String;)V
@@ -851,6 +853,7 @@ public abstract interface class io/sentry/IScope {
851853
public abstract fun getOptions ()Lio/sentry/SentryOptions;
852854
public abstract fun getPropagationContext ()Lio/sentry/PropagationContext;
853855
public abstract fun getReplayId ()Lio/sentry/protocol/SentryId;
856+
public abstract fun getReplayType ()Lio/sentry/SentryReplayEvent$ReplayType;
854857
public abstract fun getRequest ()Lio/sentry/protocol/Request;
855858
public abstract fun getScreen ()Ljava/lang/String;
856859
public abstract fun getSession ()Lio/sentry/Session;
@@ -877,6 +880,7 @@ public abstract interface class io/sentry/IScope {
877880
public abstract fun setLevel (Lio/sentry/SentryLevel;)V
878881
public abstract fun setPropagationContext (Lio/sentry/PropagationContext;)V
879882
public abstract fun setReplayId (Lio/sentry/protocol/SentryId;)V
883+
public abstract fun setReplayType (Lio/sentry/SentryReplayEvent$ReplayType;)V
880884
public abstract fun setRequest (Lio/sentry/protocol/Request;)V
881885
public abstract fun setScreen (Ljava/lang/String;)V
882886
public abstract fun setSpanContext (Ljava/lang/Throwable;Lio/sentry/ISpan;Ljava/lang/String;)V
@@ -1619,6 +1623,7 @@ public final class io/sentry/NoOpScope : io/sentry/IScope {
16191623
public fun getOptions ()Lio/sentry/SentryOptions;
16201624
public fun getPropagationContext ()Lio/sentry/PropagationContext;
16211625
public fun getReplayId ()Lio/sentry/protocol/SentryId;
1626+
public fun getReplayType ()Lio/sentry/SentryReplayEvent$ReplayType;
16221627
public fun getRequest ()Lio/sentry/protocol/Request;
16231628
public fun getScreen ()Ljava/lang/String;
16241629
public fun getSession ()Lio/sentry/Session;
@@ -1645,6 +1650,7 @@ public final class io/sentry/NoOpScope : io/sentry/IScope {
16451650
public fun setLevel (Lio/sentry/SentryLevel;)V
16461651
public fun setPropagationContext (Lio/sentry/PropagationContext;)V
16471652
public fun setReplayId (Lio/sentry/protocol/SentryId;)V
1653+
public fun setReplayType (Lio/sentry/SentryReplayEvent$ReplayType;)V
16481654
public fun setRequest (Lio/sentry/protocol/Request;)V
16491655
public fun setScreen (Ljava/lang/String;)V
16501656
public fun setSpanContext (Ljava/lang/Throwable;Lio/sentry/ISpan;Ljava/lang/String;)V
@@ -2272,6 +2278,7 @@ public final class io/sentry/Scope : io/sentry/IScope {
22722278
public fun getOptions ()Lio/sentry/SentryOptions;
22732279
public fun getPropagationContext ()Lio/sentry/PropagationContext;
22742280
public fun getReplayId ()Lio/sentry/protocol/SentryId;
2281+
public fun getReplayType ()Lio/sentry/SentryReplayEvent$ReplayType;
22752282
public fun getRequest ()Lio/sentry/protocol/Request;
22762283
public fun getScreen ()Ljava/lang/String;
22772284
public fun getSession ()Lio/sentry/Session;
@@ -2298,6 +2305,7 @@ public final class io/sentry/Scope : io/sentry/IScope {
22982305
public fun setLevel (Lio/sentry/SentryLevel;)V
22992306
public fun setPropagationContext (Lio/sentry/PropagationContext;)V
23002307
public fun setReplayId (Lio/sentry/protocol/SentryId;)V
2308+
public fun setReplayType (Lio/sentry/SentryReplayEvent$ReplayType;)V
23012309
public fun setRequest (Lio/sentry/protocol/Request;)V
23022310
public fun setScreen (Ljava/lang/String;)V
23032311
public fun setSpanContext (Ljava/lang/Throwable;Lio/sentry/ISpan;Ljava/lang/String;)V

sentry/src/main/java/io/sentry/CombinedScopeView.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,4 +507,22 @@ public void replaceOptions(@NotNull SentryOptions options) {
507507
public void setReplayId(@NotNull SentryId replayId) {
508508
getDefaultWriteScope().setReplayId(replayId);
509509
}
510+
511+
@Override
512+
public @Nullable SentryReplayEvent.ReplayType getReplayType() {
513+
final @Nullable SentryReplayEvent.ReplayType current = scope.getReplayType();
514+
if (current != null) {
515+
return current;
516+
}
517+
final @Nullable SentryReplayEvent.ReplayType isolation = isolationScope.getReplayType();
518+
if (isolation != null) {
519+
return isolation;
520+
}
521+
return globalScope.getReplayType();
522+
}
523+
524+
@Override
525+
public void setReplayType(final @Nullable SentryReplayEvent.ReplayType replayType) {
526+
getDefaultWriteScope().setReplayType(replayType);
527+
}
510528
}

sentry/src/main/java/io/sentry/IScope.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ public interface IScope {
106106
@ApiStatus.Internal
107107
void setReplayId(final @NotNull SentryId replayId);
108108

109+
/**
110+
* Returns the Scope's current replayType, previously set by {@link
111+
* IScope#setReplayType(SentryReplayEvent.ReplayType)}
112+
*
113+
* @return the type of the current session replay
114+
*/
115+
@ApiStatus.Internal
116+
@Nullable
117+
SentryReplayEvent.ReplayType getReplayType();
118+
119+
/**
120+
* Sets the Scope's current replayType
121+
*
122+
* @param replayType the type of the current session replay
123+
*/
124+
@ApiStatus.Internal
125+
void setReplayType(final @Nullable SentryReplayEvent.ReplayType replayType);
126+
109127
/**
110128
* Returns the Scope's request
111129
*

0 commit comments

Comments
 (0)