Last active
January 13, 2017 20:04
-
-
Save karmajunkie/49f3c10f1e6730766784890f54c310e7 to your computer and use it in GitHub Desktop.
Gives limited tracing around absinthe calls. Shamelessly adapted from the Phoenix plug in new_relic.ex
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 NewRelic.Plug.Absinthe do | |
@moduledoc """ | |
A plug that instruments Phoenix controllers and records their response times in New Relic. | |
Inside an instrumented controller's actions, `conn` can be used for further instrumentation with | |
`NewRelic.Plug.Instrumentation` and `NewRelic.Plug.Repo`. | |
``` | |
defmodule MyApp.UsersController do | |
use Phoenix.Controller | |
plug NewRelic.Plug.Phoenix | |
def index(conn, _params) do | |
# `conn` is setup for instrumentation | |
end | |
end | |
``` | |
""" | |
@behaviour Elixir.Plug | |
import Elixir.Plug.Conn | |
def init(opts) do | |
opts | |
end | |
def call(conn, _config) do | |
if NewRelic.configured? do | |
transaction_name = conn.params | |
|> Map.get("operationName") | |
# TODO: Figure out how to add parameter info to a transaction | |
# variables = conn.body_params | |
# |> Map.get("variables") | |
# |> IO.inspect | |
conn | |
# |> IO.inspect | |
|> put_private(:new_relixir_transaction, NewRelic.Transaction.start(transaction_name)) | |
|> register_before_send(fn conn -> | |
NewRelic.Transaction.finish(Map.get(conn.private, :new_relixir_transaction)) | |
conn | |
end) | |
else | |
conn | |
end | |
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
pipeline :graphql do | |
plug Guardian.Plug.VerifyHeader | |
plug Guardian.Plug.EnsureAuthenticated, handler: Guardian.Plug.ErrorHandler | |
plug Guardian.Plug.LoadResource | |
plug NewRelic.Plug.Absinthe | |
plug GraphQLPlug | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment