Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
5f56025
feat: change opentracing to otel
arjun-rajappa Feb 12, 2025
586bf13
feat: change opentracing to otel
arjun-rajappa Feb 12, 2025
d017f13
otel: adding otel-api to gemfile
arjun-rajappa Mar 4, 2025
d8d1290
otel: adapt instana tracer to otel standards and add tracer_provider …
arjun-rajappa Mar 4, 2025
b2f017b
otel: add otel-api as runtime dependency
arjun-rajappa Mar 4, 2025
ceb3ba1
otel: add otel-api as runtime dependency
arjun-rajappa Mar 4, 2025
351c56f
otel: fix tracer init tests
arjun-rajappa Mar 5, 2025
8a3c0d0
otel: fix rubocop lint failures
arjun-rajappa Mar 5, 2025
364a1b1
otel: fix rubocop lint failures
arjun-rajappa Mar 5, 2025
bd0aee4
otel: change license headers
arjun-rajappa Mar 19, 2025
28bcb9f
otel: move constanats to span_kind module
arjun-rajappa Mar 19, 2025
c148a57
otel: remove commented initializer
arjun-rajappa Mar 19, 2025
f4a9b27
otel: change data to attributes
arjun-rajappa Mar 10, 2025
1152f23
otel: remove the old tracer
arjun-rajappa Mar 7, 2025
cf66e68
otel: change the span context init to add new args
arjun-rajappa Mar 10, 2025
bf35983
otel: span structure change
arjun-rajappa Mar 11, 2025
8183908
otel: make trace provider to work with 'in_span' method
arjun-rajappa Mar 11, 2025
654bfe1
otel: make trace provider to work with 'in_span' method
arjun-rajappa Mar 11, 2025
8c4ee9c
otel: change constructor signature for instana span
arjun-rajappa Mar 18, 2025
90da1d4
otel: change constructor signature for instana span
arjun-rajappa Mar 18, 2025
a8e7a66
otel: change span init
arjun-rajappa Mar 14, 2025
bdbd8c0
otel: change span init
arjun-rajappa Mar 14, 2025
d2f792b
otel: tests change span context init
arjun-rajappa Mar 13, 2025
f7bb9de
otel: add OTel commons lib as dependency
arjun-rajappa Mar 25, 2025
bf753e5
otel: add OTel commons lib as dependency
arjun-rajappa Mar 25, 2025
1d025cc
otel: add OTel commons lib as dependency
arjun-rajappa Mar 25, 2025
34afdf4
otel: change arguments to init of span context
arjun-rajappa Apr 9, 2025
ef1bb9c
otel: change arguments to init of span context
arjun-rajappa Apr 9, 2025
9e5df70
Squashed commit of the following:
arjun-rajappa Jun 23, 2025
6d97010
Otel add samplers misc (#454)
arjun-rajappa Jun 23, 2025
9fdc504
otel: change instrumentations to use OTel methods
arjun-rajappa Jul 3, 2025
547414f
otel: fix grpc failures and linting failures
arjun-rajappa Jul 3, 2025
101ad9f
otel: update tests of dalli to use new otel methods
arjun-rajappa Jul 3, 2025
decdfe9
otel: add cleanup before every test
arjun-rajappa Jul 7, 2025
9ae2b87
otel: add safe operatiors when the tracing is skipped
arjun-rajappa Jul 7, 2025
ac8b682
otel: use otel specified methods
arjun-rajappa Jul 7, 2025
b6145b9
otel: change instrumentation of rest-client to use otel specification
arjun-rajappa Jul 7, 2025
84320c9
otel: change mongo instrumentation to use otel specification
arjun-rajappa Jul 8, 2025
1d7dffb
otel: add clear all before running the tests
arjun-rajappa Jul 9, 2025
f60a44a
otel: add clear all before running the tests
arjun-rajappa Jul 9, 2025
86c0efc
otel: alsways return nil if there is no current span
arjun-rajappa Jul 15, 2025
3270ac7
otel: use in_span in tests
arjun-rajappa Jul 15, 2025
0d7d420
otel: use in_span in tests
arjun-rajappa Jul 15, 2025
01efc2e
otel: use otel methods on resque instrumentation
arjun-rajappa Jul 17, 2025
2c6e965
otel: use parent span link which comes from otel
arjun-rajappa Jul 17, 2025
87b0dc8
otel: sidekiq instrumentation use otel specified methods
arjun-rajappa Jul 17, 2025
6bb49e8
otel: change to rack instrumentation for context propagation
arjun-rajappa Jul 17, 2025
a6b228b
otel: use otel standard methods on shoryuken intrumentation
arjun-rajappa Jul 21, 2025
e8469bf
otel: use otel specified methods for serverless instrumentation
arjun-rajappa Jul 23, 2025
692ebf7
otel: use otel methods in rails tests
arjun-rajappa Jul 23, 2025
a52270a
otel: adapt tests to use otel specified methods
arjun-rajappa Jul 23, 2025
cab4719
otel: fix async tests
arjun-rajappa Jul 23, 2025
95ee628
otel: move context ectraction to a different method
arjun-rajappa Jul 24, 2025
e1fd0d8
otel: fix linting through rubocop
arjun-rajappa Jul 24, 2025
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
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ gem 'simplecov', '~> 0.21.2'

# instana.gemspec
gemspec

gem "opentelemetry-api", "~> 1.4"

gem "rubocop", "~> 1.71"
gem "opentelemetry-common", "~> 0.22.0"
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Rake::TestTask.new(:test) do |t|
else
t.test_files = Dir[
'test/*_test.rb',
'test/{agent,tracing,backend,snapshot}/*_test.rb'
'test/{agent,trace,backend,snapshot}/*_test.rb'
]
end
end
Expand Down
8 changes: 4 additions & 4 deletions examples/opentracing.rb → examples/otel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
entry_span.set_tag(:'span.kind', "entry")

intermediate_span = OpenTracing.start_span("myintermediate", :child_of => entry_span)
intermediate_span.finish()
intermediate_span.finish

db_span = OpenTracing.start_span('mydbspan', :child_of => entry_span)
db_span.set_tag(:'db.instance', "users")
db_span.set_tag(:'db.statement', "SELECT * FROM user_table")
db_span.set_tag(:'db.type', "mysql")
db_span.set_tag(:'db.user', "mysql_login")
db_span.set_tag(:'span.kind', "exit")
db_span.finish()
db_span.finish

intermediate_span = OpenTracing.start_span("myintermediate", :child_of => entry_span)
intermediate_span.log("ALLOK", :message => "All seems ok")
intermediate_span.finish()
intermediate_span.finish

entry_span.set_tag(:'http.status_code', 200)
entry_span.finish()
entry_span.finish
1 change: 1 addition & 0 deletions examples/tracing.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file outlines the Instana Ruby Tracing API.
#
# Replace the below line once otel based standards are implemended
# This same tracer also supports OpenTracing. See `opentracing.rb` for
# separate documentation.

Expand Down
2 changes: 2 additions & 0 deletions instana.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency('concurrent-ruby', '>= 1.1')
spec.add_runtime_dependency('csv', '>= 0.1')
spec.add_runtime_dependency('sys-proctable', '>= 1.2.2')
spec.add_runtime_dependency('opentelemetry-api', '~> 1.4')
spec.add_runtime_dependency('opentelemetry-common')
spec.add_runtime_dependency('oj', '>=3.0.11') unless RUBY_PLATFORM =~ /java/i
end
6 changes: 4 additions & 2 deletions lib/instana/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class << self
attr_accessor :pid
attr_reader :secrets
attr_reader :serverless
attr_accessor :tracer_provider

##
# setup
Expand All @@ -22,8 +23,9 @@ class << self
# to run" state.
#
def setup
@agent = ::Instana::Backend::Agent.new
@tracer = ::Instana::Tracer.new
@agent = ::Instana::Backend::Agent.new
@tracer_provider = ::Instana::Trace::TracerProvider.new
@tracer = @tracer_provider.tracer('instana_tracer')
@processor = ::Instana::Processor.new
@secrets = ::Instana::Secrets.new
@serverless = ::Instana::Serverless.new
Expand Down
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
25 changes: 20 additions & 5 deletions lib/instana/instrumentation/active_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021
module OpenTelemetry
module Trace
module Propagation
module TraceContext
# A TraceParent is an implementation of the W3C trace context specification
# https://www.w3.org/TR/trace-context/
# {Trace::SpanContext}
class TraceParent
REGEXP = /^(?<version>[A-Fa-f0-9]{2})-(?<trace_id>[A-Fa-f0-9]{32})-(?<span_id>[A-Fa-f0-9]{32})-(?<flags>[A-Fa-f0-9]{2})(?<ignored>-.*)?$/
end
end
end
end
end

module Instana
module Instrumentation
Expand All @@ -15,7 +29,7 @@ def self.prepended(target)
}
}

