Skip to content

Commit 68edd9a

Browse files
committed
docs: Add changelog entry for trace_ids fix
https://claude.ai/code/session_012wjHQtsEPzcrxSMCufxrDY
1 parent d9c1521 commit 68edd9a

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Session Replay: Populate `trace_ids` in replay events to enable searching replays by trace ID ([#5473](https://github.com/getsentry/sentry-java/pull/5473))
8+
39
## 8.43.0
410

511
### Features

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import io.sentry.transport.ICurrentDateProvider
3333
import java.io.File
3434
import java.util.Date
3535
import java.util.Deque
36-
import java.util.concurrent.ConcurrentHashMap
3736
import java.util.concurrent.ConcurrentLinkedDeque
3837
import java.util.concurrent.Executors
3938
import java.util.concurrent.ScheduledExecutorService
@@ -55,6 +54,8 @@ internal abstract class BaseCaptureStrategy(
5554
) : CaptureStrategy {
5655
internal companion object {
5756
private const val TAG = "CaptureStrategy"
57+
// https://github.com/getsentry/sentry-javascript/blob/30eb68fff5077211c30c61ba74625e66ab514870/packages/replay-internal/src/coreHandlers/handleAfterSendEvent.ts#L41
58+
private const val MAX_TRACE_IDS = 100
5859
}
5960

6061
private val persistingExecutor: ScheduledExecutorService by lazy {
@@ -97,7 +98,8 @@ internal abstract class BaseCaptureStrategy(
9798
override var replayType by persistableAtomic<ReplayType>(propertyName = SEGMENT_KEY_REPLAY_TYPE)
9899

99100
protected val currentEvents: Deque<RRWebEvent> = ConcurrentLinkedDeque()
100-
protected val currentTraceIds: MutableSet<String> = ConcurrentHashMap.newKeySet()
101+
private val traceIdsLock = Any()
102+
protected val currentTraceIds: MutableList<String> = mutableListOf()
101103

102104
override fun start(segmentId: Int, replayId: SentryId, replayType: ReplayType?) {
103105
cache = replayCacheProvider?.invoke(replayId) ?: ReplayCache(options, replayId)
@@ -138,8 +140,11 @@ internal abstract class BaseCaptureStrategy(
138140
breadcrumbs: List<Breadcrumb>? = null,
139141
events: Deque<RRWebEvent> = this.currentEvents,
140142
): ReplaySegment {
141-
val traceIds = currentTraceIds.toList().ifEmpty { null }
142-
currentTraceIds.clear()
143+
val traceIds = synchronized(traceIdsLock) {
144+
val ids = currentTraceIds.toList().ifEmpty { null }
145+
currentTraceIds.clear()
146+
ids
147+
}
143148
return createSegment(
144149
scopes,
145150
options,
@@ -175,7 +180,14 @@ internal abstract class BaseCaptureStrategy(
175180

176181
override fun registerTraceId(traceId: SentryId) {
177182
if (traceId != SentryId.EMPTY_ID) {
178-
currentTraceIds.add(traceId.toString())
183+
synchronized(traceIdsLock) {
184+
if (currentTraceIds.size < MAX_TRACE_IDS) {
185+
val id = traceId.toString()
186+
if (!currentTraceIds.contains(id)) {
187+
currentTraceIds.add(id)
188+
}
189+
}
190+
}
179191
}
180192
}
181193

0 commit comments

Comments
 (0)