Skip to content

Commit 19cb740

Browse files
committed
fix(spring-jakarta): [Queue Instrumentation 23] Install Kafka context before trace setup
Store the lifecycle token in the thread-local context immediately after makeCurrent() so Spring's failure and clearThreadState callbacks can always clean it up. Previously, exceptions from trace continuation or transaction setup could happen before the context was published, leaving cleanup dependent on later stale-context handling instead of the normal interceptor callback path.
1 parent 80058bb commit 19cb740

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/kafka/SentryKafkaRecordInterceptor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public SentryKafkaRecordInterceptor(
6161

6262
final @NotNull IScopes forkedScopes = scopes.forkedRootScopes("SentryKafkaRecordInterceptor");
6363
final @NotNull ISentryLifecycleToken lifecycleToken = forkedScopes.makeCurrent();
64+
currentContext.set(new SentryRecordContext(lifecycleToken, null));
6465

6566
final @Nullable TransactionContext transactionContext = continueTrace(forkedScopes, record);
6667

0 commit comments

Comments
 (0)