Skip to content

fix: spring messaging kotlin async aware instrumentation#11047

Open
ygree wants to merge 7 commits intomasterfrom
ygree/spring-messaging-async-aware-instrumentation
Open

fix: spring messaging kotlin async aware instrumentation#11047
ygree wants to merge 7 commits intomasterfrom
ygree/spring-messaging-async-aware-instrumentation

Conversation

@ygree
Copy link
Copy Markdown
Contributor

@ygree ygree commented Apr 2, 2026

What Does This Do

Adds support for KotlinAwareInvocableHandlerMethod to pass the spring.consume context to a kotlin suspend consume fun and keep the span open for entire async execution.

Motivation

A kotlin suspend function execution isn't in scope of the spring.consume.

Additional Notes

Reuse slightly refactored AsyncResultExtensions class to provide a unified way of supporting different asynchronous results.

Supersedes: #10831 to keep the span open for entire async execution

Contributor Checklist

Jira ticket: APMS-18839

Note: Once your PR is ready to merge, add it to the merge queue by commenting /merge. /merge -c cancels the queue request. /merge -f --reason "reason" skips all merge queue checks; please use this judiciously, as some checks do not run at the PR-level. For more information, see this doc.

@ygree ygree added type: bug Bug report and fix inst: spring Spring instrumentation tag: concurrency Virtual Threads, Coroutines, Async, RX, Executors labels Apr 2, 2026
@ygree ygree self-assigned this Apr 2, 2026
@ygree ygree marked this pull request as ready for review April 2, 2026 23:20
@ygree ygree requested review from a team as code owners April 2, 2026 23:20
@ygree ygree requested a review from mcculls April 2, 2026 23:20
@ygree ygree force-pushed the ygree/spring-messaging-async-aware-instrumentation branch from 4885bba to 8eb2a7f Compare April 3, 2026 03:04
@ygree ygree force-pushed the ygree/spring-messaging-async-aware-instrumentation branch from 8eb2a7f to 7e0822f Compare April 3, 2026 03:17
@ygree ygree changed the title fix: spring messaging async aware instrumentation fix: spring messaging kotlin async aware instrumentation Apr 3, 2026
implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice {

public KotlinAwareHandlerInstrumentation() {
super("spring-messaging", "spring-messaging-4");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider adding an alias that specifically mentions kotlin, such as spring-messaging-kotlin - that would let us disable this specific instrumentation while leaving the main spring-messaging instrumentation enabled.

Comment on lines +45 to +49
@Override
public List<Instrumenter> typeInstrumentations() {
return Collections.singletonList(new KotlinAwareHandlerInstrumentation());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove this - use the default implementation of typeInstrumentations() which does the same thing

Suggested change
@Override
public List<Instrumenter> typeInstrumentations() {
return Collections.singletonList(new KotlinAwareHandlerInstrumentation());
}

span.finish();
}
if (null != error) {
DECORATE.onError(span, error);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't this already done above in lines 97-99?

Copy link
Copy Markdown
Contributor

@mcculls mcculls left a comment

Choose a reason for hiding this comment

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

Looks reasonable, just a couple of things to clean up before this can be merged

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

Labels

inst: spring Spring instrumentation tag: concurrency Virtual Threads, Coroutines, Async, RX, Executors type: bug Bug report and fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants