-
Notifications
You must be signed in to change notification settings - Fork 714
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
add flag to not share trace on consumption #1033
Conversation
cc @jorgheymans |
instrumentation/kafka-clients/src/main/java/brave/kafka/clients/KafkaTracing.java
Outdated
Show resolved
Hide resolved
* | ||
* @since 5.10 | ||
*/ | ||
public Builder shareTraceOnConsumption(boolean shareTraceOnConsumption) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be nice to indicate that this applies to new traces in the name itself. shareNewTraceOnConsumption
?
Though for me it's easier to grok with the opposite - splitNewTraceOnConsumption
. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I know the class is called consumer but I think receive might be easier to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'm not convinced about naming either hehe. I'll rephrase my explanation to have a better background for naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tend to agree, since shareTraceOnConsumption
is the current behaviour it might stand out more if the flag refers to enabling the opposite behaviour . splitTraceOnConsumption
, spanPerMessage
, noSpanPerBatch
,
Above names are still slightly misleading as they could make ppl (like me) think that it allows you to break a trace, whereas the flag only applies when no parent trace context is around. spanPerMessageWhenNoParentTraceFound
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would shareRootSpanOnReceive
or rootSpanOnReceiveBatch
be a better name? (I think span...WhenNoParentTrace
~= rootSpan
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw @jorgheymans I think we should have a similar flag to do not continue a trace on the consumer side (instead that removing headers on the producer), that would be related with this one. for instance: if producer is instrumented and injecting trace context, on the consumer side we can decide to do not continue the same trace context, and just create a new root span. Then, this flag can help to opt-out of sharing that root span between consumed messages in a batch.
Will tackle this on an additional PR as it will impact other messaging instrumentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeqo so maybe this should be bundled together as one feature then, where the separate-span-if-no-existing-root
and force-start-new-trace
are just different strategies of this feature ? This 'something' would allow one to relatively easily define new processing like 'if the message header contains value X we want to start a new trace, otherwise join existing'. Or is that a bridge too far ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say that (1) starting a new trace on consume is independent from (2) reusing/sharing rootSpan when consuming a batch. Where (1) is shared across messaging instrumentations, probably should be added at that level of abstraction; and (2) is specific to Kafka so far as we don't have other consumer instrumentation polling batches, but could eventually be moved to messaging
as well. So, I'd take these as 2 diff features.
About if (header=x) then start new trace
, I haven't thought about this as initial use-case. My first answer will be to do this once you have consumed a message, as part of your code. But we can discuss this further here #1039
instrumentation/kafka-clients/src/main/java/brave/kafka/clients/KafkaTracing.java
Outdated
Show resolved
Hide resolved
@anuraaga, I've rephrased API comments, and added context on the PR. Let me know if its clearer now to focus on flag name. |
instrumentation/kafka-clients/src/main/java/brave/kafka/clients/KafkaTracing.java
Outdated
Show resolved
Hide resolved
instrumentation/kafka-clients/src/main/java/brave/kafka/clients/KafkaTracing.java
Outdated
Show resolved
Hide resolved
instrumentation/kafka-clients/src/main/java/brave/kafka/clients/KafkaTracing.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
instrumentation/kafka-clients/src/main/java/brave/kafka/clients/KafkaTracing.java
Outdated
Show resolved
Hide resolved
@anuraaga @jorgheymans , I've applied latest changes based on your feedback. Let me know if it's ready to merge :) |
minor nit otherwise good to go 👍 |
instrumentation/kafka-clients/src/main/java/brave/kafka/clients/KafkaTracing.java
Outdated
Show resolved
Hide resolved
thanks for your feedback! I'll go ahead and merge this one 👍 |
fix #1032
Context:
Kafka Consumers obtain records from a Kafka topics by polling from an offset. By design, poll operation return an array of records, to be processed usually in a loop.
This
poll
operation is traced and create an initial span on the consumer application. Right before creating this span, incoming record is checked to see if it has a trace context or not. If it does,poll
span will be created to continue a record's trace. If it doesn't, it will create apoll
span to be shared with other records that doesn't have a trace context in its headers.This PR is aimed to allow users to opt-out this mechanism of creating a shared span for records without a trace context. Instead, a
poll
span will be created by record.I'd like to propose the following defaults:
shareTraceOnConsumption=true
to don't break current behavior on consumers; as plain Kafka Consumers are usually used to sink data somewhere.shareTraceOnConsumption=false
as Kafka Streams usually propagate context to other topics, leading to even larger traces that if batched, parent trace will be too big.