Skip to content

Commit

Permalink
Fix Oban test failures
Browse files Browse the repository at this point in the history
Span names
Exception atom instead of string
and Oban Job priority after insert
  • Loading branch information
joshk committed Nov 7, 2024
1 parent d25c174 commit 2ada0a1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions instrumentation/opentelemetry_oban/lib/opentelemetry_oban.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule OpentelemetryOban do
attributes = attributes_before_insert(changeset)
worker = Changeset.get_field(changeset, :worker)

OpenTelemetry.Tracer.with_span "#{worker} send", attributes: attributes, kind: :producer do
OpenTelemetry.Tracer.with_span "#{worker}.send", attributes: attributes, kind: :producer do
changeset = add_tracing_information_to_meta(changeset)

case Oban.insert(name, changeset) do
Expand All @@ -76,7 +76,7 @@ defmodule OpentelemetryOban do
attributes = attributes_before_insert(changeset)
worker = Changeset.get_field(changeset, :worker)

OpenTelemetry.Tracer.with_span "#{worker} send", attributes: attributes, kind: :producer do
OpenTelemetry.Tracer.with_span "#{worker}.send", attributes: attributes, kind: :producer do
changeset = add_tracing_information_to_meta(changeset)

try do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ defmodule OpentelemetryOban.PluginHandlerTest do

[
event(
name: "exception",
name: :exception,
attributes: event_attributes
)
] = :otel_events.list(events)
Expand Down
46 changes: 23 additions & 23 deletions instrumentation/opentelemetry_oban/test/opentelemetry_oban_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJob send",
name: "TestJob.send",
attributes: attributes,
parent_span_id: :undefined,
kind: :producer,
Expand All @@ -49,7 +49,7 @@ defmodule OpentelemetryObanTest do
"messaging.system": :oban,
"oban.job.job_id": _job_id,
"oban.job.max_attempts": 1,
"oban.job.priority": 0,
"oban.job.priority": nil,
"oban.job.worker": "TestJob"
} = :otel_attributes.map(attributes)
end
Expand All @@ -65,7 +65,7 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJob send",
name: "TestJob.send",
attributes: _attributes,
trace_id: ^root_trace_id,
parent_span_id: ^root_span_id,
Expand All @@ -88,7 +88,7 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJob send",
name: "TestJob.send",
attributes: _attributes,
trace_id: send_trace_id,
span_id: send_span_id,
Expand All @@ -98,7 +98,7 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJob process",
name: "TestJob.process",
attributes: _attributes,
kind: :consumer,
status: :undefined,
Expand All @@ -120,7 +120,7 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJob process",
name: "TestJob.process",
attributes: _attributes,
kind: :consumer,
status: :undefined,
Expand All @@ -137,7 +137,7 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJob process",
name: "TestJob.process",
attributes: attributes,
kind: :consumer,
status: :undefined
Expand Down Expand Up @@ -165,7 +165,7 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJobThatReturnsError process",
name: "TestJobThatReturnsError.process",
attributes: attributes,
kind: :consumer,
events: events,
Expand All @@ -187,7 +187,7 @@ defmodule OpentelemetryObanTest do

[
event(
name: "exception",
name: :exception,
attributes: event_attributes
)
] = :otel_events.list(events)
Expand All @@ -206,14 +206,14 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJobThatReturnsError send",
name: "TestJobThatReturnsError.send",
trace_id: send_trace_id,
span_id: send_span_id
)}

assert_receive {:span,
span(
name: "TestJobThatReturnsError process",
name: "TestJobThatReturnsError.process",
status: ^expected_status,
trace_id: first_process_trace_id,
links: job_1_links
Expand All @@ -223,7 +223,7 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJobThatReturnsError process",
name: "TestJobThatReturnsError.process",
status: ^expected_status,
trace_id: second_process_trace_id,
links: job_2_links
Expand All @@ -242,7 +242,7 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJobThatThrowsException process",
name: "TestJobThatThrowsException.process",
attributes: attributes,
kind: :consumer,
events: events,
Expand All @@ -264,7 +264,7 @@ defmodule OpentelemetryObanTest do

[
event(
name: "exception",
name: :exception,
attributes: event_attributes
)
] = :otel_events.list(events)
Expand All @@ -279,7 +279,7 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJobWithInnerSpan process",
name: "TestJobWithInnerSpan.process",
kind: :consumer,
trace_id: trace_id,
span_id: process_span_id
Expand All @@ -297,8 +297,8 @@ defmodule OpentelemetryObanTest do
test "OpentelemetryOban.insert!/2 returns job on successful insert" do
%Oban.Job{} = OpentelemetryOban.insert!(TestJob.new(%{}))
assert %{success: 1, failure: 0} = Oban.drain_queue(queue: :events)
assert_receive {:span, span(name: "TestJob send")}
assert_receive {:span, span(name: "TestJob process")}
assert_receive {:span, span(name: "TestJob.send")}
assert_receive {:span, span(name: "TestJob.process")}
end

test "OpentelemetryOban.insert!/2 raises an error on failed insert" do
Expand All @@ -313,22 +313,22 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJob send",
name: "TestJob.send",
events: events,
status: ^expected_status
)}

[
event(
name: "exception",
name: :exception,
attributes: event_attributes
)
] = :otel_events.list(events)

assert [:"exception.message", :"exception.stacktrace", :"exception.type"] ==
Enum.sort(Map.keys(:otel_attributes.map(event_attributes)))

refute_received {:span, span(name: "TestJob process")}
refute_received {:span, span(name: "TestJob.process")}
end

test "tracing information is propagated when using insert_all/2" do
Expand All @@ -351,7 +351,7 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJob process",
name: "TestJob.process",
attributes: _attributes,
kind: :consumer,
status: :undefined,
Expand All @@ -363,7 +363,7 @@ defmodule OpentelemetryObanTest do

assert_receive {:span,
span(
name: "TestJob process",
name: "TestJob.process",
attributes: _attributes,
kind: :consumer,
status: :undefined,
Expand All @@ -383,6 +383,6 @@ defmodule OpentelemetryObanTest do
test "works with Oban.Testing.perform_job helper function" do
Oban.Testing.perform_job(TestJob, %{}, repo: TestRepo)

assert_receive {:span, span(name: "TestJob process")}
assert_receive {:span, span(name: "TestJob.process")}
end
end

0 comments on commit 2ada0a1

Please sign in to comment.