Skip to content

Commit

Permalink
squash: fix ids
Browse files Browse the repository at this point in the history
  • Loading branch information
arielvalentin committed Nov 21, 2023
1 parent 7639556 commit 11799a9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
9 changes: 7 additions & 2 deletions instrumentation/active_job/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ Attributes that are specific to this instrumentation are recorded under `messagi

| Attribute Name | Type | Notes |
| - | - | - |
| `messaging.message.id` | String | |
| `messaging.active_job.message.priority` | Integer | |
| `code.namespace` | String | `ActiveJob` class name |
| `messaging.system` | String | Static value set to `active_job` |
| `messaging.destination` | String | Set from `ActiveJob#queue_name` |
| `messaging.message.id` | String | Set from `ActiveJob#job_id` |
| `messaging.active_job.adapter.name` | String | The name of the `ActiveJob` adapter implementation |
| `messaging.active_job.message.priority` | String | Present when set by the client from `ActiveJob#priority` |
| `messaging.active_job.message.provider_job_id` | String | Present if the underlying adapter has backend specific message ids |

## Differences between ActiveJob versions

Expand Down
24 changes: 7 additions & 17 deletions instrumentation/active_job/example/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,16 @@ def perform
EXAMPLE_TRACER = OpenTelemetry.tracer_provider.tracer('activejob-example', '1.0')

class TestJob < ::ActiveJob::Base
around_enqueue do |_job, block|
EXAMPLE_TRACER.in_span('around_enqueue') do
block.call
end
end

around_perform do |_job, block|
EXAMPLE_TRACER.in_span("around_perform") do
block.call
end
end

def perform
puts <<~EOS
EXAMPLE_TRACER.in_span("custom span") do
puts <<~EOS
--------------------------------------------------
The computer is doing some work, beep beep boop.
--------------------------------------------------
--------------------------------------------------
The computer is doing some work, beep beep boop.
--------------------------------------------------
EOS
EOS
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ def call(payload)

otel_attributes = {
'code.namespace' => job.class.name,
'messaging.system' => job.class.queue_adapter_name,
'messaging.system' => 'active_job',
'messaging.destination' => job.queue_name,
'messaging.message.id' => job.job_id,
'messaging.message.id' => job.provider_job_id.to_s
'messaging.active_job.adapter.name' => job.class.queue_adapter_name
}

# Not all adapters generate or provide back end specific ids for messages
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@

[publish_span, process_span].each do |span|
_(span.attributes['code.namespace']).must_equal('TestJob')
_(span.attributes['messaging.system']).must_equal('async')
_(span.attributes['messaging.system']).must_equal('active_job')
_(span.attributes['messaging.active_job.adapter.name']).must_equal('async')
_(span.attributes['messaging.destination']).must_equal('default')
_(span.attributes['messaging.message.id']).must_equal(job.job_id)
_(span.attributes['messaging.active_job.message.priority']).must_be_nil
end

_(publish_span.attributes['messaging.message.id']).must_equal('')
_(process_span.attributes['messaging.message.id']).must_equal(job.provider_job_id)
_(process_span.attributes['messaging.active_job.message.provider_job_id']).must_equal(job.provider_job_id)
end

it 'tracks the job priority' do
Expand All @@ -71,7 +71,7 @@
TestJob.perform_later

[publish_span, process_span].each do |span|
_(span.attributes['messaging.system']).must_equal('inline')
_(span.attributes['messaging.active_job.adapter.name']).must_equal('inline')
end
end
end

0 comments on commit 11799a9

Please sign in to comment.