diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/instrumentation.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/instrumentation.rb index d9c6063c5..ebcf776cb 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/instrumentation.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/instrumentation.rb @@ -55,6 +55,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base option :propagation_style, default: :link, validate: %i[link child none] option :force_flush, default: false, validate: :boolean option :span_naming, default: :queue, validate: %i[job_class queue] + option :peer_service, default: nil, validate: :string private diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/mappers/attribute.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/mappers/attribute.rb index d62405b46..bfd46cfcb 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/mappers/attribute.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/mappers/attribute.rb @@ -31,11 +31,17 @@ def call(payload) otel_attributes['messaging.active_job.message.provider_job_id'] = job.provider_job_id.to_s if job.provider_job_id # This can be problematic if programs use invalid attribute types like Symbols for priority instead of using Integers. otel_attributes['messaging.active_job.message.priority'] = job.priority.to_s if job.priority + # add peer service if exists + otel_attributes['peer.service'] = otel_config[:peer_service] if otel_config[:peer_service] otel_attributes.compact! otel_attributes end + + def otel_config + ActiveJob::Instrumentation.instance.config + end end end end diff --git a/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/handlers/perform_test.rb b/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/handlers/perform_test.rb index cf4c9b976..587af3b7f 100644 --- a/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/handlers/perform_test.rb +++ b/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/handlers/perform_test.rb @@ -261,4 +261,16 @@ _(CallbacksJob.context_after).must_be :valid? end end + + describe 'peer.service' do + let(:config) { { peer_service: 'MyActiveJobService' } } + + it 'add peer.service info' do + TestJob.perform_later + + [publish_span, process_span].each do |span| + _(span.attributes['peer.service']).must_equal('MyActiveJobService') + end + end + end end