getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.88k stars 1.55k forks source link

Serverless graphql not reporting errors #4155

Closed dborstelmann closed 2 years ago

dborstelmann commented 2 years ago

I have followed this document directly: https://blog.sentry.io/2020/07/22/handling-graphql-errors-using-sentry

Running local servers like so works fine and reports to sentry:

import * as Sentry from '@sentry/node';
import { ApolloServer } from 'apollo-server';
import { SENTRY_OPTIONS, serverOptions } from 'index';

Sentry.init(SENTRY_OPTIONS);

const server = new ApolloServer(serverOptions);

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

However, when you switch it to a lambda using @sentry/serverless, the errors don't get populated to sentry like so:

import * as Sentry from '@sentry/serverless';
import { ApolloServer } from 'apollo-server-lambda';
import { createContext } from 'context';
import { schema } from 'resolvers';

const SENTRY_DSN = 'redacted';

export const SENTRY_OPTIONS: Sentry.NodeOptions = {
  env: 'redacted',
  tracesSampleRate: 1.0,
  dsn: SENTRY_DSN,
  release: process.env.RELEASE,
};

Sentry.AWSLambda.init(SENTRY_OPTIONS);

export const serverOptions = {
  context: createContext,
  plugins,
  schema,
};

const server = new ApolloServer(serverOptions);

export const serverlessHandler = Sentry.AWSLambda.wrapHandler(
  server.createHandler(),
);

Any idea why this could be? The apollo plugins iterates through the errors and runs captureException in withScore as you can see in the docs.

EDIT: by the way, the warm start lambda function slows from ~500ms to ~2.5s with this change, while cold starts are always about ~4.5s.

dborstelmann commented 2 years ago

Adding debug context (FYI this doesn't always show in the logs):

2021-11-13T01:08:55.917Z    281c54bd-3052-4b7d-a6f6-525da472a5ee    ERROR   Sentry Logger [Error]: Error while sending event: Error: connect ETIMEDOUT 34.120.195.249:443
--
2021-11-13T01:08:55.918Z    281c54bd-3052-4b7d-a6f6-525da472a5ee    ERROR   Sentry Logger [Error]: Error while sending event: Error: connect ETIMEDOUT 34.120.195.249:443
2021-11-13T01:08:55.918Z    281c54bd-3052-4b7d-a6f6-525da472a5ee    ERROR   Sentry Logger [Error]: Error while sending event: Error: connect ETIMEDOUT 34.120.195.249:443
2021-11-13T01:08:55.918Z    281c54bd-3052-4b7d-a6f6-525da472a5ee    ERROR   Sentry Logger [Error]: Error while sending session: Error: connect ETIMEDOUT 34.120.195.249:443
2021-11-13T01:08:55.918Z    281c54bd-3052-4b7d-a6f6-525da472a5ee    ERROR   Sentry Logger [Error]: Error while sending event: Error: connect ETIMEDOUT 34.120.195.249:443
2021-11-13T01:08:55.918Z    281c54bd-3052-4b7d-a6f6-525da472a5ee    ERROR   Sentry Logger [Error]: Error while sending event: Error: connect ETIMEDOUT 34.120.195.249:443
github-actions[bot] commented 2 years ago

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

dborstelmann commented 2 years ago

Would love to see an example of anyone getting AWS Lambda working with Sentry, I still have not been able to.

dborstelmann commented 2 years ago

Turns out this had nothing to do with Sentry (or my implementation for that matter). The Lambdas don't have access to the network by default in a VPC. Feel pretty stupid admitting that was the issue but if anyone else is searching for this issue, you may want to start there as well.

https://www.serverless.com/framework/docs/providers/aws/guide/functions#vpc-configuration