From 19cb74037201442d7f0346603dc85d4979126ec1 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 22 Apr 2026 05:36:52 +0200 Subject: [PATCH] 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. --- .../spring/jakarta/kafka/SentryKafkaRecordInterceptor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/kafka/SentryKafkaRecordInterceptor.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/kafka/SentryKafkaRecordInterceptor.java index 70a115bf7d..c03d318770 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/kafka/SentryKafkaRecordInterceptor.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/kafka/SentryKafkaRecordInterceptor.java @@ -61,6 +61,7 @@ public SentryKafkaRecordInterceptor( final @NotNull IScopes forkedScopes = scopes.forkedRootScopes("SentryKafkaRecordInterceptor"); final @NotNull ISentryLifecycleToken lifecycleToken = forkedScopes.makeCurrent(); + currentContext.set(new SentryRecordContext(lifecycleToken, null)); final @Nullable TransactionContext transactionContext = continueTrace(forkedScopes, record);