diff --git a/lib/instana/instrumentation/aws_sdk_sqs.rb b/lib/instana/instrumentation/aws_sdk_sqs.rb index 855d9071..b1f9790b 100644 --- a/lib/instana/instrumentation/aws_sdk_sqs.rb +++ b/lib/instana/instrumentation/aws_sdk_sqs.rb @@ -26,7 +26,7 @@ def call(context) response = @handler.call(context) span_tags[:queue] = response.queue_url if response.respond_to?(:queue_url) - span.set_tags(sqs: span_tags) + span.add_attributes(sqs: span_tags) response end diff --git a/lib/instana/instrumentation/grpc.rb b/lib/instana/instrumentation/grpc.rb index 40180747..57dfb4c0 100644 --- a/lib/instana/instrumentation/grpc.rb +++ b/lib/instana/instrumentation/grpc.rb @@ -35,7 +35,7 @@ module GRPCCientInstrumentation super(method, *others, **options) rescue => e kvs[:rpc][:error] = true - current_span.set_tags(kvs) + current_span.add_attributes(kvs) current_span.record_exception(e) raise ensure @@ -79,7 +79,7 @@ module GRPCServerInstrumentation super(active_call, mth, *others) rescue => e kvs[:rpc][:error] = true - current_span.set_tags(kvs) + current_span.add_attributes(kvs) current_span.record_exception(e) raise ensure diff --git a/lib/instana/instrumentation/mongo.rb b/lib/instana/instrumentation/mongo.rb index 39644e1e..6f59ac53 100644 --- a/lib/instana/instrumentation/mongo.rb +++ b/lib/instana/instrumentation/mongo.rb @@ -25,7 +25,7 @@ def started(event) def failed(event) span = @requests.delete(event.request_id) - span.add_error(Exception.new(event.message)) + span.record_exception(Exception.new(event.message)) span.finish end diff --git a/lib/instana/instrumentation/net-http.rb b/lib/instana/instrumentation/net-http.rb index 2301a266..1672a4e9 100644 --- a/lib/instana/instrumentation/net-http.rb +++ b/lib/instana/instrumentation/net-http.rb @@ -63,7 +63,7 @@ def request(*args, &block) current_span&.record_exception(e) raise ensure - current_span&.set_tags(kv_payload) + current_span&.add_attributes(kv_payload) current_span&.finish unless do_skip end diff --git a/lib/instana/instrumentation/rack.rb b/lib/instana/instrumentation/rack.rb index 11b81a7a..e0007a8e 100644 --- a/lib/instana/instrumentation/rack.rb +++ b/lib/instana/instrumentation/rack.rb @@ -122,7 +122,7 @@ def merge_response_headers(kvs, headers) def finalize_trace(current_span, kvs, headers, trace_context) set_response_headers(headers, trace_context) if headers - current_span.set_tags(kvs) + current_span.add_attributes(kvs) OpenTelemetry::Context.detach(@trace_token) if @trace_token current_span.finish end diff --git a/lib/instana/instrumentation/sidekiq-client.rb b/lib/instana/instrumentation/sidekiq-client.rb index e59c063a..8c224736 100644 --- a/lib/instana/instrumentation/sidekiq-client.rb +++ b/lib/instana/instrumentation/sidekiq-client.rb @@ -36,7 +36,7 @@ def call(worker_class, msg, queue, _redis_pool) result = yield if result && result['jid'] - span.set_tag(:'sidekiq-client', { job_id: result['jid'] }) + span.set_attribute(:'sidekiq-client', { job_id: result['jid'] }) end result diff --git a/lib/instana/instrumentation/sidekiq-worker.rb b/lib/instana/instrumentation/sidekiq-worker.rb index 19ad68ac..932e1d1b 100644 --- a/lib/instana/instrumentation/sidekiq-worker.rb +++ b/lib/instana/instrumentation/sidekiq-worker.rb @@ -43,7 +43,7 @@ def call(_worker, msg, _queue) yield rescue => e kvs[:'sidekiq-worker'][:error] = true - span.set_tags(kvs) + span.add_attributes(kvs) span.record_exception(e) raise end diff --git a/lib/instana/trace/span.rb b/lib/instana/trace/span.rb index c681abf7..4d6d45e1 100644 --- a/lib/instana/trace/span.rb +++ b/lib/instana/trace/span.rb @@ -67,7 +67,7 @@ def initialize(name, parent_ctx = nil, _context = nil, parent_span = nil, _kind else configure_custom(name) end - set_tags(attributes) + add_attributes(attributes) ::Instana.processor.on_start(self) # Attach a backtrace to all exit spans add_stack if should_collect_stack_trace? @@ -450,8 +450,7 @@ def recording? # # @return [self] returns itself def set_attribute(key, value) - @attributes ||= {} - @attributes[key] = value + set_tag(key, value) self end # alias []= set_attribute @@ -470,8 +469,11 @@ def set_attribute(key, value) # # @return [self] returns itself def add_attributes(attributes) - @attributes ||= {} - @attributes.merge!(attributes) + return unless attributes.is_a?(Hash) + + attributes.each do |k, v| + set_tag(k, v) + end self end diff --git a/lib/instana/trace/tracer.rb b/lib/instana/trace/tracer.rb index 712e4f5d..3f7a08f3 100644 --- a/lib/instana/trace/tracer.rb +++ b/lib/instana/trace/tracer.rb @@ -124,7 +124,7 @@ def log_start_or_continue(name, kvs = {}, incoming_context = nil) Span.new(name) end - current_span.set_tags(kvs) unless kvs.empty? + current_span.add_attributes(kvs) unless kvs.empty? current_span end @@ -142,7 +142,7 @@ def log_entry(name, kvs = nil, _start_time = ::Instana::Util.now_in_ms, child_of else Span.new(name, child_of) end - new_span.set_tags(kvs) if kvs + new_span.add_attributes(kvs) if kvs self.current_span = new_span end @@ -153,7 +153,7 @@ def log_entry(name, kvs = nil, _start_time = ::Instana::Util.now_in_ms, child_of def log_info(kvs) return unless current_span - current_span.set_tags(kvs) + current_span.add_attributes(kvs) end # Add an error to the current span @@ -181,7 +181,7 @@ def log_exit(name, kvs = {}) @logger.warn "Span mismatch: Attempt to end #{name} span but #{current_span.name} is active." end - current_span.set_tags(kvs) + current_span.add_attributes(kvs) current_span.close self.current_span = current_span.parent || nil @@ -203,7 +203,7 @@ def log_end(name, kvs = {}, end_time = ::Instana::Util.now_in_ms) @logger.warn "Span mismatch: Attempt to end #{name} span but #{current_span.name} is active." end - current_span.set_tags(kvs) + current_span.add_attributes(kvs) current_span.close(end_time) self.current_span = nil end @@ -225,7 +225,7 @@ def log_async_entry(name, kvs) return unless tracing? new_span = Span.new(name, current_span) - new_span.set_tags(kvs) unless kvs.empty? + new_span.add_attributes(kvs) unless kvs.empty? new_span end @@ -235,7 +235,7 @@ def log_async_entry(name, kvs) # @param span [Span] the span for this Async op (previously returned from `log_async_entry`) # def log_async_info(kvs, span) - span.set_tags(kvs) + span.add_attributes(kvs) end # Add an error to an asynchronous span @@ -254,7 +254,7 @@ def log_async_error(error, span) # @param span [Span] the span for this Async op (previously returned from `log_async_entry`) # def log_async_exit(_name, kvs, span) - span.set_tags(kvs) unless kvs.empty? + span.add_attributes(kvs) unless kvs.empty? span.close end diff --git a/test/trace/custom_test.rb b/test/trace/custom_test.rb index 4e8d7b97..2b263874 100644 --- a/test/trace/custom_test.rb +++ b/test/trace/custom_test.rb @@ -62,13 +62,13 @@ def test_custom_tracing_with_nested_automagic ::Instana.tracer.in_span(:custom_span, attributes: kvs) do answer = 42 * 1 active_span = ::Instana.tracer.current_span - active_span.set_tag(:answer, answer) + active_span.set_attribute(:answer, answer) # And now nested automagic ::Instana.tracer.in_span(:custom_span2, attributes: kvs) do was_here = 'stan' active_span = ::Instana.tracer.current_span - active_span.set_tag(:was_here, was_here) + active_span.set_attribute(:was_here, was_here) end end @@ -122,12 +122,12 @@ def test_custom_tracing_with_args kvs[:return] = true span2 = ::Instana.tracer.start_span(:custom_span, attributes: kvs) - span2.set_tags({:on_info_kv => 1}) - span2.set_tags({:on_exit_kv => 1}) + span2.add_attributes({:on_info_kv => 1}) + span2.add_attributes({:on_exit_kv => 1}) span2.finish # End tracing - span1.set_tags({:on_trace_end => 1}) + span1.add_attributes({:on_trace_end => 1}) span1.finish assert_equal false, ::Instana.tracer.tracing? @@ -183,10 +183,10 @@ def test_custom_tracing_with_error # rubocop:disable Metrics/MethodLength rescue => e span2.record_exception(e) ensure - span2.set_tags(:on_exit_kv => 1) + span2.add_attributes(:on_exit_kv => 1) span2.finish end - span1.set_tags(:on_trace_end => 1) + span1.add_attributes(:on_trace_end => 1) span1.finish assert_equal false, ::Instana.tracer.tracing? diff --git a/test/trace/span_test.rb b/test/trace/span_test.rb index 48b6fc62..01ba2a5d 100644 --- a/test/trace/span_test.rb +++ b/test/trace/span_test.rb @@ -91,7 +91,7 @@ def inner(depth = 50, &blk) # rubocop:disable Lint/NestedMethodDefinition def test_multiple_errors span = Instana::Span.new(:activerecord) - span.set_tag(:activerecord, {}) + span.set_attribute(:activerecord, {}) span.record_exception(StandardError.new('Test1')) span.record_exception(StandardError.new('Test2')) @@ -109,20 +109,20 @@ def test_record_exception_nil def test_set_tag_merge span = Instana::Span.new(:excon) - span.set_tag(1024, {a: 1}) - span.set_tag(1024, {b: 2}) + span.set_attribute(1024, {a: 1}) + span.set_attribute(1024, {b: 2}) assert_equal({'1024' => {a: 1, b: 2}}, span[:data]) end def test_set_tags_non_hash span = Instana::Span.new(:excon) - assert_nil span.set_tags(0) + assert_nil span.add_attributes(0) end def test_tags_standard span = Instana::Span.new(:excon) - span.set_tag(:test, {a: 1}) + span.set_attribute(:test, {a: 1}) assert_equal({test: {a: 1}}, span.tags) assert_equal({a: 1}, span.tags(:test)) diff --git a/test/trace/tracer_async_test.rb b/test/trace/tracer_async_test.rb index 360ec7a5..ac89a536 100644 --- a/test/trace/tracer_async_test.rb +++ b/test/trace/tracer_async_test.rb @@ -70,14 +70,14 @@ def test_diff_thread_async_tracing # Sleep beyond the end of this root trace sleep 0.5 - span2.set_tags({ :wake_up => 1}) + span2.add_attributes({ :wake_up => 1}) span2.finish - span1.set_tags({:async_end => 1}) + span1.add_attributes({:async_end => 1}) span1.finish end # Current span should still be rack assert_equal :rack, ::Instana.tracer.current_span.name - span.set_tags({:rack_end_kv => 1}) + span.add_attributes({:rack_end_kv => 1}) span.finish # End tracing # ::Instana.tracer.log_end(:rack, {:rack_end_kv => 1}) @@ -144,18 +144,18 @@ def test_out_of_order_async_tracing # assert_equal :rack, ::Instana.tracer.current_span.name # Log info to the async spans (out of order) - span2.set_tags({ :info_kv => 2 }) - span1.set_tags({ :info_kv => 1 }) - span3.set_tags({ :info_kv => 3 }) + span2.add_attributes({ :info_kv => 2 }) + span1.add_attributes({ :info_kv => 1 }) + span3.add_attributes({ :info_kv => 3 }) # Log out of order errors to the async spans span3.record_exception(Exception.new("Async span 3")) span2.record_exception(Exception.new("Async span 3")) # End two out of order asynchronous spans - span3.set_tags({ :exit_kv => 3 }) + span3.add_attributes({ :exit_kv => 3 }) span3.close - span2.set_tags({ :exit_kv => 2 }) + span2.add_attributes({ :exit_kv => 2 }) span2.close # Context awareness when using Opentelemetry is done through Opentelemetry::Context so the below test is invalid @@ -163,12 +163,12 @@ def test_out_of_order_async_tracing # assert_equal :rack, ::Instana.tracer.current_span.name # End tracing - span.set_tags({:rack_end_kv => 1}) + span.add_attributes({:rack_end_kv => 1}) span.finish # Log an error to and close out the remaining async span after the parent trace has finished span1.record_exception(Exception.new("Async span 1")) - span1.set_tags({ :exit_kv => 1 }) + span1.add_attributes({ :exit_kv => 1 }) span1.close spans = ::Instana.processor.queued_spans @@ -216,7 +216,7 @@ def test_async_helpers ::Instana.tracer.start_span(:rack) span1 = ::Instana.tracer.start_span(:async, attributes: {}) - span1.set_tags({a: 1}) + span1.add_attributes({a: 1}) span1.record_exception(StandardError.new('Error')) span1.finish @@ -232,7 +232,7 @@ def test_async_helpers_tag_exit ::Instana.tracer.start_span(:rack) span1 = ::Instana.tracer.start_span(:async, attributes: {}) - span1.set_tags({a: 1}) + span1.add_attributes({a: 1}) span1.finish spans = ::Instana.processor.queued_spans diff --git a/test/trace/tracer_test.rb b/test/trace/tracer_test.rb index 983bd03b..73e2db97 100644 --- a/test/trace/tracer_test.rb +++ b/test/trace/tracer_test.rb @@ -169,9 +169,9 @@ def test_basic_low_level_tracing # Start tracing span = ::Instana.tracer.start_span(:rack, attributes: {:one => 1}) assert_equal true, ::Instana.tracer.tracing? - span.set_tags({:info_logged => 1}) + span.add_attributes({:info_logged => 1}) # End tracing - span.set_tags({:close_one => 1}) + span.add_attributes({:close_one => 1}) span.finish assert_equal false, ::Instana.tracer.tracing? @@ -187,22 +187,22 @@ def test_complex_low_level_tracing # Start tracing span = ::Instana.tracer.start_span(:rack, attributes: {:one => 1}) assert_equal true, ::Instana.tracer.tracing? - span.set_tags({:info_logged => 1}) + span.add_attributes({:info_logged => 1}) # Start tracing a sub span with context propagation span1 = ::Instana::Trace.with_span(span) do ::Instana.tracer.start_span(:sub_task) end assert_equal true, ::Instana.tracer.tracing? - span1.set_tags({:sub_task_info => 1}) + span1.add_attributes({:sub_task_info => 1}) # Exit from the sub span - span1.set_tags({:sub_task_exit_info => 1}) + span1.add_attributes({:sub_task_exit_info => 1}) span1.finish assert_equal true, ::Instana.tracer.tracing? # End tracing - span.set_tags({:close_one => 1}) + span.add_attributes({:close_one => 1}) span.finish assert_equal false, ::Instana.tracer.tracing? @@ -262,9 +262,9 @@ def test_block_tracing_error_capture def test_low_level_error_logging clear_all! span = ::Instana.tracer.start_span(:test_trace, attributes: {:one => 1}) - span.set_tags({:info_logged => 1}) + span.add_attributes({:info_logged => 1}) span.record_exception(Exception.new("Low level tracing api error")) - span.set_tags({:close_one => 1}) + span.add_attributes({:close_one => 1}) span.finish # ::Instana.tracer.log_info({:info_logged => 1}) # ::Instana.tracer.log_error(Exception.new("Low level tracing api error"))