sentry-cocoa
sentry-cocoa copied to clipboard
Add GraphQL query/mutation to HTTP breadcrumbs
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
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.
We should align with what we already have for GraphQL on Android/Java.
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!
Hey @maxchuquimia, thank you very much!!
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, 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.