movio / bramble

A federated GraphQL API gateway
https://movio.github.io/bramble/
MIT License
497 stars 53 forks source link

Add Datadog graphql trace #204

Closed marcosuma closed 1 year ago

marcosuma commented 1 year ago

Hi there (again) :), our infra uses Datadog to monitor our services. I recently noticed that for our bramble-based service we are using an http tracer but this has the advantage that it'll not correctly log request errors (graphql always returns 200).

So I noticed that the same Datadog library supports graph-gophers - see the example tab for how to use it - which would likely be ideal for us in order to get proper graphql monitoring.

The problem is that I am not sure this could be bundled into our bramble-based service. Could a plugin be used? I tried with the Init method but no luck.

nmaquet commented 1 year ago

Hey @marcosuma! Yes, you should be able to write a plugin for your use case. At Movio, we use AWS X-Ray for tracing so we've developed a plugin for it. I've created a gist for you to have a look at the code: https://gist.github.com/nmaquet/0c04308d7ae7c234387926cf4c7e791c

As you can see from the X-Ray plugin, most of the heavy lifting happens in Init, WrapGraphQLClientTransport and InterceptRequest. I'm quite confident you should be able to use a very similar approach for a Datadog plugin.

marcosuma commented 1 year ago

Thanks @nmaquet! That helps a lot. Is there a way I can get access to GraphQL errors in a plugin? What I would basically like to do is to trace those errors and publish metrics about it. Current situation is that if I capture the body response with a http.RoundTripper whenever there is an error the response.body is actually empty (here's a gist about it)

nmaquet commented 1 year ago

Hey @marcosuma. If you want easy access to GraphQL errors, the Plugin interface needs to be extended a bit. I've done so here: https://github.com/movio/bramble/pull/205 Can you give this a shot and we'll try and merge this and release it soon.

marcosuma commented 1 year ago

That's awesome! I can try to clone it and test it locally, but are you plannign to release a new version?

nmaquet commented 1 year ago

@marcosuma Yes, that's the plan. Could you test it on your side and let me know whether this works for you? Once you confirm that you've tested it, we'll do a release. Thanks!

marcosuma commented 1 year ago

I did a quick test on how to integrate it with dd-trace and it seems working. This is a way I am trying to use it https://gist.github.com/marcosuma/e3b0e095b11f1dfff09f6ad24c349bf3

FYI I am not fully able to test the whole end-to-end path until this is released as a new version. But LGTM!

nmaquet commented 1 year ago

Thanks for confirming @marcosuma. I've released https://github.com/movio/bramble/releases/tag/v1.4.8

nmaquet commented 1 year ago

Closing this issue @marcosuma. Feel free to ask additional question if you have them, though.