Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 lib/instana/instrumentation/aws_sdk_sqs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/instana/instrumentation/grpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/instrumentation/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/instrumentation/net-http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/instana/instrumentation/rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/instrumentation/sidekiq-client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/instrumentation/sidekiq-worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions lib/instana/trace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
16 changes: 8 additions & 8 deletions lib/instana/trace/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand Down
14 changes: 7 additions & 7 deletions test/trace/custom_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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?

Expand Down
10 changes: 5 additions & 5 deletions test/trace/span_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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))
Expand Down
24 changes: 12 additions & 12 deletions test/trace/tracer_async_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -144,31 +144,31 @@ 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
# Current span should still be rack
# 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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions test/trace/tracer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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?

Expand Down Expand Up @@ -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"))
Expand Down
Loading