Skip to content

Propagate sampled flag in-process and improve docs #88

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

Merged
merged 4 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## v0.16.0
### Added
- The tracer now supports B3 context propagation. Propagation can be set by using the `propagator` keyword argument to `Tracer#configure`. Valid values are `:lightstep` (default), and `:b3`.
- The tracer now supports B3 context propagation. Propagation can be set by using the `propagator` keyword argument to `LightStep.configure`. Valid values are `:lightstep` (default), and `:b3`.

## v0.15.0
### Added
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Or install it yourself as:
# Initialize the singleton tracer
LightStep.configure(component_name: 'lightstep/ruby/example', access_token: 'your_access_token')

# Specify a propagation format (options are :lightstep (default) and :b3)
LightStep.configure(component_name: 'lightstep/ruby/example', access_token: 'your_access_token', :propagator :b3)

# Create a basic span and attach a log to the span
span = LightStep.start_span('my_span')
span.log(event: 'hello world', count: 42)
Expand Down
4 changes: 3 additions & 1 deletion lib/lightstep/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def initialize(
ref = ref.context if (Span === ref)

if SpanContext === ref
@context = SpanContext.new(id: LightStep.guid, trace_id: ref.trace_id)
@context = SpanContext.new(id: LightStep.guid, trace_id: ref.trace_id, sampled: ref.sampled?)
set_baggage(ref.baggage)
set_tag(:parent_span_guid, ref.id)
else
Expand All @@ -83,6 +83,7 @@ def set_baggage_item(key, value)
@context = SpanContext.new(
id: context.id,
trace_id: context.trace_id,
sampled: context.sampled?,
baggage: context.baggage.merge({key => value})
)
self
Expand All @@ -94,6 +95,7 @@ def set_baggage(baggage = {})
@context = SpanContext.new(
id: context.id,
trace_id: context.trace_id,
sampled: context.sampled?,
baggage: baggage
)
end
Expand Down
14 changes: 14 additions & 0 deletions spec/lightstep_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ def init_callback_tracer(callback)
expect(child_span.span_context.baggage).to eq(parent_span.span_context.baggage)
end

it 'should inherit true sampled flag from parent span' do
tracer = init_test_tracer
parent_ctx = LightStep::SpanContext.new(id: LightStep.guid, trace_id: LightStep.guid, sampled: true)
child_span = tracer.start_span('child_span', child_of: parent_ctx)
expect(child_span.span_context).to be_sampled
end

it 'should inherit false sampled flag from parent span' do
tracer = init_test_tracer
parent_ctx = LightStep::SpanContext.new(id: LightStep.guid, trace_id: LightStep.guid, sampled: false)
child_span = tracer.start_span('child_span', child_of: parent_ctx)
expect(child_span.span_context).not_to be_sampled
end

it 'should allow operation_name updates' do
tracer = init_test_tracer
span = tracer.start_span('original')
Expand Down