Skip to content

Commit b2fef65

Browse files
authored
Merge branch 'main' into feat/otel-server-request-headers
2 parents 8bc3f0b + cde02ad commit b2fef65

File tree

6 files changed

+56
-7
lines changed

6 files changed

+56
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
- Added `enableTraceIdGeneration` to the AndroidOptions. This allows Hybrid SDKs to "freeze" and control the trace and connect errors on different layers of the application ([4188](https://github.com/getsentry/sentry-java/pull/4188))
1515
- Move to a single NetworkCallback listener to reduce number of IPC calls on Android ([#4164](https://github.com/getsentry/sentry-java/pull/4164))
1616
- Add GraphQL Apollo Kotlin 4 integration ([#4166](https://github.com/getsentry/sentry-java/pull/4166))
17+
- Add constructor to JUL `SentryHandler` for disabling external config ([#4208](https://github.com/getsentry/sentry-java/pull/4208))
1718

1819
### Fixes
1920

2021
- `SentryOptions.setTracePropagationTargets` is no longer marked internal ([#4170](https://github.com/getsentry/sentry-java/pull/4170))
22+
- Session Replay: Fix crash when a navigation breadcrumb does not have "to" destination ([#4185](https://github.com/getsentry/sentry-java/pull/4185))
23+
- Session Replay: Cap video segment duration to maximum 5 minutes to prevent endless video encoding in background ([#4185](https://github.com/getsentry/sentry-java/pull/4185))
2124
- Check `tracePropagationTargets` in OpenTelemetry propagator ([#4191](https://github.com/getsentry/sentry-java/pull/4191))
2225
- If a URL can be retrieved from OpenTelemetry span attributes, we check it against `tracePropagationTargets` before attaching `sentry-trace` and `baggage` headers to outgoing requests
2326
- If no URL can be retrieved we always attach the headers

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ internal interface CaptureStrategy {
5858
companion object {
5959
private const val BREADCRUMB_START_OFFSET = 100L
6060

61+
// 5 minutes, otherwise relay will just drop it. Can prevent the case where the device
62+
// time is wrong and the segment is too long.
63+
private const val MAX_SEGMENT_DURATION = 1000L * 60 * 5
64+
6165
fun createSegment(
6266
scopes: IScopes?,
6367
options: SentryOptions,
@@ -76,7 +80,7 @@ internal interface CaptureStrategy {
7680
events: Deque<RRWebEvent>
7781
): ReplaySegment {
7882
val generatedVideo = cache?.createVideoOf(
79-
duration,
83+
minOf(duration, MAX_SEGMENT_DURATION),
8084
currentSegmentTimestamp.time,
8185
segmentId,
8286
height,
@@ -179,7 +183,9 @@ internal interface CaptureStrategy {
179183
recordingPayload += rrwebEvent
180184

181185
// fill in the urls array from navigation breadcrumbs
182-
if ((rrwebEvent as? RRWebBreadcrumbEvent)?.category == "navigation") {
186+
if ((rrwebEvent as? RRWebBreadcrumbEvent)?.category == "navigation" &&
187+
rrwebEvent.data?.getOrElse("to", { null }) is String
188+
) {
183189
urls.add(rrwebEvent.data!!["to"] as String)
184190
}
185191
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,30 @@ class SessionCaptureStrategyTest {
336336
)
337337
}
338338

339+
@Test
340+
fun `does not throw when navigation destination is not a String`() {
341+
val now =
342+
System.currentTimeMillis() + (fixture.options.sessionReplay.sessionSegmentDuration * 5)
343+
val strategy = fixture.getSut(dateProvider = { now })
344+
strategy.start(fixture.recorderConfig)
345+
346+
fixture.scope.addBreadcrumb(Breadcrumb().apply { category = "navigation" })
347+
348+
strategy.onScreenshotRecorded(mock<Bitmap>()) {}
349+
350+
verify(fixture.scopes).captureReplay(
351+
check {
352+
assertNull(it.urls?.firstOrNull())
353+
},
354+
check {
355+
val breadcrumbEvents =
356+
it.replayRecording?.payload?.filterIsInstance<RRWebBreadcrumbEvent>()
357+
assertEquals("navigation", breadcrumbEvents?.first()?.category)
358+
assertNull(breadcrumbEvents?.first()?.data?.get("to"))
359+
}
360+
)
361+
}
362+
339363
@Test
340364
fun `sets screen from scope as replay url`() {
341365
fixture.scope.screen = "MainActivity"

sentry-jul/api/sentry-jul.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class io/sentry/jul/SentryHandler : java/util/logging/Handler {
88
public static final field THREAD_ID Ljava/lang/String;
99
public fun <init> ()V
1010
public fun <init> (Lio/sentry/SentryOptions;)V
11+
public fun <init> (Lio/sentry/SentryOptions;Z)V
1112
public fun close ()V
1213
public fun flush ()V
1314
public fun getMinimumBreadcrumbLevel ()Ljava/util/logging/Level;

sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class SentryHandler extends Handler {
5151

5252
/** Creates an instance of SentryHandler. */
5353
public SentryHandler() {
54-
this(new SentryOptions(), true);
54+
this(new SentryOptions());
5555
}
5656

5757
/**
@@ -60,17 +60,32 @@ public SentryHandler() {
6060
* @param options the SentryOptions
6161
*/
6262
public SentryHandler(final @NotNull SentryOptions options) {
63-
this(options, true);
63+
this(options, true, true);
64+
}
65+
66+
/**
67+
* Creates an instance of SentryHandler.
68+
*
69+
* @param options the SentryOptions
70+
* @param enableExternalConfiguration whether external options like sentry.properties and ENV vars
71+
* should be parsed
72+
*/
73+
public SentryHandler(
74+
final @NotNull SentryOptions options, final boolean enableExternalConfiguration) {
75+
this(options, true, enableExternalConfiguration);
6476
}
6577

6678
/** Creates an instance of SentryHandler. */
6779
@TestOnly
68-
SentryHandler(final @NotNull SentryOptions options, final boolean configureFromLogManager) {
80+
SentryHandler(
81+
final @NotNull SentryOptions options,
82+
final boolean configureFromLogManager,
83+
final boolean enableExternalConfiguration) {
6984
setFilter(new DropSentryFilter());
7085
if (configureFromLogManager) {
7186
retrieveProperties();
7287
}
73-
options.setEnableExternalConfiguration(true);
88+
options.setEnableExternalConfiguration(enableExternalConfiguration);
7489
options.setInitPriority(InitPriority.LOWEST);
7590
options.setSdkVersion(createSdkVersion(options));
7691
Sentry.init(options);

sentry-jul/src/test/kotlin/io/sentry/jul/SentryHandlerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SentryHandlerTest {
3636
options.setTransportFactory { _, _ -> transport }
3737
contextTags?.forEach { options.addContextTag(it) }
3838
logger = Logger.getLogger("jul.SentryHandlerTest")
39-
handler = SentryHandler(options, configureWithLogManager)
39+
handler = SentryHandler(options, configureWithLogManager, true)
4040
handler.setMinimumBreadcrumbLevel(minimumBreadcrumbLevel)
4141
handler.setMinimumEventLevel(minimumEventLevel)
4242
handler.level = Level.ALL

0 commit comments

Comments
 (0)