Skip to content

Commit

Permalink
Use 64-bit trace_ids as required by the current implementation of Dat…
Browse files Browse the repository at this point in the history
…adog.
  • Loading branch information
ioquatix committed Feb 8, 2024
1 parent 6c5522e commit 8f74c7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions lib/console/output/datadog/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# frozen_string_literal: true

module Console
module Output
# The reason why this is a serialized logger rather than an output filter, is because it needs to directly modify the top level of the record.
Expand All @@ -41,17 +43,24 @@ def call(subject = nil, *arguments, **options, &block)
if span = trace.active_span
options[:dd] = {
span_id: span.id.to_s,
trace_id: trace.id.to_s
trace_id: format_trace_id(trace.id)
}
else
options[:dd] = {
trace_id: trace.id.to_s
trace_id: format_trace_id(trace.id)
}
end
end

@output.call(subject, *arguments, **options, &block)
end

private

def format_trace_id(id)
# 128-bit tracing is not supported by the Datadog agent, so we need to convert it to 64-bit. We expect that this will be changed in the future.
::Datadog::Tracing::Utils::TraceId.to_low_order(id)
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/console/output/datadog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
expect(buffer).to receive(:call).with("Hello World",
severity: :info,
dd: {
trace_id: span.trace_id.to_s,
trace_id: ::Datadog::Tracing::Correlation::Identifier.new(trace_id: span.trace_id).trace_id,
span_id: span.id.to_s
}
)
Expand All @@ -45,7 +45,7 @@
expect(buffer).to receive(:call).with("Hello World",
severity: :info,
dd: {
trace_id: span.trace_id.to_s
trace_id: ::Datadog::Tracing::Correlation::Identifier.new(trace_id: span.trace_id).trace_id
}
)

Expand Down

0 comments on commit 8f74c7c

Please sign in to comment.