Skip to content

Commit 042cb8b

Browse files
authored
Fix Oban Plugin exception handler expecting incorrect metadata key (#392)
* fix(opentelemetry_oban): Plugin exceptions use the reason metadata key * chore(opentelemetry_oban): Eliminate most of the Logger noise when running tests
1 parent e0ad241 commit 042cb8b

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

instrumentation/opentelemetry_oban/lib/opentelemetry_oban/plugin_handler.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ defmodule OpentelemetryOban.PluginHandler do
5454
def handle_plugin_exception(
5555
_event,
5656
_measurements,
57-
%{stacktrace: stacktrace, error: error} = metadata,
57+
%{kind: :error, reason: exception, stacktrace: stacktrace} = metadata,
5858
_config
5959
) do
6060
ctx = OpentelemetryTelemetry.set_current_telemetry_span(@tracer_id, metadata)
6161

6262
# Record exception and mark the span as errored
63-
Span.record_exception(ctx, error, stacktrace)
64-
Span.set_status(ctx, OpenTelemetry.status(:error, ""))
63+
Span.record_exception(ctx, exception, stacktrace)
64+
Span.set_status(ctx, OpenTelemetry.status(:error, Exception.message(exception)))
6565

6666
OpentelemetryTelemetry.end_telemetry_span(@tracer_id, metadata)
6767
end

instrumentation/opentelemetry_oban/test/opentelemetry_oban/plugin_handler_test.exs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ defmodule OpentelemetryOban.PluginHandlerTest do
7171
%{plugin: Elixir.Oban.Plugins.Stager}
7272
)
7373

74+
exception = %UndefinedFunctionError{
75+
arity: 0,
76+
function: :error,
77+
message: nil,
78+
module: Some,
79+
reason: nil
80+
}
81+
7482
:telemetry.execute(
7583
[:oban, :plugin, :exception],
7684
%{duration: 444},
@@ -80,17 +88,11 @@ defmodule OpentelemetryOban.PluginHandlerTest do
8088
stacktrace: [
8189
{Some, :error, [], []}
8290
],
83-
error: %UndefinedFunctionError{
84-
arity: 0,
85-
function: :error,
86-
message: nil,
87-
module: Some,
88-
reason: nil
89-
}
91+
reason: exception
9092
}
9193
)
9294

93-
expected_status = OpenTelemetry.status(:error, "")
95+
expected_status = OpenTelemetry.status(:error, Exception.message(exception))
9496

9597
assert_receive {:span,
9698
span(

instrumentation/opentelemetry_oban/test/test_helper.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ExUnit.start()
1+
ExUnit.start(capture_log: true)
22

33
TestRepo.start_link(
44
database: "opentelemetry_oban_test",

0 commit comments

Comments
 (0)