Skip to content

Commit

Permalink
Add telemetry_span_context following conventions (#1128)
Browse files Browse the repository at this point in the history
Absinthe's telemetry events includes `id` metadata, as means to
correlate start/stop/exception events. Telemetry defines a
`telemetry_span_context` for this same reasons.

This patch publishes the same `id` value  as both keys, sowe maintain
backwards compatibility as well keep adherent to conventions, for tools
that rely on that - like OpenTelemetry.

The `telemetry_span_context` is generated using `:erlang.make_ref/0`.
Given typespecs describe as `term`, should be safe to use the same value
as `id`.
  • Loading branch information
andrewhr authored Nov 28, 2021
1 parent 6889e0b commit 991feb9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 8 additions & 1 deletion lib/absinthe/middleware/batch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ defmodule Absinthe.Middleware.Batch do
@batch_stop [:absinthe, :middleware, :batch, :stop]
defp emit_start_event(system_time, batch_fun, batch_opts, batch_data) do
id = :erlang.unique_integer()
metadata = %{id: id, batch_fun: batch_fun, batch_opts: batch_opts, batch_data: batch_data}

metadata = %{
id: id,
telemetry_span_context: id,
batch_fun: batch_fun,
batch_opts: batch_opts,
batch_data: batch_data
}

:telemetry.execute(
@batch_start,
Expand Down
3 changes: 2 additions & 1 deletion lib/absinthe/middleware/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Absinthe.Middleware.Telemetry do
:telemetry.execute(
@field_start,
%{system_time: system_time},
%{id: id, resolution: resolution}
%{id: id, telemetry_span_context: id, resolution: resolution}
)

%{
Expand Down Expand Up @@ -49,6 +49,7 @@ defmodule Absinthe.Middleware.Telemetry do
%{duration: end_time_mono - start_time_mono},
%{
id: id,
telemetry_span_context: id,
middleware: middleware,
resolution: resolution
}
Expand Down
8 changes: 4 additions & 4 deletions lib/absinthe/phase/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Absinthe.Phase.Telemetry do
:telemetry.execute(
@operation_start,
%{system_time: system_time},
%{id: id, blueprint: blueprint, options: options}
%{id: id, telemetry_span_context: id, blueprint: blueprint, options: options}
)

{:ok,
Expand All @@ -42,7 +42,7 @@ defmodule Absinthe.Phase.Telemetry do
:telemetry.execute(
@subscription_start,
%{system_time: system_time},
%{id: id, blueprint: blueprint, options: options}
%{id: id, telemetry_span_context: id, blueprint: blueprint, options: options}
)

{:ok,
Expand All @@ -59,7 +59,7 @@ defmodule Absinthe.Phase.Telemetry do
:telemetry.execute(
@subscription_stop,
%{duration: end_time_mono - start_time_mono},
%{id: id, blueprint: blueprint, options: options}
%{id: id, telemetry_span_context: id, blueprint: blueprint, options: options}
)
end

Expand All @@ -73,7 +73,7 @@ defmodule Absinthe.Phase.Telemetry do
:telemetry.execute(
@operation_stop,
%{duration: end_time_mono - start_time_mono},
%{id: id, blueprint: blueprint, options: options}
%{id: id, telemetry_span_context: id, blueprint: blueprint, options: options}
)
end

Expand Down

0 comments on commit 991feb9

Please sign in to comment.