From 199d42cb34a47803daab522ff1c824f590a23eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20van=20Diemen?= Date: Fri, 12 Jul 2024 14:14:56 +0200 Subject: [PATCH] Use Tracing functions throughout modules more Tracing has a few functions that cover the grounds of other functions that are used. These can be altered to use Tracings own functions. --- lib/tracing.ex | 7 +++++++ lib/tracing/monitor.ex | 14 +++++++------- lib/tracing/oban_telemetry.ex | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/tracing.ex b/lib/tracing.ex index c707b1d..344919d 100644 --- a/lib/tracing.ex +++ b/lib/tracing.ex @@ -105,6 +105,13 @@ defmodule Tracing do |> extract() end + @doc """ + Simple wrapper around `OpenTelemetry.Tracer.end_span/0` + """ + def end_span() do + OpenTelemetry.Tracer.end_span() + end + @doc """ Helper function for propogating opentelemetry """ diff --git a/lib/tracing/monitor.ex b/lib/tracing/monitor.ex index a770c85..775f9a6 100644 --- a/lib/tracing/monitor.ex +++ b/lib/tracing/monitor.ex @@ -18,8 +18,8 @@ defmodule Tracing.Monitor do def handle_info({:DOWN, _ref, :process, pid, :normal}, state) do :ets.take(__MODULE__, pid) |> Enum.each(fn {_pid, ctx} -> - _span_ctx = OpenTelemetry.Tracer.set_current_span(ctx) - _ = OpenTelemetry.Tracer.end_span() + _span_ctx = Tracing.set_current_span(ctx) + _ = Tracing.end_span() end) {:noreply, state} @@ -28,8 +28,8 @@ defmodule Tracing.Monitor do def handle_info({:DOWN, _ref, :process, pid, {:shutdown, _}}, state) do :ets.take(__MODULE__, pid) |> Enum.each(fn {_pid, ctx} -> - _span_ctx = OpenTelemetry.Tracer.set_current_span(ctx) - _ = OpenTelemetry.Tracer.end_span() + _span_ctx = Tracing.set_current_span(ctx) + _ = Tracing.end_span() end) {:noreply, state} @@ -38,9 +38,9 @@ defmodule Tracing.Monitor do def handle_info({:DOWN, _ref, :process, pid, reason}, state) do :ets.take(__MODULE__, pid) |> Enum.each(fn {_pid, ctx} -> - _span_ctx = OpenTelemetry.Tracer.set_current_span(ctx) - _ = OpenTelemetry.Tracer.add_event("Process died", [{"reason", inspect(reason)}]) - _ = OpenTelemetry.Tracer.end_span() + Tracing.set_current_span(ctx) + Tracing.add_event("Process died", [{"reason", inspect(reason)}]) + Tracing.end_span() end) {:noreply, state} diff --git a/lib/tracing/oban_telemetry.ex b/lib/tracing/oban_telemetry.ex index dbcf883..f682944 100644 --- a/lib/tracing/oban_telemetry.ex +++ b/lib/tracing/oban_telemetry.ex @@ -69,7 +69,7 @@ defmodule Tracing.ObanTelemetry do }) |> Span.set_attributes(attributes) - Tracing.Monitor.monitor(OpenTelemetry.Tracer.current_span_ctx()) + Tracing.monitor() end def handle_event([:oban, :job, :stop], _, meta, _) do @@ -82,7 +82,7 @@ defmodule Tracing.ObanTelemetry do %{kind: kind, reason: reason, stacktrace: stacktrace} = meta, _ ) do - case OpenTelemetry.Tracer.current_span_ctx() do + case Tracing.current_span() do :undefined -> nil