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

feat: sentry integration #470

Merged
merged 13 commits into from
Dec 11, 2024
Merged

feat: sentry integration #470

merged 13 commits into from
Dec 11, 2024

Conversation

Kingcedru
Copy link
Contributor

@Kingcedru Kingcedru commented Dec 3, 2024

Describe your changes

Integrated Sentry for logging errors in production.

Issue ticket number and link

Checklist before requesting a review

  • Sentry is setup and configured to the DREC backend account
  • Sentry logs all the errors and warnings happening in the backend
  • We log errors based on the environments production, stage and dev
  • Sentry shouldn't be log errors happening in local development
  • I have performed a self-review of my code
  • No existing features have been broken without good reason.
  • The code style guideline have been followed
  • Documentation has been updated to reflect your changes.

Testing the implementation

  • Create this endpoint
@Get('/test-sentry')
  @UseGuards(AuthGuard('jwt'), PermissionGuard)
  @Permission('Read')
  @ACLModules('READS_MANAGEMENT_CRUDL')
  async throwTestError(): Promise<boolean> {
    throw new HttpException(
      'Test Sentry Error',
      HttpStatus.INTERNAL_SERVER_ERROR,
    );
  }

Add this variables in the .env file

SENTRY_DSN="" //add the sentry url
NODE_ENV= 'production', 'staging', 'development', or 'local'

choose one either production, staging, local

@Kingcedru Kingcedru linked an issue Dec 3, 2024 that may be closed by this pull request
divinecharlotte
divinecharlotte previously approved these changes Dec 9, 2024
@@ -5,7 +5,7 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { useContainer } from 'class-validator';
import fs from 'fs';
import { DrecModule } from './drec.module';

import './instrument';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we call this sentry why instrument ?

if (process.env.NODE_ENV !== 'local') {
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.NODE_ENV,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should separate the environment here with process.env.NODE_ENV.

process.env.NODE_ENV is primarily used to indicate if we are running in local or built (production) mode.

We should have an env Variable that we will assign to the environment property that will be called SENTRY_ENV

We should disable reporting if process.env.NODE_ENV is not equal to production

@musayann musayann merged commit ecd27c6 into develop Dec 11, 2024
9 checks passed
@musayann musayann deleted the ft/sentry-integration branch December 11, 2024 16:46
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

Successfully merging this pull request may close these issues.

Integrate Sentry For error monitoring In The backend
3 participants