Skip to content

KafkaMessageListenerContainer Observation Scope seems to be setup incorrectlyΒ #3686

@leaf-upper

Description

@leaf-upper

In what version(s) of Spring for Apache Kafka are you seeing this issue?

For example:

3.3.0

Describe the bug

Recently In applicaiton, Spring Kafka Version upgraded to spring-kafka 3.3.0 from spring-kafka 3.2.4
In doInvokeRecordListener method, when message failed and scope is closed, logging data (For example, MDC) is disappered.

//spring-kafka 3.3.0
observation.start();
try (Observation.Scope ignored = observation.openScope()) {
  invokeOnMessage(cRecord);
  successTimer(sample, cRecord);
  recordInterceptAfter(cRecord, null);
}
catch (RuntimeException e) {
  failureTimer(sample, cRecord); // Observation Scope is closed and, (Logging Data) MDC is initialized. 
  recordInterceptAfter(cRecord, e); 
  ...

but In spring-kafka 3.2.4
Observaiton scope is not closed when message failed, and Logging Information is maintained

//spring-kafka 3.2.4
return observation.observe(() -> {
try {
  invokeOnMessage(cRecord);
  successTimer(sample, cRecord);
  recordInterceptAfter(cRecord, null);
}
catch (RuntimeException e) {
  failureTimer(sample, cRecord);
  recordInterceptAfter(cRecord, e);
  ...

In conclusion, is it possible to roll back to the original code?

Expected behavior

i expect that logging data is maintained when message failed for logging in RecordInterceptor

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions