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
12 changes: 8 additions & 4 deletions lib/instana/instrumentation/action_cable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ def transmit(data, via: nil)
}

context = connection.instana_trace_context
::Instana.tracer.start_or_continue_trace(:'rpc-server', rpc_tags, context) do
super(data, via: via)
Trace.with_span(OpenTelemetry::Trace.non_recording_span(context)) do
::Instana.tracer.in_span(:'rpc-server', attributes: rpc_tags) do
super(data, via: via)
end
end
end

Expand All @@ -44,8 +46,10 @@ def dispatch_action(action, data)
}

context = connection.instana_trace_context
::Instana.tracer.start_or_continue_trace(:'rpc-server', rpc_tags, context) do
super(action, data)
Trace.with_span(OpenTelemetry::Trace.non_recording_span(context)) do
::Instana.tracer.in_span(:'rpc-server', attributes: rpc_tags) do
super(action, data)
end
end
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/instana/instrumentation/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ def process_action(*args)
action: action_name
}
}

request.env['INSTANA_HTTP_PATH_TEMPLATE'] = matched_path_template
::Instana::Tracer.trace(:actioncontroller, call_payload) { super(*args) }
::Instana.tracer.in_span(:actioncontroller, attributes: call_payload) { super(*args) }
end

def render(*args, &block)
Expand All @@ -22,8 +21,7 @@ def render(*args, &block)
name: describe_render_options(args.first) || 'Default'
}
}

::Instana::Tracer.trace(:actionview, call_payload) { super(*args, &block) }
::Instana.tracer.in_span(:actionview, attributes: call_payload) { super(*args, &block) }
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/instrumentation/action_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def method_missing(method_name, *args) # rubocop:disable Style/MissingRespondToM
method: method_name.to_s
}
}
Instana::Tracer.trace(:'mail.actionmailer', tags) { super }
Instana.tracer.in_span(:'mail.actionmailer', attributes: tags) { super }
else
super
end
Expand Down
8 changes: 4 additions & 4 deletions lib/instana/instrumentation/action_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def render_partial(*args)
}
}

::Instana::Tracer.trace(:render, call_payload) { super(*args) }
::Instana.tracer.in_span(:render, attributes: call_payload) { super(*args) }
end

def render_collection(*args)
Expand All @@ -24,7 +24,7 @@ def render_collection(*args)
}
}

::Instana::Tracer.trace(:render, call_payload) { super(*args) }
::Instana.tracer.in_span(:render, attributes: call_payload) { super(*args) }
end

def render_partial_template(*args)
Expand All @@ -35,7 +35,7 @@ def render_partial_template(*args)
}
}

::Instana::Tracer.trace(:render, call_payload) { super(*args) }
::Instana.tracer.in_span(:render, attributes: call_payload) { super(*args) }
end
end

Expand All @@ -48,7 +48,7 @@ def render_collection(*args)
}
}

::Instana::Tracer.trace(:render, call_payload) { super(*args) }
::Instana.tracer.in_span(:render, attributes: call_payload) { super(*args) }
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/instana/instrumentation/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def self.prepended(target)
}

::Instana.tracer.in_span(:activejob, attributes: tags) do
instana_context = {}
OpenTelemetry::Trace::Propagation::TraceContext.text_map_propagator.inject(instana_context)
context = ::Instana.tracer.context
job.arguments.append(instana_context: instana_context)
job.arguments.append({
instana_context: context ? context.to_hash : nil
})

block.call
end
Expand All @@ -53,7 +53,7 @@ def self.prepended(target)
job.arguments.pop
instana_context ? ::Instana::SpanContext.new(trace_id: instana_context[:trace_id], span_id: instana_context[:span_id]) : nil
end
OpenTelemetry::Context.with_current(instana_context ? OpenTelemetry::Trace::Propagation::TraceContext.text_map_propagator.extract(instana_context) : OpenTelemetry::Context.current) do
Trace.with_span(OpenTelemetry::Trace.non_recording_span(incoming_context)) do
::Instana.tracer.in_span(:activejob, attributes: tags) do
block.call
end
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/instrumentation/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def maybe_sanitize(sql)

def maybe_trace(call_payload, name, &blk)
if ::Instana.tracer.tracing? && !ignored?(call_payload, name)
::Instana.tracer.trace(:activerecord, call_payload, &blk)
::Instana.tracer.in_span(:activerecord, attributes: call_payload, &blk)
else
yield
end
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/instrumentation/aws_sdk_dynamodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def call(context)
table: table_name_from(context)
}

::Instana.tracer.trace(:dynamodb, {dynamodb: dynamo_tags}) { @handler.call(context) }
::Instana.tracer.in_span(:dynamodb, attributes: {dynamodb: dynamo_tags}) { @handler.call(context) }
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/instrumentation/aws_sdk_lambda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def call(context)
type: context.params[:invocation_type]
}.reject { |_, v| v.nil? }

::Instana.tracer.start_or_continue_trace(:"aws.lambda.invoke", {aws: {lambda: {invoke: tags}}}) do
::Instana.tracer.in_span(:"aws.lambda.invoke", attributes: {aws: {lambda: {invoke: tags}}}) do
response = @handler.call(context)
if response.respond_to? :status_code
::Instana.tracer.log_info(:http => {:status => response.status_code })
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/instrumentation/aws_sdk_s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def call(context)
key: key_from_context(context)
}.reject { |_, v| v.nil? }

::Instana.tracer.trace(:s3, {s3: s3_tags}) { @handler.call(context) }
::Instana.tracer.in_span(:s3, attributes: {s3: s3_tags}) { @handler.call(context) }
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/instrumentation/aws_sdk_sns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def call(context)
}.reject { |_, v| v.nil? }

if context.operation_name == :publish
::Instana.tracer.trace(:sns, {sns: sns_tags}) { @handler.call(context) }
::Instana.tracer.in_span(:sns, attributes: {sns: sns_tags}) { @handler.call(context) }
else
@handler.call(context)
end
Expand Down
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 @@ -15,7 +15,7 @@ def call(context)

span_tags = tags_for(context.operation_name, context.params).reject { |_, v| v.nil? }

::Instana.tracer.trace(:sqs, {sqs: span_tags}) do |span|
::Instana.tracer.in_span(:sqs, attributes: {sqs: span_tags}) do |span|
case context.operation_name
when :send_message
inject_instana_headers(span, context.params)
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/instrumentation/dalli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def perform(*args, &blk)
entry_payload[:memcache][:command] = op
entry_payload[:memcache][:key] = key

::Instana.tracer.log_entry(:memcache, entry_payload)
::Instana.tracer.start_span(:memcache, attributes: entry_payload)
exit_payload = { :memcache => {} }

result = super(*args, &blk)
Expand Down
4 changes: 2 additions & 2 deletions lib/instana/instrumentation/excon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def request_call(datum)
if datum[:pipeline] == true
# Pass the context along in the datum so we get back on response
# and can close out the async span
datum[:instana_span] = ::Instana.tracer.log_async_entry(:excon, payload)
datum[:instana_span] = ::Instana.tracer.start_span(:excon, attributes: payload)
t_context = datum[:instana_span].context
else
::Instana.tracer.log_entry(:excon, payload)
::Instana.tracer.start_span(:excon, attributes: payload)
t_context = ::Instana.tracer.context
end

Expand Down
6 changes: 3 additions & 3 deletions lib/instana/instrumentation/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ def platform_trace(platform_key, key, data)
}

begin
::Instana.tracer.log_entry(:'graphql.server')
span = ::Instana.tracer.start_span(:'graphql.server', attributes: {graphql: payload})
yield
rescue Exception => e
::Instana.tracer.log_error(e)
span.record_exception(e)
raise e
ensure
::Instana.tracer.log_exit(:'graphql.server', {graphql: payload})
span.finish
end
end

Expand Down
27 changes: 14 additions & 13 deletions lib/instana/instrumentation/grpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module GRPCCientInstrumentation
kvs[:rpc][:call] = method
kvs[:rpc][:call_type] = call_type

::Instana.tracer.log_entry(:'rpc-client', kvs)
current_span = ::Instana.tracer.start_span(:'rpc-client', attributes: kvs)

context = ::Instana.tracer.context
if context
Expand All @@ -35,11 +35,11 @@ module GRPCCientInstrumentation
super(method, *others, **options)
rescue => e
kvs[:rpc][:error] = true
::Instana.tracer.log_info(kvs)
::Instana.tracer.log_error(e)
current_span.set_tags(kvs)
current_span.record_exception(e)
raise
ensure
::Instana.tracer.log_exit(:'rpc-client', {})
current_span.finish
end
end
end
Expand All @@ -60,9 +60,9 @@ module GRPCServerInstrumentation

incoming_context = {}
if metadata.key?('x-instana-t')
incoming_context[:trace_id] = ::Instana::Util.header_to_id(metadata['x-instana-t'])
incoming_context[:span_id] = ::Instana::Util.header_to_id(metadata['x-instana-s']) if metadata.key?('x-instana-s')
incoming_context[:level] = metadata['x-instana-l'] if metadata.key?('x-instana-l')
incoming_context = SpanContext.new(trace_id: ::Instana::Util.header_to_id(metadata['x-instana-t']),
span_id: metadata.key?('x-instana-s') ? ::Instana::Util.header_to_id(metadata['x-instana-s']) : nil,
level: metadata.key?('x-instana-l') ? metadata['x-instana-l'] : nil)
end

kvs[:rpc][:flavor] = :grpc
Expand All @@ -71,18 +71,19 @@ module GRPCServerInstrumentation
kvs[:rpc][:call_type] = call_type
kvs[:rpc][:peer] = { address: active_call.peer }

::Instana.tracer.log_start_or_continue(
:'rpc-server', kvs, incoming_context
)
span = OpenTelemetry::Trace.non_recording_span(incoming_context) if incoming_context
parent_context = Trace.context_with_span(span) if incoming_context

