Created
May 1, 2017 21:37
-
-
Save karmajunkie/1bff516ca518e00f8be8144b1dccbcc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Bling.GraphQL.Schema do | |
use Absinthe.Schema | |
def middleware([]=middleware, _field, _object), do: middleware | |
def middleware(middleware, field, object) do | |
Bling.GraphQL.ScoutMiddleware.instrument(middleware, field, object) | |
end | |
query do | |
#... | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Bling.GraphQL.ScoutMiddleware do | |
@behaviour Absinthe.Middleware | |
@behaviour Absinthe.Plugin | |
def call( res, {:start, object_identifier, field_identifier }) do | |
IO.puts "Scout middleware" | |
ScoutApm.TrackedRequest.start_layer("Controller", "#{object_identifier}/#{field_identifier}" ) | |
res | |
end | |
# def after_resolution(acc=%{__MODULE__: [layer_on | layers_after]}) do | |
def call( res, {:end, object_identifier, field_identifier }) do | |
ScoutApm.TrackedRequest.stop_layer fn | |
layer -> layer | |
end | |
res | |
end | |
def instrument(middleware, field, object) do | |
[{{ __MODULE__,:call}, {:start, object.identifier, field.identifier} } | middleware ] ++ [{{__MODULE__, :call}, {:end, object.identifier, field.identifier}}] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment