Skip to content

Commit

Permalink
fix trace_id packing and types
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Apr 23, 2024
1 parent 7e9fe1e commit 59e9c5c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/datadog/opentelemetry/sdk/span_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def start_datadog_span(span)
unless span.links.nil?
datadog_span.links = span.links.map do |link|
Datadog::Tracing::SpanLink.new(
Datadog::Tracing::TraceDigest.new(
trace_id: link.span_context.trace_id.unpack1('Q'),
span_id: link.span_context.span_id.unpack1('Q'),
digest: Datadog::Tracing::TraceDigest.new(
trace_id: link.span_context.hex_trace_id.to_i(16),
span_id: link.span_context.hex_span_id.to_i(16),
trace_flags: (link.span_context.trace_flags&.sampled? ? 1 : 0),
trace_state: link.span_context.tracestate&.to_s,
span_remote: link.span_context.remote?,
Expand Down
17 changes: 11 additions & 6 deletions spec/datadog/opentelemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,15 @@
end

context 'with span_links' do
let(:sc1) { OpenTelemetry::Trace::SpanContext.new(trace_id: 36893488147419103231, span_id: 2) }
let(:sc1) do
OpenTelemetry::Trace::SpanContext.new(
trace_id: ['000000000000006d5b953ca4d9c834ab'].pack('H*'),
span_id: [67893423423].pack('Q')
)
end
let(:sc2) do
OpenTelemetry::Trace::SpanContext.new(
trace_id: [1234534].pack('Q'),
trace_id: ['12d666'].pack('H*'),
span_id: [67890].pack('Q'),
trace_flags: OpenTelemetry::Trace::TraceFlags::SAMPLED,
tracestate: OpenTelemetry::Trace::Tracestate.from_string('otel=blahxd')
Expand All @@ -340,14 +345,14 @@
start_span.finish
expect(span.links.size).to eq(2)

expect(span.links[0].trace_id).to eq(sc1.trace_id)
expect(span.links[0].span_id).to eq(sc1.span_id)
expect(span.links[0].trace_id).to eq(2017294351542048535723)
expect(span.links[0].span_id).to eq(67893423423)
expect(span.links[0].trace_flags).to eq(0)
expect(span.links[0].trace_state).to eq('')
expect(span.links[0].attributes).to eq({ 'key' => 'val', '1' => true })

expect(span.links[1].trace_id).to eq(sc2.trace_id)
expect(span.links[1].span_id).to eq(sc2.span_id)
expect(span.links[1].trace_id).to eq(1234534)
expect(span.links[1].span_id).to eq(67890)
expect(span.links[1].trace_flags).to eq(1)
expect(span.links[1].trace_state).to eq(sc2.tracestate.to_s)
expect(span.links[1].attributes).to eq({ 'key2' => true, 'list' => [1, 2] })
Expand Down

0 comments on commit 59e9c5c

Please sign in to comment.