Instrumenting Absinthe via Telemetry

I’m trying to expose graphql operations in a dashboard but I’m having trouble parsing the operation name from the query or mutation. At this stage I’d like to expose the total time for either a query or mutation, I have the following query:

query {
  me {
    id
  }
}

And I believe I should be able to pull out the appropriate duration metric by attaching to [:absinthe, :execute, :operation, :stop] with something like:

:telemetry.attach_many(
  :demo,
  [
    [:absinthe, :execute, :operation, :stop]
  ],
  fn event_name, measurements, metadata, _config ->
    IO.inspect(metadata)
  end,
  []
)

metadata seems to be an id, blueprint and options. If I take a look at blueprint’s source code I can’t see where I can access the name of the query - in this case me. I would love to be able to report the duration of the me query.

Absinthe.Language.Document.get_operation(metadata.blueprint.input) gets me what the client passes as the friendly name but given that can be anything I’d prefer to get me but I cannot figure it out. I know it’s somewhere because absinthe uses it internally to figure out which query to run.

Alternatively I’m thinking about this the wrong way and there is a different way to get what I want. Any help would be appreciated.

Thanks!

I’ve been looking at this too trying to see if we can connect absinthe with appsignal. Blueprint just seems like a really big data structure, but I did find

metadata.options a lot easier to check. It is a keyword list and seems to have the “operation_name” for a query

lobo

1 Like

Thanks for responding @dlobo - I need to double check but I thought the operation_name was the name the client passes e.g.

query currentUser {
  me {
    id
  }
}

operation_name would be currentUser and not me. I could be wrong through and I’ll double check.

yes it is. In my first few graphql statements, they matched and hence I did not detect it. the next mutation, it was different and I realized it. However. in the same options array, there is also the complete document that you can extract it from (yes, a bit of a pain). I did a search on the other entries and could not find the “name”