Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat: add sentry to worker (#1472)

Max Deichmann9690314f3e3b
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 08463aacaf..0f5502ac50 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -511,6 +511,12 @@ importers:
'@langfuse/shared':
specifier: workspace:*
version: link:../packages/shared
+ '@sentry/node':
+ specifier: ^7.107.0
+ version: 7.107.0
+ '@sentry/profiling-node':
+ specifier: ^7.102.1
+ version: 7.107.0
backoff:
specifier: ^2.5.0
version: 2.5.0
@@ -8656,7 +8662,7 @@ packages:
eslint: 8.57.0
eslint-import-resolver-node: 0.3.9
eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/[email protected])([email protected])([email protected])([email protected])
- eslint-plugin-import: 2.29.1(@typescript-eslint/[email protected])([email protected])([email protected])
+ eslint-plugin-import: 2.29.1(@typescript-eslint/[email protected])([email protected])
eslint-plugin-jsx-a11y: 6.8.0([email protected])
eslint-plugin-react: 7.34.1([email protected])
eslint-plugin-react-hooks: 4.6.0([email protected])
@@ -8729,7 +8735,7 @@ packages:
enhanced-resolve: 5.16.0
eslint: 8.57.0
eslint-module-utils: 2.8.1(@typescript-eslint/[email protected])([email protected])([email protected])([email protected])
- eslint-plugin-import: 2.29.1(@typescript-eslint/[email protected])([email protected])([email protected])
+ eslint-plugin-import: 2.29.1(@typescript-eslint/[email protected])([email protected])
fast-glob: 3.3.2
get-tsconfig: 4.7.3
is-core-module: 2.13.1
@@ -8751,7 +8757,7 @@ packages:
debug: 4.3.4([email protected])
enhanced-resolve: 5.16.0
eslint: 8.57.0
- eslint-module-utils: 2.8.1(@typescript-eslint/[email protected])([email protected])([email protected])
+ eslint-module-utils: 2.8.1(@typescript-eslint/[email protected])([email protected])([email protected])([email protected])
eslint-plugin-import: 2.29.1(@typescript-eslint/[email protected])([email protected])
fast-glob: 3.3.2
get-tsconfig: 4.7.3
@@ -8789,35 +8795,6 @@ packages:
debug: 3.2.7
eslint: 8.57.0
eslint-import-resolver-node: 0.3.9
- eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/[email protected])([email protected])([email protected])([email protected])
- transitivePeerDependencies:
- - supports-color
- dev: true
-
- resolution: {integrity: sha512-rXDXR3h7cs7dy9RNpUlQf80nX31XWJEyGq1tRMo+6GsO5VmTe4UTwtmonAD4ZkAsrfMVDA2wlGJ3790Ys+D49Q==}
- engines: {node: '>=4'}
- peerDependencies:
- '@typescript-eslint/parser': '*'
- eslint: '*'
- eslint-import-resolver-node: '*'
- eslint-import-resolver-typescript: '*'
- eslint-import-resolver-webpack: '*'
- peerDependenciesMeta:
- '@typescript-eslint/parser':
- optional: true
- eslint:
- optional: true
- eslint-import-resolver-node:
- optional: true
- eslint-import-resolver-typescript:
- optional: true
- eslint-import-resolver-webpack:
- optional: true
- dependencies:
- '@typescript-eslint/parser': 6.21.0([email protected])([email protected])
- debug: 3.2.7
- eslint: 8.57.0
eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/[email protected])([email protected])([email protected])
transitivePeerDependencies:
- supports-color
@@ -8875,7 +8852,7 @@ packages:
ignore: 5.3.1
dev: true
resolution: {integrity: sha512-BbPC0cuExzhiMo4Ff1BTVwHpjjv28C5R+btTOGaCRC7UEz801up0JadwkeSk5Ued6TG34uaczuVuH6qyy5YUxw==}
engines: {node: '>=4'}
peerDependencies:
diff --git a/worker/package.json b/worker/package.json
index baededcb2f..24f7aa0891 100644
--- a/worker/package.json
+++ b/worker/package.json
@@ -17,6 +17,8 @@
"author": "[email protected]",
"dependencies": {
"@langfuse/shared": "workspace:*",
+ "@sentry/node": "^7.107.0",
+ "@sentry/profiling-node": "^7.102.1",
"backoff": "^2.5.0",
"bullmq": "^5.4.2",
"cors": "^2.8.5",
@@ -31,11 +33,11 @@
"zod": "^3.22.4"
},
"devDependencies": {
- "@types/express-serve-static-core": "^4.17.43",
"@repo/eslint-config": "*",
"@repo/typescript-config": "*",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
+ "@types/express-serve-static-core": "^4.17.43",
"@types/lodash": "^4.14.202",
"@types/node": "^20.11.19",
"@types/pg": "^8.11.2",
diff --git a/worker/src/app.ts b/worker/src/app.ts
index c5100bcf13..61f3afe0e5 100644
--- a/worker/src/app.ts
+++ b/worker/src/app.ts
@@ -1,5 +1,7 @@
import express from "express";
import cors from "cors";
+import * as Sentry from "@sentry/node";
+import { nodeProfilingIntegration } from "@sentry/profiling-node";
import * as middlewares from "./middlewares";
import api from "./api";
@@ -9,6 +11,27 @@ require("dotenv").config();
const app = express();
+Sentry.init({
+ dsn: String(process.env.SENTRY_DSN),
+ integrations: [
+ // enable HTTP calls tracing
+ new Sentry.Integrations.Http({ tracing: true }),
+ // enable Express.js middleware tracing
+ new Sentry.Integrations.Express({ app }),
+ nodeProfilingIntegration(),
+ ],
+ // Performance Monitoring
+ tracesSampleRate: 1.0, // Capture 100% of the transactions
+ // Set sampling rate for profiling - this is relative to tracesSampleRate
+ profilesSampleRate: 1.0,
+});
+
+// The request handler must be the first middleware on the app
+app.use(Sentry.Handlers.requestHandler());
+
+// TracingHandler creates a trace for every incoming request
+app.use(Sentry.Handlers.tracingHandler());
+
app.use(cors());
app.use(express.json());
@@ -19,7 +42,8 @@ app.get<{}, MessageResponse>("/", (req, res) => {
});
app.use("/api/v1", api);
-
+// The error handler must be before any other error middleware and after all controllers
+app.use(Sentry.Handlers.errorHandler());
app.use(middlewares.notFound);
app.use(middlewares.errorHandler);