Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'dotenv/config';
import './instrument';

import healthRouter, { setHealthRuntimeState } from './routes/health';
import authRouter from './routes/auth';
Expand Down Expand Up @@ -42,7 +42,6 @@ import { withTransaction, type PoolClient } from './core';
import { bootstrapAllSchemas } from './schema-bootstrap';
import { ensureDemoAccountsSeeded } from './services/DemoAccountService';
import { ApiError, log, serializeError } from './core/errors';
import { initBackendErrorTracking } from './core/errorTracking';
import {
getPermissionsForRole,
normalizeUserRole,
Expand Down Expand Up @@ -99,7 +98,6 @@ const allowedOrigins = buildAllowedCorsOrigins(env.CORS_ORIGIN);

const app = express();
app.use(securityHeaders);
initBackendErrorTracking();
initEmailJobs();
installDatabaseApm(pool);
startApmMonitoring();
Expand Down
8 changes: 8 additions & 0 deletions backend/src/instrument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Loaded first by index.ts. Sentry must initialize before express, http and pg are required so its
// OpenTelemetry instrumentation can patch them; otherwise errors still reach Sentry through the
// error handler, but request tracing records nothing. The build is CommonJS, so import order is
// load order.
import 'dotenv/config';
import { initBackendErrorTracking } from './core/errorTracking';

initBackendErrorTracking();
12 changes: 11 additions & 1 deletion src/lib/errorTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,21 @@ export function getCurrentFrontendErrorTrackingConfig() {
export function initFrontendErrorTracking(config = getCurrentFrontendErrorTrackingConfig()) {
if (!config.enabled || initialized) return;

const tracingEnabled = config.tracesSampleRate > 0;
Sentry.init({
dsn: config.dsn,
environment: config.environment,
release: config.release,
tracesSampleRate: config.tracesSampleRate,
// Page loads, navigations and fetches become traces only when a sample rate is set.
...(tracingEnabled
? {
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: config.tracesSampleRate,
// Continue the trace into the API so one request shows up across web and backend. The
// backend's CORS reflects requested headers, so sentry-trace and baggage are allowed.
tracePropagationTargets: ['localhost', /^https:\/\/api\.kaffepos\.my\.id\//],
}
: {}),
});
initialized = true;
}
Expand Down
Loading