From 0e6e62229d1dc060c24fe6bcdacf0e67011e33dc Mon Sep 17 00:00:00 2001 From: Matthew Wear Date: Thu, 17 Sep 2020 20:52:14 -0700 Subject: [PATCH] refactor: update tests to use context_with_span convenience method --- api/benchmarks/tracer_bench.rb | 2 +- .../exporter/otlp/exporter_test.rb | 6 +++--- sdk/test/integration/api_trace_test.rb | 17 ++++++++--------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/api/benchmarks/tracer_bench.rb b/api/benchmarks/tracer_bench.rb index c197237a8..5a0f71401 100644 --- a/api/benchmarks/tracer_bench.rb +++ b/api/benchmarks/tracer_bench.rb @@ -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', diff --git a/exporter/otlp/test/opentelemetry/exporter/otlp/exporter_test.rb b/exporter/otlp/test/opentelemetry/exporter/otlp/exporter_test.rb index d8618ed80..e9a5dd932 100644 --- a/exporter/otlp/test/opentelemetry/exporter/otlp/exporter_test.rb +++ b/exporter/otlp/test/opentelemetry/exporter/otlp/exporter_test.rb @@ -154,7 +154,7 @@ 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 @@ -162,9 +162,9 @@ 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) } diff --git a/sdk/test/integration/api_trace_test.rb b/sdk/test/integration/api_trace_test.rb index 122e6a4cd..49f41a02e 100644 --- a/sdk/test/integration/api_trace_test.rb +++ b/sdk/test/integration/api_trace_test.rb @@ -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 @@ -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