Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Apollo server plugin #1703

Open
villesau opened this issue Mar 11, 2022 · 6 comments
Open

Feature request: Apollo server plugin #1703

villesau opened this issue Mar 11, 2022 · 6 comments
Labels
backlog We hope to fix this feature/bug in the future feature request Request for a new feature

Comments

@villesau
Copy link

Description

Apollo server is a popular framework and has a special way of handling errors. Would make sense if Bugsnag would have 1st party package handling Apollo server errors.

Describe the solution you'd like

Either a plugin, or a function passed to apollos formatError hook.

@johnkiely1
Copy link
Member

Hi @villesau,

Thanks for the suggestion. We are already looking into ways to better support Apollo Server/GraphQL errors so this is definitely on our radar. We don't have any timeframes at this stage or exactly what it would look like but we will let you know of updates here.

@johnkiely1 johnkiely1 added feature request Request for a new feature backlog We hope to fix this feature/bug in the future labels Mar 18, 2022
@villesau
Copy link
Author

Nice, thanks for the info!

I've tried this:

  formatError: error => {
    Bugsnag.notify(error);
    return error;
  },

But it does not work and needs improvement to capture stacktraces and error details. Apollo throws GraphQLError which holds the stacktrace differently. Here are further details of error handling: https://www.apollographql.com/docs/apollo-server/data/errors/

@villesau
Copy link
Author

villesau commented Mar 19, 2022

@johnkiely1 something like this could be a good starting point:

const bugsnagPlugin = (): ApolloServerPlugin => ({
  requestDidStart: async () => ({
    async didEncounterErrors(requestContext) {
      requestContext.errors.forEach(error => {
        Bugsnag.notify(error, event => {
          event.addMetadata('GraphQLMetadata', {
            path: error.path
          });
        });
      });
    }
  })
});

See this for the reference: https://www.apollographql.com/docs/apollo-server/integrations/plugins-event-reference/#didencountererrors

There's likely plenty of good heuristics that could be added as a metadata.

@villesau
Copy link
Author

villesau commented Oct 6, 2022

@johnkiely1 any news on this? Apollo is more popular than many of the other plugins provided so far.

@villesau
Copy link
Author

villesau commented Oct 6, 2022

This is how we currently forward apollo errors to bugsnag:


const notifyGraphqlError = (
  error: Error,
  graphqlError: GraphQLError,
  request: GraphQLRequest
) => {
  Bugsnag.notify(error, event => {
    event.addMetadata('GraphQLMetadata', {
      path: graphqlError.path,
      source: graphqlError.source,
      graphqlError: error
    });

    event.addMetadata('request', {
      // @ts-expect-error raw not found
      headers: request?.http?.headers?.raw?.(),
      url: request?.http?.url
    });
  });
};

const bugsnagPlugin = (): ApolloServerPlugin => ({
  requestDidStart: async () => ({
    async didEncounterErrors(requestContext) {
      requestContext.errors.forEach(error => {
        console.log(error);
        notifyGraphqlError(
          // prefer reporting the original error over the more generic grpahql error
          error.originalError ?? error,
          error,
          requestContext.request
        );
      });
    }
  })
});

@johnkiely1
Copy link
Member

Hi @villesau, unfortunately we don't have any updates at this time. This work is still on our backlog but we have not yet been able to get to it. We will update here as soon as we have any information to share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog We hope to fix this feature/bug in the future feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

2 participants