Skip to content

Commit 844313d

Browse files
committed
Refine how we set values for Oban jobs
- Use the worker name as the description and transaction name instead of "{worker} process" - Use "queue.process" as the op - this is according to the docs https://develop.sentry.dev/sdk/telemetry/traces/modules/queues/ Maybe this could be improved in the opentelemetry_oban package?
1 parent 4d0eda9 commit 844313d

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

lib/sentry/opentelemetry/span_processor.ex

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Sentry.OpenTelemetry.SpanProcessor do
55
require OpenTelemetry.SemConv.Incubating.DBAttributes, as: DBAttributes
66
require OpenTelemetry.SemConv.Incubating.HTTPAttributes, as: HTTPAttributes
77
require OpenTelemetry.SemConv.Incubating.URLAttributes, as: URLAttributes
8-
8+
require OpenTelemetry.SemConv.Incubating.MessagingAttributes, as: MessagingAttributes
99
@behaviour :otel_span_processor
1010

1111
require Logger
@@ -64,7 +64,7 @@ defmodule Sentry.OpenTelemetry.SpanProcessor do
6464

6565
Transaction.new(%{
6666
span_id: root_span.span_id,
67-
transaction: root_span_record.name,
67+
transaction: transaction_name(root_span_record),
6868
transaction_info: %{source: :custom},
6969
contexts: %{
7070
trace: build_trace_context(root_span_record),
@@ -74,6 +74,15 @@ defmodule Sentry.OpenTelemetry.SpanProcessor do
7474
})
7575
end
7676

77+
defp transaction_name(
78+
%{attributes: %{unquote(to_string(MessagingAttributes.messaging_system())) => :oban}} =
79+
span_record
80+
) do
81+
span_record.attributes["oban.job.worker"]
82+
end
83+
84+
defp transaction_name(span_record), do: span_record.name
85+
7786
defp build_trace_context(span_record) do
7887
{op, description} = get_op_description(span_record)
7988

@@ -118,6 +127,13 @@ defmodule Sentry.OpenTelemetry.SpanProcessor do
118127
{"db", db_query_text}
119128
end
120129

130+
defp get_op_description(%{
131+
attributes:
132+
%{unquote(to_string(MessagingAttributes.messaging_system())) => :oban} = attributes
133+
}) do
134+
{"queue.process", attributes["oban.job.worker"]}
135+
end
136+
121137
defp get_op_description(span_record) do
122138
{span_record.name, span_record.name}
123139
end

test_integrations/phoenix_app/test/phoenix_app/oban_test.exs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,23 @@ defmodule Sentry.Integrations.Phoenix.ObanTest do
2828

2929
[transaction] = transactions
3030

31-
assert transaction.transaction == "Sentry.Integrations.Phoenix.ObanTest.TestWorker process"
31+
assert transaction.transaction == "Sentry.Integrations.Phoenix.ObanTest.TestWorker"
3232
assert transaction.transaction_info == %{source: :custom}
3333

3434
trace = transaction.contexts.trace
3535
assert trace.origin == "opentelemetry_oban"
36-
assert trace.op == "Sentry.Integrations.Phoenix.ObanTest.TestWorker process"
36+
assert trace.op == "queue.process"
37+
assert trace.description == "Sentry.Integrations.Phoenix.ObanTest.TestWorker"
3738
assert trace.data["oban.job.job_id"]
3839
assert trace.data["messaging.destination"] == "default"
3940
assert trace.data["oban.job.attempt"] == 1
4041

41-
assert [_span] = transaction.spans
42+
assert [span] = transaction.spans
43+
44+
assert span.op == "queue.process"
45+
assert span.description == "Sentry.Integrations.Phoenix.ObanTest.TestWorker"
46+
assert span.data["oban.job.job_id"]
47+
assert span.data["messaging.destination"] == "default"
48+
assert span.data["oban.job.attempt"] == 1
4249
end
4350
end

0 commit comments

Comments
 (0)