From 11799a9e3ba11382375cf736cb3b3d7477199d12 Mon Sep 17 00:00:00 2001 From: Ariel Valentin Date: Tue, 21 Nov 2023 13:38:54 -0600 Subject: [PATCH] squash: fix ids --- instrumentation/active_job/README.md | 9 +++++-- .../active_job/example/active_job.rb | 24 ++++++------------- .../active_job/mappers/attribute.rb | 6 +++-- .../active_job/mappers/attribute_test.rb | 8 +++---- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/instrumentation/active_job/README.md b/instrumentation/active_job/README.md index 9b1c42022..686247ab9 100644 --- a/instrumentation/active_job/README.md +++ b/instrumentation/active_job/README.md @@ -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 diff --git a/instrumentation/active_job/example/active_job.rb b/instrumentation/active_job/example/active_job.rb index 67f863f59..71cd31646 100644 --- a/instrumentation/active_job/example/active_job.rb +++ b/instrumentation/active_job/example/active_job.rb @@ -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 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 aa1af16db..d62405b46 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 @@ -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 diff --git a/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/mappers/attribute_test.rb b/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/mappers/attribute_test.rb index 07d24f426..060e93f67 100644 --- a/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/mappers/attribute_test.rb +++ b/instrumentation/active_job/test/opentelemetry/instrumentation/active_job/mappers/attribute_test.rb @@ -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 @@ -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