Skip to content

Commit

Permalink
refactor: update tests to use context_with_span convenience method
Browse files Browse the repository at this point in the history
  • Loading branch information
mwear committed Sep 18, 2020
1 parent 6594a9e commit 0e6e622
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api/benchmarks/tracer_bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
tracer = OpenTelemetry::Trace::Tracer.new

parent_span = tracer.start_span('parent')
parent_context = tracer.with_span(parent_span) { |_, c| c }
parent_context = tracer.context_with_span(parent_span)

attributes = {
'component' => 'rack',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,17 @@

OpenTelemetry.tracer_provider.add_span_processor(processor)
root = with_ids(trace_id, root_span_id) { tracer.start_root_span('root', kind: :internal, start_timestamp: start_timestamp).finish(end_timestamp: end_timestamp) }
root_ctx = tracer.with_span(root) { |_, ctx| ctx }
root_ctx = tracer.context_with_span(root)
span = with_ids(trace_id, child_span_id) { tracer.start_span('child', with_parent: root_ctx, kind: :producer, start_timestamp: start_timestamp + 1, links: [OpenTelemetry::Trace::Link.new(root.context, 'attr' => 4)]) }
span['b'] = true
span['f'] = 1.1
span['i'] = 2
span['s'] = 'val'
span['a'] = [3, 4]
span.status = OpenTelemetry::Trace::Status.new(OpenTelemetry::Trace::Status::UNKNOWN_ERROR)
child_ctx = tracer.with_span(span) { |_, ctx| ctx }
child_ctx = tracer.context_with_span(span)
client = with_ids(trace_id, client_span_id) { tracer.start_span('client', with_parent: child_ctx, kind: :client, start_timestamp: start_timestamp + 2).finish(end_timestamp: end_timestamp) }
client_ctx = tracer.with_span(client) { |_, ctx| ctx }
client_ctx = tracer.context_with_span(client)
with_ids(trace_id, server_span_id) { other_tracer.start_span('server', with_parent: client_ctx, kind: :server, start_timestamp: start_timestamp + 3).finish(end_timestamp: end_timestamp) }
span.add_event('event', attributes: { 'attr' => 42 }, timestamp: start_timestamp + 4)
with_ids(trace_id, consumer_span_id) { tracer.start_span('consumer', with_parent: child_ctx, kind: :consumer, start_timestamp: start_timestamp + 5).finish(end_timestamp: end_timestamp) }
Expand Down
17 changes: 8 additions & 9 deletions sdk/test/integration/api_trace_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@
end

before do
@remote_span = tracer.start_span('remote', with_parent: context_with_remote_parent)
tracer.with_span(@remote_span) do |_, ctx|
@child_of_remote = tracer.start_span('child1', with_parent: ctx)
end
@remote_span = tracer.start_span('remote', with_parent: context_with_remote_parent))
@child_of_remote = tracer.start_span('child1', with_parent: tracer.context_with_span(@remote_span))

end

it 'has a child' do
Expand All @@ -70,11 +69,11 @@

describe 'tracing child-of-local spans' do
before do
tracer.in_span('local') do |parent|
@local_parent_span = parent
tracer.in_span('child1') do |child|
@child_of_local = child
end
@local_parent_span = tracer.start_span('local')
parent_ctx = tracer.context_with_span(@local_parent_span)
tracer.in_span('child1', with_parent: parent_ctx) do |child|
@child_of_local = child
end
end
end

Expand Down

0 comments on commit 0e6e622

Please sign in to comment.