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

chore: add sentry error tracker #1507

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ jobs:
echo "//npm.pkg.github.com/:_authToken=${{ secrets.ORG_GITHUB_PACKAGES_PAT }}" > ~/.npmrc
echo "registry=https://npm.pkg.github.com/dasch-swiss" >> ~/.npmrc
- run: make docker-publish
- run: npm run sentry:sourcemaps
env:
SECRET_VARIABLE: ${{ secrets.SENTRY_AUTH_TOKEN }}

trigger-dev-deployment:
name: Trigger deployment to DEV
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ Thumbs.db
#E2E
/.nx
apps/dsp-app/cypress/screenshots

# Sentry Config File
.sentryclirc
14 changes: 13 additions & 1 deletion apps/dsp-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ClipboardModule } from '@angular/cdk/clipboard';
import { CommonModule } from '@angular/common';
import { HTTP_INTERCEPTORS, HttpClient, HttpClientModule } from '@angular/common/http';
import { ErrorHandler, NgModule, NgZone } from '@angular/core';
import { APP_INITIALIZER, ErrorHandler, NgModule, NgZone } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { Router } from '@angular/router';
import { CKEditorModule } from '@ckeditor/ckeditor5-angular';
import { MatJDNConvertibleCalendarDateAdapterModule } from '@dasch-swiss/jdnconvertiblecalendardateadapter';
import { AdvancedSearchComponent } from '@dasch-swiss/vre/advanced-search';
Expand Down Expand Up @@ -35,6 +36,7 @@ import {
} from '@dasch-swiss/vre/shared/app-string-literal';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import * as Sentry from '@sentry/angular-ivy';
import { IMaskModule } from 'angular-imask';
import { AngularSplitModule } from 'angular-split';
import { PdfViewerModule } from 'ng2-pdf-viewer';
Expand Down Expand Up @@ -408,6 +410,16 @@ export function httpLoaderFactory(httpClient: HttpClient) {
useClass: IiifWithCredentialsInterceptor,
multi: true,
},
{
provide: Sentry.TraceService,
deps: [Router],
},
{
provide: APP_INITIALIZER,
useFactory: () => () => {},
deps: [Sentry.TraceService],
multi: true,
},
],
bootstrap: [AppComponent],
})
Expand Down
27 changes: 24 additions & 3 deletions apps/dsp-app/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppConfigToken } from '@dasch-swiss/vre/shared/app-config';
import * as Sentry from '@sentry/angular-ivy';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

function initSentry(environmentName: string) {
Sentry.init({
dsn: 'https://20bfc69ec9e457239886c1128cc17928@o4506122165747712.ingest.us.sentry.io/4506122171252736',
environment: environmentName,
release: environment.version,
integrations: [
Sentry.browserTracingIntegration(),
Sentry.replayIntegration({
maskAllText: false,
blockAllMedia: false,
}),
],
// Performance Monitoring
tracesSampleRate: 1.0, // Capture 100% of the transactions
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
tracePropagationTargets: ['localhost', /^https:\/\/yourserver\.io\/api/],
Copy link
Contributor

Choose a reason for hiding this comment

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

you dont need to specify the server here?

// Session Replay
replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
});
}

function configListener() {
try {
const configuration = JSON.parse(this.responseText);

initSentry(configuration.instrumentation.environment);
// pass config to bootstrap process using an injection token
// which will make the encapsulated value available inside
// services that inject this token
Expand All @@ -19,7 +41,6 @@ function configListener() {
console.error(error);
}
}

function configFailed() {
console.error('Error: retrieving config.json');
}
Expand Down
13 changes: 11 additions & 2 deletions libs/vre/shared/app-error-handler/src/lib/app-error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ErrorHandler, Injectable, NgZone } from '@angular/core';
import { ApiResponseError } from '@dasch-swiss/dsp-js';
import { AppConfigService } from '@dasch-swiss/vre/shared/app-config';
import { NotificationService } from '@dasch-swiss/vre/shared/app-notification';
import * as Sentry from '@sentry/angular-ivy';
import { SentryErrorHandler } from '@sentry/angular-ivy';
import { AjaxError } from 'rxjs/ajax';
import { AppError } from './app-error';

Expand All @@ -25,8 +27,11 @@ export class AppErrorHandler implements ErrorHandler {
this.handleHttpErrorResponse(error);
} else if (error instanceof AppError) {
this.displayNotification(error.message);
} else if (this._appConfig.dspInstrumentationConfig.environment !== 'prod') {
console.error(error);
} else {
if (this._appConfig.dspInstrumentationConfig.environment !== 'prod') {
console.error(error);
}
this.sendErrorToSentry(error);
}
}

Expand Down Expand Up @@ -85,4 +90,8 @@ export class AppErrorHandler implements ErrorHandler {
this.displayNotification(invalidRequestRegexMatch[1]);
}
}

private sendErrorToSentry(error: any) {
Sentry.captureException(error);
}
}