Skip to content

Commit

Permalink
add tracestate to span data (#276)
Browse files Browse the repository at this point in the history
* add tracestate to span data

* fix rubocop on tracestate change

* add tracestate test that validates tracestate during span lifecycle

Co-authored-by: Francis Bogsanyi <francis.bogsanyi@shopify.com>
  • Loading branch information
ericmustin and fbogsany committed Jun 15, 2020
1 parent a76c428 commit 0af1128
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion exporters/jaeger/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Metrics/AbcSize:
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Max: 20
Max: 21
Metrics/ParameterLists:
Enabled: false
Naming/FileName:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
)
end

def create_span_data(attributes: nil, events: nil, links: nil, trace_id: OpenTelemetry::Trace.generate_trace_id, trace_flags: OpenTelemetry::Trace::TraceFlags::DEFAULT)
def create_span_data(attributes: nil, events: nil, links: nil, trace_id: OpenTelemetry::Trace.generate_trace_id, trace_flags: OpenTelemetry::Trace::TraceFlags::DEFAULT, tracestate: nil)
OpenTelemetry::SDK::Trace::SpanData.new(
'',
nil,
Expand All @@ -79,7 +79,8 @@ def create_span_data(attributes: nil, events: nil, links: nil, trace_id: OpenTel
nil,
OpenTelemetry::Trace.generate_span_id,
trace_id,
trace_flags
trace_flags,
tracestate
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def create_span_data(name: '', kind: nil, status: nil, parent_span_id: OpenTelem
total_recorded_attributes: 0, total_recorded_events: 0, total_recorded_links: 0, start_timestamp: Time.now,
end_timestamp: Time.now, attributes: nil, links: nil, events: nil, library_resource: nil, instrumentation_library: nil,
span_id: OpenTelemetry::Trace.generate_span_id, trace_id: OpenTelemetry::Trace.generate_trace_id,
trace_flags: OpenTelemetry::Trace::TraceFlags::DEFAULT)
trace_flags: OpenTelemetry::Trace::TraceFlags::DEFAULT, tracestate: nil)
OpenTelemetry::SDK::Trace::SpanData.new(name, kind, status, parent_span_id, child_count, total_recorded_attributes,
total_recorded_events, total_recorded_links, start_timestamp, end_timestamp,
attributes, links, events, library_resource, instrumentation_library, span_id, trace_id, trace_flags)
attributes, links, events, library_resource, instrumentation_library, span_id, trace_id, trace_flags, tracestate)
end
end
2 changes: 1 addition & 1 deletion sdk/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Metrics/AbcSize:
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Max: 20
Max: 21
Metrics/ParameterLists:
Enabled: false
Naming/FileName:
Expand Down
3 changes: 2 additions & 1 deletion sdk/lib/opentelemetry/sdk/trace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def to_span_data
@instrumentation_library,
context.span_id,
context.trace_id,
context.trace_flags
context.trace_flags,
context.tracestate
)
end

Expand Down
3 changes: 2 additions & 1 deletion sdk/lib/opentelemetry/sdk/trace/span_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module Trace
:instrumentation_library,
:span_id,
:trace_id,
:trace_flags)
:trace_flags,
:tracestate)
end
end
end
24 changes: 23 additions & 1 deletion sdk/test/integration/global_tracer_configurations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
end
end
let(:tracer) { provider.tracer(__FILE__, sdk::VERSION) }
let(:parent_context) { nil }
let(:finished_spans) { exporter.finished_spans }

before do
tracer.in_span('root') do
tracer.in_span('root', with_parent_context: parent_context) do
tracer.in_span('child1') {}
tracer.in_span('child2') {}
end
Expand Down Expand Up @@ -48,4 +49,25 @@
finished_spans
end
end

describe 'using tracestate in extracted span context' do
let(:mock_tracestate) { 'vendor_key=vendor_value' }
let(:parent_span_context) { OpenTelemetry::Trace::SpanContext.new(tracestate: mock_tracestate) }
let(:parent_context) do
OpenTelemetry::Context.empty.set_value(
OpenTelemetry::Trace::Propagation::ContextKeys.extracted_span_context_key,
parent_span_context
)
end

describe '#finished_spans' do
it 'propogates tracestate through span lifecycle into SpanData' do
finish_span_keys = finished_spans.collect(&:members).flatten.uniq

_(finish_span_keys).must_include(:tracestate)

finished_spans.first.tracestate.must_equal(mock_tracestate)
end
end
end
end

0 comments on commit 0af1128

Please sign in to comment.