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

Bug: Original Error Not Sent to Sentry in AwsStorageException #292

Closed
tnramalho opened this issue Oct 15, 2024 · 2 comments
Closed

Bug: Original Error Not Sent to Sentry in AwsStorageException #292

tnramalho opened this issue Oct 15, 2024 · 2 comments
Assignees

Comments

@tnramalho
Copy link
Collaborator

tnramalho commented Oct 15, 2024

When throwing the following exception:

throw new AwsStorageException({
  safeMessage: 'Error downloading file from S3',
  originalError: error,
});

Only the text 'Error downloading file from S3' appears in Sentry. It seems that the originalError is not being sent to Sentry for better traceability.

Expected Behavior
Both the safeMessage and the originalError should be captured and logged in Sentry, ensuring that the original error information is available for debugging.

Actual Behavior
Currently, only the safeMessage ('Error downloading file from S3') is showing up in Sentry, with no trace of the originalError information.

Steps to Reproduce

Add global exception filter

import { ExceptionsFilter } from '@concepta/nestjs-exception';

// ... 
const exceptionsFilter = app.get(HttpAdapterHost);
 app.useGlobalFilters(new ExceptionsFilter(exceptionsFilter));

Register LoggeModule and LoggerSentryModule
make sure to use proper Sentry configurations

// ... 
 LoggerSentryModule.forRoot({}),
    LoggerModule.forRootAsync({
      inject: [LoggerSentryTransport],
      useFactory: (
        loggerSentryTransport: LoggerSentryTransport,
      ) => {
        return {
          transports: [loggerSentryTransport],
        };
      },
    }),

Create the custom AwsStorageException class:

import {
  RuntimeException,
  RuntimeExceptionContext,
  RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class AwsStorageException extends RuntimeException {
  context: RuntimeExceptionContext;

  constructor(options: RuntimeExceptionOptions) {
    super(options);
    this.errorCode = 'AWS_STORAGE_ERROR';
  }
}

Trigger the exception with the following code snippet:

throw new AwsStorageException({
  safeMessage: 'Error downloading file from S3',
  originalError: error,
});

Check the Sentry logs for the captured exception.

Observe that only the safeMessage is logged, with no trace of the originalError.

Additional Information
Version: 5.0.0-alpha.4

@MrMaz
Copy link
Collaborator

MrMaz commented Oct 15, 2024

Please add this feature to the logger and sentry logger modules and validate agains the scenario reported.

@MrMaz
Copy link
Collaborator

MrMaz commented Oct 21, 2024

Fixed by #293

@MrMaz MrMaz closed this as completed Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants