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

aws-sdk errors not being logged

Open Sammaye opened this issue 2 years ago • 6 comments

Is there an existing issue for this?

  • [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [X] I have reviewed the documentation https://docs.sentry.io/
  • [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/angular

SDK Version

7.34.0

Framework Version

4.17.6

Link to Sentry event

https://delenta.sentry.io/issues/3903038744/?project=6739047&query=is%3Aunresolved&referrer=issue-stream

SDK Setup

            global.process.on('uncaughtException', (error) => {
            });

            const sentryOptions = {
                environment: config.APP_ENV === 'DEV'
                    ? 'development'
                    : (
                        config.APP_ENV.includes('ALPHA')
                            ? 'alpha'
                            : (config.APP_ENV === 'BETA' ? 'beta' : 'production')
                    ),
                dsn: config.LOGS_SENTRY_DSN,
                // Set tracesSampleRate to 1.0 to capture 100%
                // of transactions for performance monitoring.
                // We recommend adjusting this value in production
                tracesSampleRate: 0.25,
                integrations: integrations => {
                    const newIntegrations = integrations.filter(integration =>
                        integration.name !== 'OnUncaughtException' &&
                        integration.name !== 'Http' &&
                        integration.name !== 'LocalVariables'
                    );

                    newIntegrations.push(
                        new Sentry.Integrations.OnUncaughtException({exitEvenIfOtherHandlersAreRegistered: false}),
                        new Sentry.Integrations.Http({tracing: true}),
                        new Sentry.Integrations.LocalVariables({
                            captureAllExceptions: true,
                        })
                    );

                    if (app) {
                        newIntegrations.push(
                            // enable Express.js middleware tracing
                            new Tracing.Integrations.Express({app}),
                        );
                    }

                    return newIntegrations;
                },
                beforeSend: function(event, hint) {
                    return event;
                }
            };

            Sentry.init(sentryOptions);

Steps to Reproduce

I noticed this nasty issue on my winston implementation as well.

aws-sdk errors come in as Error type but for some reason they simply do not work properly so in my old winston logger I overcame it with converting the error to a new Error when I got it.

This is a quick basic hack I did:

            if (err instanceof Error && err.requestId) {
                // This is a workaround for errors that have custom
                // properties, like AWS SDK errors, they do not seem to work
                // with Winston `winston.format.errors({stack: true})` so
                // we copy the error object to a new fresh error object which seems to work
                const errc = new Error(err.message);
                errc.stack = err.stack;
                err = errc;

                req.error(err);
            }

Expected Result

The error comes in as shown in the linked error, this was from me manually hacking around the issue

Actual Result

Error not logged at all as shown by no console.log in beforeSend

Sammaye avatar Jan 28 '23 17:01 Sammaye

Hey @Sammaye thanks for writing in. Maybe this is related to our isError check: https://github.com/getsentry/sentry-javascript/blob/a6c6b2a9e69fefdc5b2817232d3c63d751e189b3/packages/browser/src/eventbuilder.ts#L228, and we don't correctly identify what is given by aws as an error.

Could you log out the err object? What fields does it have? What about if you call err.toString(), what do you get?

A reproduction app is also very helpful!

AbhiPrasad avatar Jan 31 '23 17:01 AbhiPrasad

To reproduce with a AWS account you might possess you can simply make a single route express app and add:

        const tempParams = { Bucket: 'somenonexistewntbucket', Key: 'gibberish' };
        const commonFile = await new AWS.S3({accesskeyId, secretAccessKey}).getObject(tempParams).promise();
        const commonFileAsStream = await new AWS.S3({accesskeyId, secretAccessKey}).getObject(tempParams).createReadStream();

It should log out the error I linked above.

As for the shape of the error, hmm using err.toString I just get the exception mesage:

NoSuchBucket: The specified bucket does not exist

Loggign the error I just get the stack trace output as standard, the only way I could even see the requestId property was since I checked the aws-sdk library documentation for it

Sammaye avatar Jan 31 '23 19:01 Sammaye

Well isError should be fine https://github.com/getsentry/sentry-javascript/blob/a6c6b2a9e69fefdc5b2817232d3c63d751e189b3/packages/utils/src/is.ts#L16 since that is a more complex version of when I check err inastanceof Error for the hack I posted above

Sammaye avatar Jan 31 '23 19:01 Sammaye

In fact using your code on the aws error I get

[object Error]

So valid

Sammaye avatar Jan 31 '23 19:01 Sammaye

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 🥀

github-actions[bot] avatar Feb 22 '23 00:02 github-actions[bot]

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 remove the label Waiting for: Community, I will leave it alone ... forever!


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

getsantry[bot] avatar May 16 '24 07:05 getsantry[bot]