Skip to content

GH-3741: Fix metric tag to show underlying exception type #3756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2025

Conversation

sobychacko
Copy link
Contributor

Fixes: #3741
Issue: #3741

When exceptions occur in Kafka listeners, the metrics currently show ListenerExecutionFailedException in both the error tag (when using observation) and exception tag (when using micrometer without observation), rather than the actual underlying exception.

  • Modify ListenerContainer to pass actual exception to failure metrics
  • Update MessagingMessageListenerAdapter to report cause to observation
  • Add MicrometerMetricsTests to verify both observation and non-observation metrics
  • Fix ObservationTests to verify correct error reporting in metrics

This ensures metrics show the actual underlying exception while maintaining existing span behavior.

Signed-off-by: Soby Chacko [email protected]

Auto-cherry-pick to 3.3.x & 3.2.x

Fixes: spring-projects#3741
Issue: spring-projects#3741

When exceptions occur in Kafka listeners, the metrics currently show
`ListenerExecutionFailedException` in both the `error` tag (when using
observation) and `exception` tag (when using micrometer without observation),
rather than the actual underlying exception.

* Modify ListenerContainer to pass actual exception to failure metrics
* Update MessagingMessageListenerAdapter to report cause to observation
* Add MicrometerMetricsTests to verify both observation and non-observation metrics
* Fix ObservationTests to verify correct error reporting in metrics

This ensures metrics show the actual underlying exception while maintaining
existing span behavior.

Signed-off-by: Soby Chacko <[email protected]>

**Auto-cherry-pick to `3.3.x` & `3.2.x`**
Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple remarks.
Thanks


/**
* @author Soby Chacko
* @since 3.3.3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 3.3.3
* @since 3.2.7

static class Config {

@Bean
KafkaAdmin admin(EmbeddedKafkaBroker broker) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why do we need this bean?

}

@Bean
SimpleTracer simpleTracer() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use this bean somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry - copy error from the other test :)

@artembilan artembilan merged commit ea9cf27 into spring-projects:main Feb 18, 2025
3 checks passed
@artembilan
Copy link
Member

Yeah...
Looks like we have some breaking changes between 3.2.x and 3.3.x.
We just cannot cherry-pick this fix over there down to 3.2.x.

Let's see if we want to have this fix in 3.2.x at all!
Otherwise just aim it maximum for 3.3.x and that's it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metric collection for errors always report the same error "ListenerExecutionFailedException" regardless of what's thrown in the consumer method
2 participants