sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Add GraphQL query/mutation to HTTP breadcrumbs

Open maxchuquimia opened this issue 1 year ago • 6 comments

Problem Statement

HTTP breadcrumbs are super useful for seeing what the user was doing before and when an error occurred - however for those of us using GraphQL, the URL is always the same. This leads to a long list of logs similar to:

POST https://api.myapp.com/v1/graphql [200]

{
    reason: no error, 
    request_body_size: 62241,
    response_body_size: 0
}

It would be amazing if we could add a parameter there for the name of the GraphQL query or mutation that was run!

Solution Brainstorm

-[SentryNetworkTracker addBreadcrumbForSessionTask:] already has conditional logic for adding URL query and fragment tracking to the breadcrumb. Ideally something could be added there to allow logs in Sentry to appear as

POST https://api.myapp.com/v1/graphql [200]

{
    reason: no error, 
    request_body_size: 62241,
    response_body_size: 0,
    graphql: 'mutation myMutationName'
}

Alternatively, could a closure be introduced to allow SDK users to construct their own custom parameter value given a NSURLSessionTask?

Thank you for your consideration!

Are you willing to submit a PR?

No response

maxchuquimia avatar Dec 13 '23 21:12 maxchuquimia

Hi @maxchuquimia - thanks for writing in, this feature makes sense. We are discussing ways to better support and surface GraphQL queries in general and will follow up here.

kahest avatar Dec 14 '23 12:12 kahest

We should align with what we already have for GraphQL on Android/Java.

philipphofmann avatar Dec 14 '23 14:12 philipphofmann

Still super keen for this to happen! We forked this repo and tried a couple of ways to modify the breadcrumb: Using JSON: https://github.com/maxchuquimia/sentry-cocoa/commit/fa0b6607ed04ca3af9f3cabe588f13c319a24e25 Using Regex to: https://github.com/maxchuquimia/sentry-cocoa/commit/6bc3bedb723ca025e2687beca48a448e7df5ed5d

Ultimately we decided the JSON version was safer and have been using it in production, it's been extremely helpful so far.

Would still love an official solution for this, so I hope that sharing our work helps show how important it is to us!

maxchuquimia avatar Feb 29 '24 02:02 maxchuquimia

Hey @maxchuquimia, thank you very much!!

brustolin avatar Feb 29 '24 07:02 brustolin

FYI, I think there may be an issue with the current breadcrumbs in the context of eg. the Apollo GraphQL library, I am seeing a flood of HTTP breadcrumbs where only a few should exist, wondering if Apollo's usage of URLSession is causing Sentry to add breadcrumbs repeatedly. Example event: us.sentry.io.json This feels similar to https://github.com/getsentry/sentry-cocoa/issues/2971, let me know if you'd prefer that I make a separate issue to investigate this.

lhunath avatar Apr 29 '24 15:04 lhunath

@lhunath, it could be related to #2971, but it doesn't have to be. Please open a separate issue for this, as I don't think it's related to this one.

philipphofmann avatar Apr 30 '24 12:04 philipphofmann