Skip to content

Commit bc2cce1

Browse files
committed
wip
1 parent 33cf151 commit bc2cce1

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

instrumentation/base/lib/opentelemetry/instrumentation/base.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def infer_version
192192
end
193193
end
194194

195-
attr_reader :name, :version, :config, :installed, :tracer
195+
attr_reader :name, :version, :config, :installed, :tracer, :meter
196196

197197
alias installed? installed
198198

@@ -207,7 +207,8 @@ def initialize(name, version, install_blk, present_blk,
207207
@config = {}
208208
@installed = false
209209
@options = options
210-
@tracer = OpenTelemetry::Trace::Tracer.new
210+
@tracer = OpenTelemetry::Trace::Tracer.new # default no-op tracer
211+
@meter = OpenTelemetry::Metrics::Meter.new # default no-op meter
211212
end
212213
# rubocop:enable Metrics/ParameterLists
213214

@@ -224,7 +225,11 @@ def install(config = {})
224225

225226
instance_exec(@config, &@install_blk)
226227
@tracer = OpenTelemetry.tracer_provider.tracer(name, version)
228+
227229
@installed = true
230+
231+
return unless config[:metrics]
232+
@meter = OpenTelemetry.meter_provider.meter(name, version: version)
228233
end
229234

230235
# Whether or not this instrumentation is installable in the current process. Will

instrumentation/concurrent_ruby/opentelemetry-instrumentation-concurrent_ruby.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
2626
spec.required_ruby_version = '>= 3.0'
2727

2828
spec.add_dependency 'opentelemetry-api', '~> 1.0'
29+
spec.add_dependency 'opentelemetry-metrics-api', '~> 1.0'
2930
spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1'
3031

3132
spec.add_development_dependency 'appraisal', '~> 2.5'

instrumentation/sidekiq/lib/opentelemetry/instrumentation/sidekiq/instrumentation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
107107
option :trace_poller_wait, default: false, validate: :boolean
108108
option :trace_processor_process_one, default: false, validate: :boolean
109109
option :peer_service, default: nil, validate: :string
110+
option :metrics, default: false, validate: :boolean
110111

111112
private
112113

instrumentation/sidekiq/lib/opentelemetry/instrumentation/sidekiq/middlewares/client/tracer_middleware.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ def call(_worker_class, job, _queue, _redis_pool)
3333
OpenTelemetry.propagation.inject(job)
3434
span.add_event('created_at', timestamp: job['created_at'])
3535
yield
36+
end.tap do
37+
# FIXME: is it possible to detect failures here? Does sidekiq bubble them up the middlewares?
38+
if instrumentation_config[:metrics]
39+
begin
40+
counter_attributes = {
41+
'messaging.operation.name' => 'enqueue', # FIXME: metrics semconv
42+
'messaging.system' => 'sidekiq', # FIXME: metrics semconv
43+
'messaging.destination.name' => job['queue'] # FIXME: metrics semconv
44+
# server.address => # FIXME: required if available
45+
# messaging.destination.partition.id => FIXME: recommended
46+
# server.port => # FIXME: recommended
47+
}
48+
49+
counter = meter.create_counter('messaging.client.sent.messages')
50+
counter.add(1, attributes: counter_attributes)
51+
end
52+
end
3653
end
3754
end
3855

@@ -45,6 +62,10 @@ def instrumentation_config
4562
def tracer
4663
Sidekiq::Instrumentation.instance.tracer
4764
end
65+
66+
def meter
67+
Sidekiq::Instrumentation.instance.meter
68+
end
4869
end
4970
end
5071
end

0 commit comments

Comments
 (0)