Propagate the Tapper Id into the Absinthe context
Elixir
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
config
lib
test
.editorconfig
.gitignore
.travis.yml
README.md
mix.exs
mix.lock

README.md

Tapper Absinthe Integration

Works in concert with Tapper.Plug.Trace to propagate the Tapper Id into the Absinthe context.

Hex pm Inline docs Build Status

Synopsis

Using this plug, you can access the Tapper Id via a resolver's info (%Absinthe.Resolution{}) parameter, using Tapper.Plug.Absinthe.get/1.

In your router:

plug Tapper.Plug.Trace # pick up the trace
plug Tapper.Plug.Absinthe # copy the id into the Absinthe context

In your resolver:

def resolve(args, info) do
  # pick up from id info.context
  tapper_id = Tapper.Plug.Absinthe.get(info)

  tapper_id = Tapper.start_span(id, name: "my-resolver") # etc.
  ...
  Tapper.finish_span(tapper_id)
end

See also

The API documentation can be found at https://hexdocs.pm/tapper_absinthe_plug.

Helpers

Since you'll probably want to wrap a span around every resolver call, we provide Tapper.Absinthe.Helper.in_span/2, which wraps a new child span around a function call.

Using this in your Absinthe schema or type definition looks something like:

import Tapper.Absinthe.Helper, only: [in_span: 2]


query do

  @desc "Get a Thing by UUID"
  field :thing, type: :thing do
    @desc "A Thing UUID"
    arg :id, non_null(:id)
    resolve fn(%{id: thing_id}, info) ->

      in_span(info, fn(tapper_id) ->
        # call real resolver function, passing %Tapper.Id{} etc.
        MyApp.ThingResolver.thing(thing_id, tapper_id)
      end)
      
    end
  end

end

When the resolver is called, in_span/2 will start a child span, using the Tapper.Id from the Absinthe context, and apply the function, passing the child span id, so you can add annotations and pass to other functions, and returning the result. It will take care of finishing the child span, even in exception situations.

The name of the child span will be the schema node name, in this case thing.

Installation

For the latest pre-release (and unstable) code, add github repo to your mix dependencies:

def deps do
  [{:tapper_absinthe_plug, github: "Financial-Times/tapper_absinthe_plug"}]
end

For release versions, the package can be installed by adding tapper_absinthe_plug to your list of dependencies in mix.exs:

def deps do
  [{:tapper_absinthe_plug, "~> 0.2"}]
end

Ensure that the :tapper application is present in your mix project's applications:

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [
      mod: {MyApp, []},
      applications: [:tapper]
    ]
  end