Skip to content

Commit

Permalink
feat(metrics): integrate Sentry tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed May 18, 2021
1 parent 67ede53 commit 929baa4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
10 changes: 4 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@polyfiller/form-data": "0.0.40",
"@polyfiller/object-fit": "0.0.39",
"@sentry/node": "6.4.0",
"@sentry/tracing": "6.4.0",
"@swc/core": "1.2.57",
"@webcomponents/custom-elements": "1.4.3",
"@webcomponents/shadycss": "1.10.2",
Expand Down
2 changes: 1 addition & 1 deletion src/api/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Server implements IServer {
async initialize(): Promise<void> {
const app = express();

await this.metricsService.initialize();
await this.metricsService.initialize(app);
await this.metricsService.configureRequestHandlers(app);

// Options
Expand Down
2 changes: 1 addition & 1 deletion src/service/metrics/i-metrics-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Express} from "express";

export interface IMetricsService {
initialize(): Promise<void>;
initialize(app: Express): Promise<void>;
configureRequestHandlers(app: Express): Promise<void>;
configureErrorHandlers(app: Express): Promise<void>;
}
2 changes: 1 addition & 1 deletion src/service/metrics/noop-metrics-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {IMetricsService} from "./i-metrics-service";
import {Express} from "express";

export class NoopMetricsService implements IMetricsService {
async initialize(): Promise<void> {}
async initialize(_app: Express): Promise<void> {}

async configureRequestHandlers(_app: Express): Promise<void> {}

Expand Down
12 changes: 10 additions & 2 deletions src/service/metrics/sentry-service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import {IMetricsService} from "./i-metrics-service";
import {init, Handlers} from "@sentry/node";
import {init, Handlers, Integrations} from "@sentry/node";
import {Integrations as TracingIntegrations} from "@sentry/tracing";
import {environment} from "../../environment/environment";
import {Express} from "express";

export class SentryService implements IMetricsService {
async initialize(): Promise<void> {
async initialize(app: Express): Promise<void> {
init({
dsn: environment.SENTRY_DSN,
integrations: [
// enable HTTP calls tracing
new Integrations.Http({tracing: true}),
// enable Express.js middleware tracing
new TracingIntegrations.Express({app})
],
tracesSampleRate: environment.NODE_ENV === "development" ? 1.0 : 0.5
});
}

async configureRequestHandlers(app: Express): Promise<void> {
app.use(Handlers.requestHandler());
app.use(Handlers.tracingHandler());
}

async configureErrorHandlers(app: Express): Promise<void> {
Expand Down

0 comments on commit 929baa4

Please sign in to comment.