-
-
Save garthk/fddffdb2880b665c296cab435f216267 to your computer and use it in GitHub Desktop.
Experiment adding OpenTelemetry Python style exception recording to OpenTelemetry Elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule OpenTelemetry.Tracer do | |
# ... | |
quote do | |
span_ctx = unquote(span_ctx) | |
{exception_opts, start_opts} = | |
unquote(start_opts) | |
|> Map.new() | |
|> Map.split([:record_exception, :set_status_on_exception]) | |
start_opts = | |
Map.merge(start_opts, %{record_exception: false, set_status_on_exception: false}) | |
try do | |
:otel_tracer.with_span( | |
span_ctx, | |
:opentelemetry.get_tracer(__MODULE__), | |
unquote(name), | |
start_opts, | |
fn _ -> unquote(block) end | |
) | |
rescue | |
exception -> | |
if not match?(%{record_exception: false}, exception_opts) do | |
OpenTelemetry.Span.record_exception(span_ctx, exception, __STACKTRACE__) | |
end | |
if not match?(%{set_status_on_exception: false}, exception_opts) do | |
status = OpenTelemetry.status(:error, Exception.message(exception)) | |
OpenTelemetry.Span.set_status(span_ctx, status) | |
end | |
reraise exception, __STACKTRACE__ | |
end | |
end | |
# ... | |
end |
Removed delegation to Tracer. with_span_exception/4
. Contains if
, which'll have some maintainers breaking out in a rash, but it strikes me as closer to the house code style.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Experiment adding OT Python style opt-out record_exception and set_status_on_exception start options to OT Elixir's
with_span/4
. Most of the mess is in the capabilities being conditional, and turning both off for the innerotel_tracer:with_span/5
so exceptions don't get recorded twice.