Skip to content

Commit

Permalink
Use Tracing functions throughout modules more
Browse files Browse the repository at this point in the history
Tracing has a few functions that cover the grounds of other functions
that are used. These can be altered to use Tracings own functions.
  • Loading branch information
MvanDiemen committed Jul 12, 2024
1 parent 3feed77 commit 199d42c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
7 changes: 7 additions & 0 deletions lib/tracing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
14 changes: 7 additions & 7 deletions lib/tracing/monitor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions lib/tracing/oban_telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 199d42c

Please sign in to comment.