-
Notifications
You must be signed in to change notification settings - Fork 394
Fix losing original karafka trace after iterating through the messages with distributed_tracing on #4876
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
base: master
Are you sure you want to change the base?
Fix losing original karafka trace after iterating through the messages with distributed_tracing on #4876
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,24 +24,39 @@ def propagation | |
# (e.g. `my_batch_operation messages.payloads`) | ||
# @see https://github.com/karafka/karafka/blob/b06d1f7c17818e1605f80c2bb573454a33376b40/README.md?plain=1#L29-L35 | ||
def each(&block) | ||
parent_span = Datadog::Tracing.active_span | ||
parent_trace_digest = Datadog::Tracing.active_trace&.to_digest | ||
|
||
@messages_array.each do |message| | ||
if configuration[:distributed_tracing] | ||
trace_digest = if configuration[:distributed_tracing] | ||
headers = if message.metadata.respond_to?(:raw_headers) | ||
message.metadata.raw_headers | ||
else | ||
message.metadata.headers | ||
end | ||
trace_digest = Karafka.extract(headers) | ||
Datadog::Tracing.continue_trace!(trace_digest) if trace_digest | ||
Karafka.extract(headers) | ||
end | ||
|
||
Tracing.trace(Ext::SPAN_MESSAGE_CONSUME) do |span| | ||
Tracing.trace(Ext::SPAN_MESSAGE_CONSUME, continue_from: trace_digest) do |span, trace| | ||
span.set_tag(Ext::TAG_OFFSET, message.metadata.offset) | ||
span.set_tag(Contrib::Ext::Messaging::TAG_DESTINATION, message.topic) | ||
span.set_tag(Contrib::Ext::Messaging::TAG_SYSTEM, Ext::TAG_SYSTEM) | ||
|
||
span.resource = message.topic | ||
|
||
# link the outer trace (where the messages batch was consumed) | ||
# with the individual message's processing trace, so they're easier to | ||
# correlate in the Datadog UI | ||
if parent_span && span.parent_id != parent_span.id | ||
# add a link from the parent trace to the message span | ||
span_link = Tracing::SpanLink.new(parent_trace_digest) | ||
span.links << span_link | ||
|
||
# add a link from the current trace to the parent span | ||
span_link = Tracing::SpanLink.new(trace.to_digest) | ||
parent_span.links << span_link | ||
end | ||
Comment on lines
+50
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please let me know your thoughts here! I understand that "span links" are not very widely used here in the ruby sdk, but one challenge we have once we continue a trace is co-relating the span with its "original parent". I think span links are a great fit for solving that problem. |
||
|
||
yield message | ||
end | ||
end | ||
|
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.
Actually I am not sure this is correct. Is
continue_from
really meant for parent/child relationship?