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

fix(span_links): ensures trace_flags is consistent with the sampling priority #3596

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/datadog/tracing/span_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ class SpanLink
attr_reader :dropped_attributes

def initialize(
attributes: nil,
digest: nil
digest,
attributes: nil
)
@span_id = digest&.span_id
@trace_id = digest&.trace_id
@trace_flags = digest&.trace_flags
@trace_state = digest&.trace_state && digest&.trace_state.dup
@span_id = digest.span_id
@trace_id = digest.trace_id
@trace_flags = if digest.trace_sampling_priority.nil?
nil
elsif digest.trace_sampling_priority > 0
1
else
0
end
@trace_state = digest.trace_state && digest.trace_state.dup
@dropped_attributes = 0
@attributes = (attributes && attributes.dup) || {}
end
Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/tracing/span_link.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module Datadog
# @return [Integer]
attr_reader dropped_attributes: untyped

def initialize: (?attributes: untyped?, ?digest: untyped?) -> void
def initialize: (untyped digest, ?attributes: untyped?) -> void

def to_hash: () -> untyped
end
Expand Down
6 changes: 3 additions & 3 deletions spec/datadog/tracing/span_link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
require 'datadog/tracing/trace_digest'

RSpec.describe Datadog::Tracing::SpanLink do
subject(:span_link) { described_class.new(attributes: attributes, digest: digest) }
subject(:span_link) { described_class.new(digest, attributes: attributes) }

let(:attributes) { nil }
let(:digest) do
Datadog::Tracing::TraceDigest.new(
span_id: span_id,
trace_id: trace_id,
trace_flags: trace_flags,
trace_sampling_priority: trace_flags,
trace_state: trace_state,
)
end
Expand All @@ -23,7 +23,7 @@

describe '::new' do
context 'by default' do
let(:digest) { nil }
let(:digest) { Datadog::Tracing::TraceDigest.new }
let(:attributes) { nil }

it do
Expand Down
8 changes: 4 additions & 4 deletions spec/datadog/tracing/transport/serializable_trace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,22 @@
'dummy',
links: [
Datadog::Tracing::SpanLink.new(
digest: Datadog::Tracing::TraceDigest.new(
Datadog::Tracing::TraceDigest.new(
trace_id: 0xaaaaaaaaaaaaaaaaffffffffffffffff,
span_id: 0x1,
trace_state: 'vendor1=value,v2=v,dd=s:1',
trace_flags: 0x1,
trace_sampling_priority: 0x1,
),
attributes: { 'link.name' => 'test_link' }
),
Datadog::Tracing::SpanLink.new(
digest: Datadog::Tracing::TraceDigest.new(
Datadog::Tracing::TraceDigest.new(
trace_id: 0xa0123456789abcdef,
span_id: 0x2,
),
),
Datadog::Tracing::SpanLink.new(
digest: Datadog::Tracing::TraceDigest.new,
Datadog::Tracing::TraceDigest.new,
)
],
)
Expand Down
Loading