Skip to content

Commit

Permalink
Clean up after ourselves instead of right before setting the status
Browse files Browse the repository at this point in the history
I didn't realize `Span.end_span` does _not_ change the current span,
which is why when the parent catches the reraise it had the wrong span
as the current span. We're starting the span in a place where we can
hold on to it so we can manually update the current span to the parent
so that callers that _aren't_ using the decorator have the correct
current span.
  • Loading branch information
marcdel committed Mar 9, 2024
1 parent d118245 commit af60045
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/open_telemetry_decorator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ defmodule OpenTelemetryDecorator do
|> Map.take(unquote(dynamic_links))
|> Map.values()

parent_span = Tracer.current_span_ctx()
span = Tracer.start_span(unquote(span_name), links: links)
Tracer.set_current_span(span)

Expand All @@ -80,12 +81,12 @@ defmodule OpenTelemetryDecorator do
result
rescue
e ->
Tracer.set_current_span(span)
Tracer.record_exception(e)
Tracer.set_status(OpenTelemetry.status(:error))
reraise e, __STACKTRACE__
after
Span.end_span(span)
Tracer.set_current_span(parent_span)
end
end
rescue
Expand Down

0 comments on commit af60045

Please sign in to comment.