diff --git a/instrumentation/opentelemetry_oban/CHANGELOG.md b/instrumentation/opentelemetry_oban/CHANGELOG.md index c4fbdb14..2eeb534f 100644 --- a/instrumentation/opentelemetry_oban/CHANGELOG.md +++ b/instrumentation/opentelemetry_oban/CHANGELOG.md @@ -4,8 +4,33 @@ ### Changed -* Improve Plugin span attributes. The Plugin's span introduce a set of - attributes prefixed with `oban.`. +* Improve `OpentelemetryOban.PluginHandler` Tracer span attributes. + The Plugin's span introduce a set of attributes prefixed with `oban.`. + Previously, no attributes were added to the span. The new attributes are: + + * All Plugin: + * `oban.plugin` + * `Oban.Plugins.Cron` Plugin: + * `oban.jobs_count` + * `Oban.Plugins.Gossip` Plugin: + * `oban.gossip_count` + * `Oban.Plugins.Lifeline` Plugin: + * `oban.discarded_count` + * `oban.rescued_count` + * `Oban.Plugins.Pruner` Plugin: + * `oban.pruned_count` + * `Oban.Pro.Plugins.DynamicCron` Plugin: + * `oban.jobs_count` + * `Oban.Pro.Plugins.DynamicLifeline` Plugin: + * `oban.discarded_count` + * `oban.rescued_count` + * `Oban.Pro.Plugins.DynamicPrioritizer` Plugin: + * `oban.reprioritized_count` + * `Oban.Pro.Plugins.DynamicPruner` Plugin: + * `oban.pruned_count` + * `Oban.Pro.Plugins.DynamicScaler` Plugin: + * `oban.scaler.last_scaled_to` + * `oban.scaler.last_scaled_at` ## 1.0.0 diff --git a/instrumentation/opentelemetry_oban/lib/opentelemetry_oban.ex b/instrumentation/opentelemetry_oban/lib/opentelemetry_oban.ex index a6af0c08..617062bc 100644 --- a/instrumentation/opentelemetry_oban/lib/opentelemetry_oban.ex +++ b/instrumentation/opentelemetry_oban/lib/opentelemetry_oban.ex @@ -133,15 +133,15 @@ defmodule OpentelemetryOban do Trace.messaging_system() => :oban, Trace.messaging_destination() => queue, Trace.messaging_destination_kind() => :queue, - :"messaging.oban.worker" => worker + :"oban.job.worker" => worker } end defp attributes_after_insert(job) do %{ - "messaging.oban.job_id": job.id, - "messaging.oban.priority": job.priority, - "messaging.oban.max_attempts": job.max_attempts + "oban.job.job_id": job.id, + "oban.job.priority": job.priority, + "oban.job.max_attempts": job.max_attempts } end end diff --git a/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/job_handler.ex b/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/job_handler.ex index 469443e2..8d14f781 100644 --- a/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/job_handler.ex +++ b/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/job_handler.ex @@ -64,14 +64,13 @@ defmodule OpentelemetryOban.JobHandler do Trace.messaging_destination() => queue, Trace.messaging_destination_kind() => :queue, Trace.messaging_operation() => :process, - :"messaging.oban.job_id" => id, - :"messaging.oban.worker" => worker, - :"messaging.oban.priority" => priority, - :"messaging.oban.attempt" => attempt, - :"messaging.oban.max_attempts" => max_attempts, - :"messaging.oban.inserted_at" => - if(inserted_at, do: DateTime.to_iso8601(inserted_at), else: nil), - :"messaging.oban.scheduled_at" => DateTime.to_iso8601(scheduled_at) + :"oban.job.job_id" => id, + :"oban.job.worker" => worker, + :"oban.job.priority" => priority, + :"oban.job.attempt" => attempt, + :"oban.job.max_attempts" => max_attempts, + :"oban.job.inserted_at" => DateTime.to_iso8601(inserted_at), + :"oban.job.scheduled_at" => DateTime.to_iso8601(scheduled_at) } span_name = "#{worker} process" diff --git a/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/plugin_handler.ex b/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/plugin_handler.ex index ab00aa34..5d0fee0c 100644 --- a/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/plugin_handler.ex +++ b/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/plugin_handler.ex @@ -1,6 +1,5 @@ defmodule OpentelemetryOban.PluginHandler do - require OpenTelemetry.Tracer, as: Tracer - + alias OpenTelemetry.Tracer alias OpenTelemetry.Span @tracer_id __MODULE__ @@ -68,47 +67,47 @@ defmodule OpentelemetryOban.PluginHandler do end defp end_span_plugin_attrs(%{plugin: Oban.Plugins.Cron} = metadata) do - %{"oban.jobs_count": length(metadata[:jobs])} + %{"oban.plugins.cron.jobs_count": length(metadata[:jobs])} end defp end_span_plugin_attrs(%{plugin: Oban.Plugins.Gossip} = metadata) do - %{"oban.gossip_count": metadata[:gossip_count]} + %{"oban.plugins.gossip.gossip_count": metadata[:gossip_count]} end defp end_span_plugin_attrs(%{plugin: Oban.Plugins.Lifeline} = metadata) do %{ - "oban.discarded_count": metadata[:discarded_count], - "oban.rescued_count": metadata[:rescued_count] + "oban.plugins.lifeline.discarded_count": metadata[:discarded_count], + "oban.plugins.lifeline.rescued_count": metadata[:rescued_count] } end defp end_span_plugin_attrs(%{plugin: Oban.Plugins.Pruner} = metadata) do - %{"oban.pruned_count": metadata[:pruned_count]} + %{"oban.plugins.pruner.pruned_count": metadata[:pruned_count]} end defp end_span_plugin_attrs(%{plugin: Oban.Pro.Plugins.DynamicCron} = metadata) do - %{"oban.jobs_count": length(metadata[:jobs])} + %{"oban.pro.plugins.dynamic_cron.jobs_count": length(metadata[:jobs])} end defp end_span_plugin_attrs(%{plugin: Oban.Pro.Plugins.DynamicLifeline} = metadata) do %{ - "oban.discarded_count": metadata[:discarded_count], - "oban.rescued_count": metadata[:rescued_count] + "oban.pro.plugins.dynamic_lifeline.discarded_count": metadata[:discarded_count], + "oban.pro.plugins.dynamic_lifeline.rescued_count": metadata[:rescued_count] } end defp end_span_plugin_attrs(%{plugin: Oban.Pro.Plugins.DynamicPrioritizer} = metadata) do - %{"oban.reprioritized_count": metadata[:reprioritized_count]} + %{"oban.pro.plugins.dynamic_prioritizer.reprioritized_count": metadata[:reprioritized_count]} end defp end_span_plugin_attrs(%{plugin: Oban.Pro.Plugins.DynamicPruner} = metadata) do - %{"oban.pruned_count": metadata[:pruned_count]} + %{"oban.pro.plugins.dynamic_pruner.pruned_count": metadata[:pruned_count]} end defp end_span_plugin_attrs(%{plugin: Oban.Pro.Plugins.DynamicScaler} = metadata) do %{ - "oban.scaler.last_scaled_to": metadata[:scaler][:last_scaled_to], - "oban.scaler.last_scaled_at": metadata[:scaler][:last_scaled_at] + "oban.pro.plugins.dynamic_scaler.scaler.last_scaled_to": metadata[:scaler][:last_scaled_to], + "oban.pro.plugins.dynamic_scaler.scaler.last_scaled_at": metadata[:scaler][:last_scaled_at] } end diff --git a/instrumentation/opentelemetry_oban/test/opentelemetry_oban_test.exs b/instrumentation/opentelemetry_oban/test/opentelemetry_oban_test.exs index c75b3bb3..de3828de 100644 --- a/instrumentation/opentelemetry_oban/test/opentelemetry_oban_test.exs +++ b/instrumentation/opentelemetry_oban/test/opentelemetry_oban_test.exs @@ -47,10 +47,10 @@ defmodule OpentelemetryObanTest do assert %{ "messaging.destination": "events", "messaging.destination_kind": :queue, - "messaging.oban.job_id": _job_id, - "messaging.oban.max_attempts": 1, - "messaging.oban.priority": 0, - "messaging.oban.worker": "TestJob", + "oban.job.job_id": _job_id, + "oban.job.max_attempts": 1, + "oban.job.priority": 0, + "oban.job.worker": "TestJob", "messaging.system": :oban } = :otel_attributes.map(attributes) end @@ -147,13 +147,13 @@ defmodule OpentelemetryObanTest do assert %{ "messaging.destination": "events", "messaging.destination_kind": :queue, - "messaging.oban.attempt": 1, - "messaging.oban.inserted_at": _inserted_at, - "messaging.oban.job_id": _job_id, - "messaging.oban.max_attempts": 1, - "messaging.oban.priority": 0, - "messaging.oban.scheduled_at": _scheduled_at, - "messaging.oban.worker": "TestJob", + "oban.job.attempt": 1, + "oban.job.inserted_at": _inserted_at, + "oban.job.job_id": _job_id, + "oban.job.max_attempts": 1, + "oban.job.priority": 0, + "oban.job.scheduled_at": _scheduled_at, + "oban.job.worker": "TestJob", "messaging.operation": :process, "messaging.system": :oban } = :otel_attributes.map(attributes) @@ -177,13 +177,13 @@ defmodule OpentelemetryObanTest do assert %{ "messaging.destination": "events", "messaging.destination_kind": :queue, - "messaging.oban.attempt": 1, - "messaging.oban.inserted_at": _inserted_at, - "messaging.oban.job_id": _job_id, - "messaging.oban.max_attempts": 1, - "messaging.oban.priority": 0, - "messaging.oban.scheduled_at": _scheduled_at, - "messaging.oban.worker": "TestJobThatReturnsError", + "oban.job.attempt": 1, + "oban.job.inserted_at": _inserted_at, + "oban.job.job_id": _job_id, + "oban.job.max_attempts": 1, + "oban.job.priority": 0, + "oban.job.scheduled_at": _scheduled_at, + "oban.job.worker": "TestJobThatReturnsError", "messaging.operation": :process, "messaging.system": :oban } = :otel_attributes.map(attributes) @@ -255,13 +255,13 @@ defmodule OpentelemetryObanTest do assert %{ "messaging.destination": "events", "messaging.destination_kind": :queue, - "messaging.oban.attempt": 1, - "messaging.oban.inserted_at": _inserted_at, - "messaging.oban.job_id": _job_id, - "messaging.oban.max_attempts": 1, - "messaging.oban.priority": 0, - "messaging.oban.scheduled_at": _scheduled_at, - "messaging.oban.worker": "TestJobThatThrowsException", + "oban.job.attempt": 1, + "oban.job.inserted_at": _inserted_at, + "oban.job.job_id": _job_id, + "oban.job.max_attempts": 1, + "oban.job.priority": 0, + "oban.job.scheduled_at": _scheduled_at, + "oban.job.worker": "TestJobThatThrowsException", "messaging.operation": :process, "messaging.system": :oban } = :otel_attributes.map(attributes)