Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 40ecdbc

Browse files
committed
➕ ajout de sentry pour le tracking des erreurs
1 parent b24445b commit 40ecdbc

File tree

5 files changed

+269
-5
lines changed

5 files changed

+269
-5
lines changed

package-lock.json

Lines changed: 225 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"@ngrx/router-store": "^13.2.0",
2323
"@ngrx/store": "^13.2.0",
2424
"@ngrx/store-devtools": "^13.2.0",
25+
"@sentry/angular": "^7.12.1",
26+
"@sentry/tracing": "^7.12.1",
2527
"@tailwindcss/aspect-ratio": "^0.4.1",
2628
"@tailwindcss/forms": "^0.5.2",
2729
"@tailwindcss/line-clamp": "^0.4.1",

src/app/app.module.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NgModule } from '@angular/core';
1+
import { APP_INITIALIZER, ErrorHandler, NgModule } from '@angular/core';
22
import { HttpClientModule } from '@angular/common/http';
33
import { BrowserModule } from '@angular/platform-browser';
44
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@@ -7,12 +7,14 @@ import { StoreModule } from '@ngrx/store';
77
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
88
import { EffectsModule } from '@ngrx/effects';
99
import { StoreRouterConnectingModule } from '@ngrx/router-store';
10+
import * as Sentry from '@sentry/angular';
1011

1112
import { environment } from '../environments/environment';
1213
import { AppRoutingModule } from './core/routes/app-routing.module';
1314
import { AppComponent } from './core/components/app/app.component';
1415
import { ROOT_REDUCERS } from './core/store/app.store';
1516
import { ROOT_EFFECTS } from './core/store/app.effects';
17+
import { Router } from '@angular/router';
1618

1719
@NgModule({
1820
declarations: [
@@ -30,7 +32,24 @@ import { ROOT_EFFECTS } from './core/store/app.effects';
3032
StoreDevtoolsModule.instrument({ maxAge: 25, logOnly: environment.production }),
3133
StoreRouterConnectingModule.forRoot(),
3234
],
33-
providers: [],
35+
providers: [
36+
{
37+
provide: ErrorHandler,
38+
useValue: Sentry.createErrorHandler({
39+
showDialog: true,
40+
}),
41+
},
42+
{
43+
provide: Sentry.TraceService,
44+
deps: [Router],
45+
},
46+
{
47+
provide: APP_INITIALIZER,
48+
useFactory: () => () => {},
49+
deps: [Sentry.TraceService],
50+
multi: true,
51+
},
52+
],
3453
bootstrap: [AppComponent],
3554
})
3655
export class AppModule { }

src/env.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ declare var process: {
66
NG_APP_BASE_URL: string;
77
NG_APP_API_URL: string;
88
NG_APP_API_VERSION: string;
9-
NG_APP_SENTRY_DSN: string | null;
10-
NG_APP_SENTRY_TRACES_SAMPLE_RATE: string;
9+
NG_APP_SENTRY_DSN: string | undefined;
10+
NG_APP_SENTRY_TRACES_SAMPLE_RATE: number | undefined;
1111
};
1212
};

src/main.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
import { enableProdMode } from '@angular/core';
22
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3+
import * as Sentry from "@sentry/angular";
4+
import { BrowserTracing } from "@sentry/tracing";
35

46
import { AppModule } from './app/app.module';
57
import { environment } from './environments/environment';
68

9+
Sentry.init({
10+
dsn: process.env.NG_APP_SENTRY_DSN,
11+
integrations: [
12+
new BrowserTracing({
13+
tracingOrigins: ["localhost", "https://yourserver.io/api"],
14+
routingInstrumentation: Sentry.routingInstrumentation,
15+
}),
16+
],
17+
18+
// Set tracesSampleRate to 1.0 to capture 100%
19+
// of transactions for performance monitoring.
20+
// We recommend adjusting this value in production
21+
tracesSampleRate: process.env.NG_APP_SENTRY_TRACES_SAMPLE_RATE,
22+
});
23+
724
if (environment.production) {
825
enableProdMode();
926
}
1027

11-
platformBrowserDynamic().bootstrapModule(AppModule)
28+
platformBrowserDynamic()
29+
.bootstrapModule(AppModule)
1230
.catch(err => console.error(err));

0 commit comments

Comments
 (0)