Skip to content

Commit

Permalink
fix: passing custom oban attributes to span
Browse files Browse the repository at this point in the history
  • Loading branch information
yordis committed Dec 12, 2023
1 parent 8af382e commit c8e41ea
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule OpentelemetryOban.PluginHandler do
require OpenTelemetry.Tracer, as: Tracer

alias OpenTelemetry.Span

@tracer_id __MODULE__
Expand Down Expand Up @@ -41,11 +43,12 @@ defmodule OpentelemetryOban.PluginHandler do
@tracer_id,
"#{plugin} process",
metadata,
%{}
%{attributes: %{"oban.plugin" => plugin}}
)
end

def handle_plugin_stop(_event, _measurements, metadata, _config) do
Tracer.set_attributes(end_span_plugin_attrs(metadata))
OpentelemetryTelemetry.end_telemetry_span(@tracer_id, metadata)
end

Expand All @@ -63,4 +66,24 @@ defmodule OpentelemetryOban.PluginHandler do

OpentelemetryTelemetry.end_telemetry_span(@tracer_id, metadata)
end

defp end_span_plugin_attrs(%{plugin: Oban.Plugins.Cron} = metadata) do
%{jobs_count: length(metadata[:jobs])}
end

defp end_span_plugin_attrs(%{plugin: Oban.Plugins.Gossip} = metadata) do
Map.take(metadata, [:gossip_count])
end

defp end_span_plugin_attrs(%{plugin: Oban.Plugins.Lifeline} = metadata) do
Map.take(metadata, [:discarded_count, :rescued_count])
end

defp end_span_plugin_attrs(%{plugin: Oban.Plugins.Pruner} = metadata) do
Map.take(metadata, [:pruned_count])
end

defp end_span_plugin_attrs(_) do
%{}
end
end

0 comments on commit c8e41ea

Please sign in to comment.