OpentelemetryAbsinthe.Helpers (opentelemetry_absinthe v1.0.0)
OpenTelemetry-friendly alternatives of Absinthe.Resolution.Helpers functions
Some of the standard absinthe resolution helpers, like batch
or async
,
are not "opentelemetry-friendly": the resolvers, when invoked, lose the active span
and break the trace propagation.
This module defines compatible alternatives that can be used in the same way, but don't lose the trace information.
Link to this section Summary
Functions
Wrapper around the "real" batch function used by batch_keep_span
Works like Absinthe.Resolution.Helpers.batch, but preserves the active span.
Link to this section Functions
batch_fun_wrapper(arg, aggregate)
Wrapper around the "real" batch function used by batch_keep_span
Takes the passed span and sets it as the active one, then calls the original batch function with the original parameter.
batch_keep_span(batch_key, batch_data, post_batch_fn)
Specs
batch_keep_span( Absinthe.Middleware.Batch.batch_fun(), any(), Absinthe.Middleware.Batch.post_batch_fun() ) :: {:middleware, Absinthe.Middleware.Batch, term()}
Works like Absinthe.Resolution.Helpers.batch, but preserves the active span.
The function supplied to the batch
helper is executed in a Task by Absinthe,
which means that the erlang opentelemetry SDK would lose track of the currently
active span, because they are kept in a pdict.
To work around this, you can just replace batch
with batch_keep_span
,
and the active span will be automatically passed and reset as the active one
inside the batch function.
batch_keep_span(arg, batch_data, post_batch_fn, opts)
Specs
batch_keep_span( Absinthe.Middleware.Batch.batch_fun(), any(), Absinthe.Middleware.Batch.post_batch_fun(), opts :: [{:timeout, pos_integer()}] ) :: {:middleware, Absinthe.Middleware.Batch, term()}