diff --git a/instrumentation/opentelemetry_oban/lib/opentelemetry_oban.ex b/instrumentation/opentelemetry_oban/lib/opentelemetry_oban.ex index 7a4a41a5..3bc61e70 100644 --- a/instrumentation/opentelemetry_oban/lib/opentelemetry_oban.ex +++ b/instrumentation/opentelemetry_oban/lib/opentelemetry_oban.ex @@ -18,9 +18,8 @@ defmodule OpentelemetryOban do alias Ecto.Changeset alias OpenTelemetry.Span - alias OpenTelemetry.SemanticConventions.Trace + alias OpenTelemetry.SemConv.Incubating.MessagingAttributes - require Trace require OpenTelemetry.Tracer @doc """ @@ -130,15 +129,18 @@ defmodule OpentelemetryOban do worker = Changeset.get_field(changeset, :worker) %{ - Trace.messaging_system() => :oban, - Trace.messaging_destination() => queue, - Trace.messaging_destination_kind() => :queue, + MessagingAttributes.messaging_system() => :oban, + MessagingAttributes.messaging_client_id() => worker, + MessagingAttributes.messaging_destination_name() => queue, + MessagingAttributes.messaging_operation_type() => + MessagingAttributes.messaging_operation_type_values().create, :"oban.job.worker" => worker } end defp attributes_after_insert(job) do %{ + MessagingAttributes.messaging_message_id() => job.id, "oban.job.job_id": job.id, "oban.job.priority": job.priority, "oban.job.max_attempts": job.max_attempts diff --git a/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/job_handler.ex b/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/job_handler.ex index 8d14f781..7f9d52d8 100644 --- a/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/job_handler.ex +++ b/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/job_handler.ex @@ -1,8 +1,6 @@ defmodule OpentelemetryOban.JobHandler do alias OpenTelemetry.Span - alias OpenTelemetry.SemanticConventions.Trace - - require Trace + alias OpenTelemetry.SemConv.Incubating.MessagingAttributes @tracer_id __MODULE__ @@ -60,10 +58,12 @@ defmodule OpentelemetryOban.JobHandler do OpenTelemetry.Tracer.set_current_span(:undefined) attributes = %{ - Trace.messaging_system() => :oban, - Trace.messaging_destination() => queue, - Trace.messaging_destination_kind() => :queue, - Trace.messaging_operation() => :process, + MessagingAttributes.messaging_system() => :oban, + MessagingAttributes.messaging_message_id() => id, + MessagingAttributes.messaging_client_id() => worker, + MessagingAttributes.messaging_destination_name() => queue, + MessagingAttributes.messaging_operation_type() => + MessagingAttributes.messaging_operation_type_values().process, :"oban.job.job_id" => id, :"oban.job.worker" => worker, :"oban.job.priority" => priority, diff --git a/instrumentation/opentelemetry_oban/mix.exs b/instrumentation/opentelemetry_oban/mix.exs index 5ba1ea18..102485bc 100644 --- a/instrumentation/opentelemetry_oban/mix.exs +++ b/instrumentation/opentelemetry_oban/mix.exs @@ -47,7 +47,7 @@ defmodule OpentelemetryOban.MixProject do {:oban, "~> 2.0"}, {:opentelemetry_api, "~> 1.2"}, {:opentelemetry_telemetry, "~> 1.1"}, - {:opentelemetry_semantic_conventions, "~> 0.2"}, + {:opentelemetry_semantic_conventions, "~> 1.27"}, {:opentelemetry, "~> 1.0", only: [:test]}, {:opentelemetry_exporter, "~> 1.0", only: [:test]}, {:telemetry, "~> 0.4 or ~> 1.0"}, diff --git a/instrumentation/opentelemetry_oban/mix.lock b/instrumentation/opentelemetry_oban/mix.lock index 2abcfc31..1d4869d4 100644 --- a/instrumentation/opentelemetry_oban/mix.lock +++ b/instrumentation/opentelemetry_oban/mix.lock @@ -15,12 +15,12 @@ "makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"}, "makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"}, "makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"}, - "nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"}, "oban": {:hex, :oban, "2.17.4", "3ebe79dc0cad16f23e5feea418f9bc5b07d453b8fb7caf376d812be96157a5c5", [:mix], [{:ecto_sql, "~> 3.6", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:ecto_sqlite3, "~> 0.9", [hex: :ecto_sqlite3, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.16", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "71a804abea3bb7e104782a5b5337cbab76c1a56b9689a6d5159a3873c93898b6"}, "opentelemetry": {:hex, :opentelemetry, "1.5.0", "7dda6551edfc3050ea4b0b40c0d2570423d6372b97e9c60793263ef62c53c3c2", [:rebar3], [{:opentelemetry_api, "~> 1.4", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}], "hexpm", "cdf4f51d17b592fc592b9a75f86a6f808c23044ba7cf7b9534debbcc5c23b0ee"}, "opentelemetry_api": {:hex, :opentelemetry_api, "1.4.0", "63ca1742f92f00059298f478048dfb826f4b20d49534493d6919a0db39b6db04", [:mix, :rebar3], [], "hexpm", "3dfbbfaa2c2ed3121c5c483162836c4f9027def469c41578af5ef32589fcfc58"}, "opentelemetry_exporter": {:hex, :opentelemetry_exporter, "1.8.0", "5d546123230771ef4174e37bedfd77e3374913304cd6ea3ca82a2add49cd5d56", [:rebar3], [{:grpcbox, ">= 0.0.0", [hex: :grpcbox, repo: "hexpm", optional: false]}, {:opentelemetry, "~> 1.5.0", [hex: :opentelemetry, repo: "hexpm", optional: false]}, {:opentelemetry_api, "~> 1.4.0", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}, {:tls_certificate_check, "~> 1.18", [hex: :tls_certificate_check, repo: "hexpm", optional: false]}], "hexpm", "a1f9f271f8d3b02b81462a6bfef7075fd8457fdb06adff5d2537df5e2264d9af"}, - "opentelemetry_semantic_conventions": {:hex, :opentelemetry_semantic_conventions, "0.2.0", "b67fe459c2938fcab341cb0951c44860c62347c005ace1b50f8402576f241435", [:mix, :rebar3], [], "hexpm", "d61fa1f5639ee8668d74b527e6806e0503efc55a42db7b5f39939d84c07d6895"}, + "opentelemetry_semantic_conventions": {:hex, :opentelemetry_semantic_conventions, "1.27.0", "acd0194a94a1e57d63da982ee9f4a9f88834ae0b31b0bd850815fe9be4bbb45f", [:mix, :rebar3], [], "hexpm", "9681ccaa24fd3d810b4461581717661fd85ff7019b082c2dff89c7d5b1fc2864"}, "opentelemetry_telemetry": {:hex, :opentelemetry_telemetry, "1.1.2", "410ab4d76b0921f42dbccbe5a7c831b8125282850be649ee1f70050d3961118a", [:mix, :rebar3], [{:opentelemetry_api, "~> 1.3", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "641ab469deb181957ac6d59bce6e1321d5fe2a56df444fc9c19afcad623ab253"}, "postgrex": {:hex, :postgrex, "0.17.5", "0483d054938a8dc069b21bdd636bf56c487404c241ce6c319c1f43588246b281", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "50b8b11afbb2c4095a3ba675b4f055c416d0f3d7de6633a595fc131a828a67eb"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"}, diff --git a/instrumentation/opentelemetry_oban/test/opentelemetry_oban/plugin_handler_test.exs b/instrumentation/opentelemetry_oban/test/opentelemetry_oban/plugin_handler_test.exs index 87e93aac..aceab172 100644 --- a/instrumentation/opentelemetry_oban/test/opentelemetry_oban/plugin_handler_test.exs +++ b/instrumentation/opentelemetry_oban/test/opentelemetry_oban/plugin_handler_test.exs @@ -103,7 +103,7 @@ defmodule OpentelemetryOban.PluginHandlerTest do [ event( - name: "exception", + name: :exception, attributes: event_attributes ) ] = :otel_events.list(events) diff --git a/instrumentation/opentelemetry_oban/test/opentelemetry_oban_test.exs b/instrumentation/opentelemetry_oban/test/opentelemetry_oban_test.exs index de3828de..e53803b6 100644 --- a/instrumentation/opentelemetry_oban/test/opentelemetry_oban_test.exs +++ b/instrumentation/opentelemetry_oban/test/opentelemetry_oban_test.exs @@ -32,7 +32,7 @@ defmodule OpentelemetryObanTest do end test "records span on job insertion" do - OpentelemetryOban.insert(TestJob.new(%{})) + {:ok, %{id: id}} = OpentelemetryOban.insert(TestJob.new(%{})) assert %{success: 1, failure: 0} = Oban.drain_queue(queue: :events) assert_receive {:span, @@ -45,12 +45,14 @@ defmodule OpentelemetryObanTest do )} assert %{ - "messaging.destination": "events", - "messaging.destination_kind": :queue, + "messaging.destination.name": "events", "oban.job.job_id": _job_id, "oban.job.max_attempts": 1, "oban.job.priority": 0, "oban.job.worker": "TestJob", + "messaging.message.id": ^id, + "messaging.client.id": "TestJob", + "messaging.operation.type": :create, "messaging.system": :oban } = :otel_attributes.map(attributes) end @@ -133,7 +135,7 @@ defmodule OpentelemetryObanTest do end test "records spans for successful Oban jobs" do - OpentelemetryOban.insert(TestJob.new(%{})) + {:ok, %{id: id}} = OpentelemetryOban.insert(TestJob.new(%{})) assert %{success: 1, failure: 0} = Oban.drain_queue(queue: :events) assert_receive {:span, @@ -145,22 +147,23 @@ defmodule OpentelemetryObanTest do )} assert %{ - "messaging.destination": "events", - "messaging.destination_kind": :queue, + "messaging.destination.name": "events", "oban.job.attempt": 1, "oban.job.inserted_at": _inserted_at, - "oban.job.job_id": _job_id, + "oban.job.job_id": ^id, "oban.job.max_attempts": 1, "oban.job.priority": 0, "oban.job.scheduled_at": _scheduled_at, "oban.job.worker": "TestJob", - "messaging.operation": :process, + "messaging.message.id": ^id, + "messaging.client.id": "TestJob", + "messaging.operation.type": :process, "messaging.system": :oban } = :otel_attributes.map(attributes) end test "records spans for Oban jobs that stop with {:error, :something}" do - OpentelemetryOban.insert(TestJobThatReturnsError.new(%{})) + {:ok, %{id: id}} = OpentelemetryOban.insert(TestJobThatReturnsError.new(%{})) assert %{success: 0, discard: 1} = Oban.drain_queue(queue: :events) expected_status = OpenTelemetry.status(:error, "") @@ -175,22 +178,23 @@ defmodule OpentelemetryObanTest do )} assert %{ - "messaging.destination": "events", - "messaging.destination_kind": :queue, "oban.job.attempt": 1, "oban.job.inserted_at": _inserted_at, - "oban.job.job_id": _job_id, + "oban.job.job_id": ^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 + "messaging.destination.name": "events", + "messaging.operation.type": :process, + "messaging.system": :oban, + "messaging.message.id": ^id, + "messaging.client.id": "TestJobThatReturnsError" } = :otel_attributes.map(attributes) [ event( - name: "exception", + name: :exception, attributes: event_attributes ) ] = :otel_events.list(events) @@ -238,7 +242,7 @@ defmodule OpentelemetryObanTest do end test "records spans for Oban jobs that stop with an exception" do - OpentelemetryOban.insert(TestJobThatThrowsException.new(%{})) + {:ok, %{id: id}} = OpentelemetryOban.insert(TestJobThatThrowsException.new(%{})) assert %{success: 0, discard: 1} = Oban.drain_queue(queue: :events) expected_status = OpenTelemetry.status(:error, "") @@ -253,22 +257,23 @@ defmodule OpentelemetryObanTest do )} assert %{ - "messaging.destination": "events", - "messaging.destination_kind": :queue, + "messaging.destination.name": "events", "oban.job.attempt": 1, "oban.job.inserted_at": _inserted_at, - "oban.job.job_id": _job_id, + "oban.job.job_id": ^id, "oban.job.max_attempts": 1, "oban.job.priority": 0, "oban.job.scheduled_at": _scheduled_at, "oban.job.worker": "TestJobThatThrowsException", - "messaging.operation": :process, + "messaging.operation.type": :process, + "messaging.message.id": ^id, + "messaging.client.id": "TestJobThatThrowsException", "messaging.system": :oban } = :otel_attributes.map(attributes) [ event( - name: "exception", + name: :exception, attributes: event_attributes ) ] = :otel_events.list(events) @@ -324,7 +329,7 @@ defmodule OpentelemetryObanTest do [ event( - name: "exception", + name: :exception, attributes: event_attributes ) ] = :otel_events.list(events)