Skip to content

Commit

Permalink
fix: Add peer.service option for ActiveJob instrumentation
Browse files Browse the repository at this point in the history
fix: Rubocop
  • Loading branch information
Hareramrai authored and jdehaan committed Feb 5, 2024
1 parent f26eeb1 commit b6d0617
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b6d0617

Please sign in to comment.