fix(spring-jakarta): [Queue Instrumentation 12] Add Kafka retry count attribute#5282
Conversation
… attribute Set messaging.message.retry.count on queue.process transactions when the Spring Kafka delivery attempt header is present. This keeps retry context on consumer traces without changing transaction lifecycle behavior. Co-Authored-By: Claude <noreply@anthropic.com>
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. This PR will not appear in the changelog. 🤖 This preview updates automatically when you update the PR. |
Sentry Build Distribution
|
Performance metrics 🚀
|
| return transaction; | ||
| } | ||
|
|
||
| private @Nullable Integer retryCount(final @NotNull ConsumerRecord<K, V> record) { |
There was a problem hiding this comment.
Not sure about the semantics of the header, but if the retry header has a value of 1 we return 0. Does that make sense?
There was a problem hiding this comment.
Yeah, need to confirm this is what's actually happening on our sample but attempt 2 means first retry.
There was a problem hiding this comment.
Confirmed, it does work with config:
@Bean
DefaultErrorHandler kafkaErrorHandler() {
return new DefaultErrorHandler(new FixedBackOff(0L, 1L));
}
@Bean
ContainerCustomizer<Object, Object, ConcurrentMessageListenerContainer<Object, Object>>
kafkaContainerCustomizer() {
return container -> container.getContainerProperties().setDeliveryAttemptHeader(true);
}
There was a problem hiding this comment.
Nice, just need to remember to put this into the docs if its something the user has to do
PR Stack (Queue Instrumentation)
📜 Description
Set
messaging.message.retry.countonqueue.processtransactions when Spring Kafka provides the delivery attempt header. The retry count is derived asdeliveryAttempt - 1(attempt 1 → retry count 0).If the header is missing, malformed, or non-positive, no retry count attribute is added.
💡 Motivation and Context
Kafka retries currently create multiple
queue.processtransactions for the same record. Adding retry-count metadata makes attempts distinguishable in traces and aligns with Sentry conventions.💚 How did you test it?
./gradlew :sentry-spring-jakarta:test --tests='*SentryKafkaRecordInterceptorTest*'sets retry count from delivery attempt headerdoes not set retry count when delivery attempt header is missing📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
None.
#skip-changelog