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

Instrument spring-kafka batch message listeners #3922

Merged
merged 4 commits into from
Aug 27, 2021

Conversation

mateuszrzeszutek
Copy link
Member

Fixes #3529

// this instrumentation will create CONSUMER receive spans for each record instead of
// kafka-clients
if (it instanceof KafkaConsumerIteratorWrapper) {
it = ((KafkaConsumerIteratorWrapper<K, V>) it).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be better to somehow completely suppress kafka-client instrumentation. Currently it is still possible to have kafka-client create extra spans. Copy logback.xml from spring-webmvc-3.1 to test/resources and add <logger name="org.springframework.kafka.listener" level="trace"/>

Copy link
Member Author

Choose a reason for hiding this comment

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

It definitely is better to have it disabled by default. For a broader picture, I'm planning to instrument the most commonly used "higher-level" kafka consumer APIs (spring, vertx, reactor, ... anything else?) and after they all have their own separate instrumentations I believe we should have the kafka-clients consumer one disabled by default (which is exactly what @trask suggested in #1947 (comment)). It might take some time though 😅
For now this hack must suffice, but I'd love to turn off the kafka-clients instrumentation completely sometime.

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

👍

Comment on lines +13 to +31
/** Extractor of span links for a request. */
@FunctionalInterface
public interface SpanLinksExtractor<REQUEST> {

/**
* Extracts {@link SpanContext}s that should be linked to the newly created span and adds them to
* {@code spanLinks}.
*/
void extract(SpanLinksBuilder spanLinks, Context parentContext, REQUEST request);

/**
* Returns a new {@link SpanLinksExtractor} that will extract a {@link SpanContext} from the
* request using configured {@code propagators}.
*/
static <REQUEST> SpanLinksExtractor<REQUEST> fromUpstreamRequest(
ContextPropagators propagators, TextMapGetter<REQUEST> getter) {
return new PropagatorBasedSpanLinksExtractor<>(propagators, getter);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

cc: @anuraaga new Instrumenter API addition


Context parentContext = Context.current();

// create spans for all records received in a batch
Copy link
Member

Choose a reason for hiding this comment

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

any particular thoughts on this vs a single receive span with the links on the receive span?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried matching the code with one of the spec example scenarios, I chose the "batch processing" one because it made the most sense to have a single process span for all received messages. It's not a perfect match though - in case of Kafka we're both receiving and processing in batch; so it'd make much more sense to have one receive span that spans the whole consumer.poll() call and a second process span for the spring message listener that links the PRODUCER spans. That's more or less what open-telemetry/opentelemetry-specification#1085 proposes; I guess this PR might be a good reason to revisit the messaging conventions and think what telemetry we should generate in a "batch receive+process" scenario.

Mateusz Rzeszutek and others added 2 commits August 26, 2021 10:12
…tion/api/instrumenter/InstrumenterBuilder.java

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
@mateuszrzeszutek
Copy link
Member Author

Do you mind if I implement the "one receive span + one process span" idea in a separate PR? I thought a bit about how to do this, and it'd probably require lots of changes in this and the kafka-clients instrumentations. I don't really want to make this PR any bigger, it's large enough as it is, so I thought it may be a better idea to implement this thing separately.

@trask
Copy link
Member

trask commented Aug 27, 2021

Do you mind if I implement the "one receive span + one process span" idea in a separate PR? I thought a bit about how to do this, and it'd probably require lots of changes in this and the kafka-clients instrumentations. I don't really want to make this PR any bigger, it's large enough as it is, so I thought it may be a better idea to implement this thing separately.

sounds good 👍

@trask trask merged commit 4567bc0 into open-telemetry:main Aug 27, 2021
@mateuszrzeszutek mateuszrzeszutek deleted the spring-kafka-batch branch August 27, 2021 15:09
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.

spring-kafka batch listener creates disjointed traces
3 participants