scoutapp / scout_apm_elixir

ScoutAPM Elixir Agent. Supports Phoenix and other frameworks.
https://scoutapm.com
Other
36 stars 20 forks source link

Absinthe Plug doesn't work since v0.2.7 #33

Closed weixiyen closed 7 years ago

weixiyen commented 7 years ago

The Absinthe Plug no longer works as of version 0.2.7 https://gist.github.com/itsderek23/d9435b21c9a44cd9629e93c4e8c2750e

Seems it's due to TrackedRequest.start_layer and TrackedRequest.stop_layer accepting modules instead of strings as the first argument.

Would it be possible to make an update to that gist?

Thanks!

cschneid commented 7 years ago

I assume that the error is happening on stop_layer?

It looks like we did change the API on that to not include the full_name argument as a distinct argument, and instead let the callback function handle it.

I'll have to setup my testing environment for Absinthe again to be positive, but it likely would work if you remove full_name on line 15 of the Gist.

weixiyen commented 7 years ago

Correct it seems it's just stop_layer that didn't match.

Your recommendation fixes the issue, thanks!

defmodule ScoutApm.Absinthe.Plug do
  alias ScoutApm.Internal.Layer

  def init(default), do: default

  def call(conn, _default) do
    ScoutApm.TrackedRequest.start_layer("Controller", action_name(conn))

    conn
    |> Plug.Conn.register_before_send(&before_send/1)
  end
  def before_send(conn) do
    full_name = action_name(conn)
    uri = "#{conn.request_path}"
    ScoutApm.TrackedRequest.stop_layer(
      fn layer ->
        layer
        |> Layer.update_name(full_name)
        |> Layer.update_uri(uri)
      end
    )

    conn
  end

  # Takes a connection, extracts the phoenix controller & action, then manipulates & cleans it up.
  # Returns a string like "PageController#index"
  defp action_name(conn) do
    action_name = conn.params["operationName"]
    "GraphQL##{action_name}"
  end
end
cschneid commented 7 years ago

@weixiyen I'm going to reopen this until we get our documentation & that gist updated.

Thank you for reporting this, and I'm glad it's working for you.

itsderek23 commented 7 years ago

Gist updated.