opencensus_absinthe v0.2.0 Opencensus.Absinthe
Extends Absinthe
to automatically create opencensus
spans. Designed to work with whatever
is producing spans upstream, e.g. Opencensus.Plug
.
Installation
Assuming you're using Absinthe.Plug
:
Add opencensus_absinthe
to your deps
in mix.exs
, using a tighter version constraint than:
{:absinthe_plug, ">= 0.0.0"},
{:opencensus_absinthe, ">= 0.0.0"},
Add a :pipeline
to your Absinthe.Plug.opts/0
to have it call
Opencensus.Absinthe.Plug.traced_pipeline/2
. If you're using Phoenix.Router.forward/4
, for
example:
forward(
path,
Absinthe.Plug,
# ... existing config ...
pipeline: {Opencensus.Absinthe.Plug, :traced_pipeline}
)
If you already have a pipeline
, you can define your own and call both to insert their phases.
To work with ApolloTracing
, for example:
def your_custom_pipeline(config, pipeline_opts \ []) do
config
|> Absinthe.Plug.default_pipeline(pipeline_opts)
|> ApolloTracing.Pipeline.add_phases()
|> Opencensus.Absinthe.add_phases()
end
Worst case, you'll need to copy the code from the current pipeline
target and add a call to
Opencensus.Absinthe.add_phases/1
as above.
Link to this section Summary
Functions
Add tracing phases to an existing pipeline for blueprint resolution.
Add tracing middleware for field resolution.
Link to this section Functions
add_phases(pipeline)
add_phases(Absinthe.Pipeline.t()) :: Absinthe.Pipeline.t()
add_phases(Absinthe.Pipeline.t()) :: Absinthe.Pipeline.t()
Add tracing phases to an existing pipeline for blueprint resolution.
pipeline =
Absinthe.Pipeline.for_document(schema, pipeline_opts)
|> Opencensus.Absinthe.add_phases()
middleware(middleware, field, object)
middleware(
[Absinthe.Middleware.spec(), ...],
Absinthe.Type.Field.t(),
Absinthe.Type.Object.t()
) :: [Absinthe.Middleware.spec(), ...]
middleware( [Absinthe.Middleware.spec(), ...], Absinthe.Type.Field.t(), Absinthe.Type.Object.t() ) :: [Absinthe.Middleware.spec(), ...]
Add tracing middleware for field resolution.
Specifically, prepends Opencensus.Absinthe.Middleware
to the middleware
chain if the field
has trace
or absinthe_telemetry
set in its metadata, e.g.:
field :users, list_of(:user), meta: [trace: true] do
middleware(Middleware.Authorize, "superadmin")
resolve(&Resolvers.Account.all_users/2)
end