::Instana::Tracer.trace(:activejob, tags) do
::Instana.tracer.in_span(:activejob, attributes: tags) do
context = ::Instana.tracer.context
job.arguments.append({
instana_context: context ? context.to_hash : nil
Expand All @@ -37,11 +51,12 @@ def self.prepended(target)
incoming_context = if job.arguments.is_a?(Array) && job.arguments.last.is_a?(Hash) && job.arguments.last.key?(:instana_context)
instana_context = job.arguments.last[:instana_context]
job.arguments.pop
instana_context ? ::Instana::SpanContext.new(instana_context[:trace_id], instana_context[:span_id]) : nil
instana_context ? ::Instana::SpanContext.new(trace_id: instana_context[:trace_id], span_id: instana_context[:span_id]) : nil
end

::Instana::Tracer.start_or_continue_trace(:activejob, tags, incoming_context) do
block.call
Trace.with_span(OpenTelemetry::Trace.non_recording_span(incoming_context)) do
::Instana.tracer.in_span(:activejob, attributes: tags) do
block.call
end
end
end
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
6 changes: 3 additions & 3 deletions lib/instana/instrumentation/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ def started(event)
json: filter_statement(event.command)
}

@requests[event.request_id] = ::Instana.tracer.log_async_entry(:mongo, {mongo: tags})
@requests[event.request_id] = ::Instana.tracer.start_span(:mongo, attributes: {mongo: tags})
end

def failed(event)
span = @requests.delete(event.request_id)
span.add_error(Exception.new(event.message))

::Instana.tracer.log_async_exit(:mongo, {}, span)
span.finish
end

def succeeded(event)
span = @requests.delete(event.request_id)
::Instana.tracer.log_async_exit(:mongo, {}, span)
span.finish
end

private
Expand Down
Loading
Loading