Skip to content
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

Custom metrics/logging integration point #1681

Closed
nikoncode opened this issue Jan 16, 2021 · 6 comments · Fixed by #1695
Closed

Custom metrics/logging integration point #1681

nikoncode opened this issue Jan 16, 2021 · 6 comments · Fixed by #1695

Comments

@nikoncode
Copy link

nikoncode commented Jan 16, 2021

I want to build custom metrics over handler execution time and result (success/unsuccess).

After exploring spring-kafka codebase I found kind of hook-based micrometer built-in implementation (org.springframework.kafka.listener.KafkaMessageListenerContainer.ListenerConsumer#doInvokeRecordListener). But end-user cannot customize it.

Why it's so strict? I mean spring-kafka has various integration points: interceptor (before-execution), error handlers (in case of error) but no handler to connect them all together (even using ThreadLocal).

I expect something like this:

interface Hook {
   void before(ConsumerRecord);
   void after(ConsumerRecord);
   void error(ConsumerRecord, Exception);
}

And existing micrometer integration can work through this interface as well.

If there is any way how to handle all these events exists, please let me know.

P.S.: in our production, we can partially solve this problem by using aspects, but in case of multiple topics in KafkaListener we are not able to extract topic name because of using value injection.

@nikoncode nikoncode changed the title Custom metrics integration point Custom metrics/logging integration point Jan 16, 2021
@garyrussell
Copy link
Contributor

I believe we can add additional (default) methods to the existing RecordInterceptor for this.

@garyrussell garyrussell added this to the 2.7.0-M2 milestone Jan 27, 2021
garyrussell added a commit to garyrussell/spring-kafka that referenced this issue Jan 27, 2021
garyrussell added a commit to garyrussell/spring-kafka that referenced this issue Jan 27, 2021
artembilan pushed a commit that referenced this issue Jan 27, 2021
Resolves #1681

Also add `BatchInterceptor`.

* Fix LogAccessor Usage.
@nikoncode
Copy link
Author

nikoncode commented May 5, 2021

@artembilan @garyrussell BTW absence of this integration ruins migration to spring-kafka inside our organization since we cannot integrate tracing and metrics because of that.

As I understand this one will be addressed in 2.7.0 which will be included only in spring boot 2.5.x.

Does it possible to backport this change into 2.6.x to give us possibility to use it earlier than boot 2.5.x.

We have tried multiple ways how to bypass that including AOP, but it's not possible to get information about topic (in case of wildcard subscription) if you are using plain POJO instead of ConsumerRecord.

@artembilan
Copy link
Member

Well, technically Spring Boot 2.5 is due on May 20th: https://github.com/spring-projects/spring-boot/milestone/201 - just a couple weeks! If even we back-port that fix into 2.6.x, it is going to happen around the same time anyway.

saying that I see @garyrussell has scheduled this for back-porting, but then remove that label. Perhaps there was a reason to consider this feature as a breaking change somehow...

@garyrussell
Copy link
Contributor

I don't remember why I decided not to back-port - I'll take a look to see how hard it might be.

@nikoncode
Copy link
Author

nikoncode commented May 6, 2021

@artembilan @garyrussell we have big amount of services, that's why it might be hard to migrate anyway, moreover we use spring cloud which is not ready yet for 2.5

@garyrussell please, It will be fantastic.

garyrussell added a commit that referenced this issue May 6, 2021
Resolves #1681

Also add `BatchInterceptor`.

* Fix LogAccessor Usage.
@garyrussell
Copy link
Contributor

Backported as ffa7e80 - 2.6.8 is currently scheduled for May 17th.

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

Successfully merging a pull request may close this issue.

3 participants