current_span = ::Instana.tracer.start_span(:'rpc-server', attributes: kvs, with_parent: parent_context)

super(active_call, mth, *others)
rescue => e
kvs[:rpc][:error] = true
::Instana.tracer.log_info(kvs)
::Instana.tracer.log_error(e)
current_span.set_tags(kvs)
current_span.record_exception(e)
raise
ensure
::Instana.tracer.log_end(:'rpc-server', {}) if ::Instana.tracer.tracing?
current_span.finish if ::Instana.tracer.tracing?
end
end
end
Expand Down
9 changes: 5 additions & 4 deletions lib/instana/instrumentation/net-http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def request(*args, &block)
return super(*args, &block)
end

::Instana.tracer.log_entry(:'net-http')
current_span = ::Instana.tracer.start_span(:'net-http')

# Send out the tracing context with the request
request = args[0]
Expand Down Expand Up @@ -54,15 +54,16 @@ def request(*args, &block)
if response.code.to_i >= 500
# Because of the 5xx response, we flag this span as errored but
# without a backtrace (no exception)
::Instana.tracer.log_error(nil)
current_span.record_exception(nil)
end

response
rescue => e
::Instana.tracer.log_error(e)
current_span.record_exception(e)
raise
ensure
::Instana.tracer.log_exit(:'net-http', kv_payload) unless do_skip
current_span.set_tags(kv_payload)
current_span.finish unless do_skip
end

def skip_instrumentation?
Expand Down
30 changes: 26 additions & 4 deletions lib/instana/instrumentation/rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,28 @@ def call(env)
http: req.request_tags
}.reject { |_, v| v.nil? }

current_span = ::Instana.tracer.log_start_or_continue(:rack, {}, req.incoming_context)
incoming_context = req.incoming_context
if incoming_context
if incoming_context.is_a?(Hash)
unless incoming_context.empty?
parent_context = SpanContext.new(
trace_id: incoming_context[:trace_id],
span_id: incoming_context[:span_id],
level: incoming_context[:level],
baggage: {
external_trace_id: incoming_context[:external_trace_id],
external_state: incoming_context[:external_state]
}
)
end
else
parent_context = incoming_context
end
end

span = OpenTelemetry::Trace.non_recording_span(parent_context) if parent_context
parent_context = Trace.context_with_span(span) if parent_context
current_span = ::Instana.tracer.start_span(:rack, attributes: {}, with_parent: parent_context)

status, headers, response = @app.call(env)

Expand Down Expand Up @@ -66,7 +87,7 @@ def call(env)

[status, headers, response]
rescue Exception => e
::Instana.tracer.log_error(e) if ::Instana.tracer.tracing?
current_span.record_exception(e) if ::Instana.tracer.tracing?
raise
ensure
if ::Instana.tracer.tracing?
Expand All @@ -85,8 +106,9 @@ def call(env)
headers['Traceparent'] = trace_context.trace_parent_header
headers['Server-Timing'] = "intid;desc=#{trace_context.trace_id_header}"
end

::Instana.tracer.log_end(:rack, kvs)
current_span.set_tags(kvs)
current_span.close(::Instana::Util.now_in_ms)
::Instana.tracer.current_span = nil
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/instana/instrumentation/sequel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Instana
module Instrumentation
module Sequel
IGNORED_SQL = %w[BEGIN COMMIT SET].freeze
IGNORED_SQL = %w[BEGIN COMMIT SET PRAGMA].freeze
VERSION_SELECT_STATEMENT = "SELECT VERSION()".freeze
SANITIZE_REGEXP = /('[\s\S][^']*'|\d*\.\d+|\d+|NULL)/i

Expand All @@ -26,9 +26,9 @@ def maybe_sanitize(sql)
::Instana.config[:sanitize_sql] ? sql.gsub(SANITIZE_REGEXP, '?') : sql
end

def maybe_trace(call_payload, &blk)
def maybe_trace(call_payload, &block)
if ::Instana.tracer.tracing? && !ignored?(call_payload)
::Instana.tracer.trace(:sequel, call_payload, &blk)
::Instana.tracer.in_span(:sequel, attributes: call_payload, &block)
else
yield
end
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def context_with_span(span, parent_context: OpenTelemetry::Context.current)
# @param [Span] span the span to activate
# @yield [span, context] yields span and a context containing the span to the block.
def with_span(span)
Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c }
OpenTelemetry::Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c }
end

# Wraps a SpanContext with an object implementing the Span interface. This is done in order
Expand Down
8 changes: 8 additions & 0 deletions lib/instana/trace/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,15 @@ def clear!
self.current_span = nil
end

def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
return if !::Instana.agent.ready? || !::Instana.config[:tracing][:enabled]

super
end

def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: ::Instana::Util.now_in_ms, kind: nil) # rubocop:disable Metrics/ParameterLists
return if !::Instana.agent.ready? || !::Instana.config[:tracing][:enabled]

with_parent ||= OpenTelemetry::Context.current
name ||= 'empty'
kind ||= :internal
Expand Down
Loading