apollographql / apollographql/apollo-server

Allow conditional trace reporting to Apollo Studio based on response of ApolloGateway

Open
#4,844 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
14k
Forks
2k
Avg merge
5h 30m
Merged PRs (30d)
1

Description

# What does this try to solve?

For a GraphQL implementation using Apollo Federation, the usage reporting plugin (used by `ApolloGateway` in this case) currently reports all errors to Apollo Studio based on. The implementing graphs being federated are responsible for conditionally adding the errors to the `extension.ftv1` that is sent to the `ApolloGateway`; this is done in `ApolloServer` by using the inline tracing plugin and providing a function for `rewriteError`.

In the specific use case, I would like to keep all `500` errors and conditionally filter `404` errors based on a couple conditions (and which service it's coming from). In the current state, I must define this logic in my implementing GraphQL servers instead of the `ApolloGateway` instance.

# Why are other approaches unreasonable

If my implementing services use various languages, I will now have to write the same logic in multiple implementations that becomes technical debt.

# Looking forward

We provide a mechanism for conditionally reporting traces with `includeRequest`, but it is called before anything is executed. Instead of calling `includeRequest` at the start of the lifecycle, it could be called in `willSendResponse` that could provide `GraphQLRequestContextWillSendResponse` which would give access to view all the errors and make the conditional decision.

I created a [branch](https://github.com/apollographql/apollo-server/blob/watson/includeResponse/packages/apollo-server-core/src/plugin/usageReporting/plugin.ts#L670) to show what this could look like (I called it [`includeResponse` to test](https://github.com/apollographql/apollo-server/blob/watson/includeResponse/packages/apollo-server-core/src/plugin/usageReporting/options.ts#L97), but shouldn't be called that). This satisfied the use-case requirement outlined.

Contributor guide

Open the contributing guide

Research direction

Start with packages/apollo-server-core/src/plugin/usageReporting/plugin.ts and options.ts, then compare the linked includeResponse branch. Trace how includeRequest is currently invoked and assess the proposed response-stage context. Done should allow ApolloGateway to conditionally report errors from the completed response while preserving the existing usage-reporting behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.