From 314be134a294887a38892c5c6818fb53771450c5 Mon Sep 17 00:00:00 2001 From: jpwilson Date: Tue, 24 Feb 2026 20:57:52 -0600 Subject: [PATCH] fix(agent): use require() for Langfuse and install packages in Dockerfile Static imports fail TS compilation since packages lack type declarations. Use require() with try/catch and explicitly install @langfuse/otel and @opentelemetry/sdk-node in the dist directory during Docker build. --- Dockerfile.railway | 1 + apps/api/src/main.ts | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Dockerfile.railway b/Dockerfile.railway index 348994783..b32d5e282 100644 --- a/Dockerfile.railway +++ b/Dockerfile.railway @@ -34,6 +34,7 @@ RUN npm run build:production WORKDIR /ghostfolio/dist/apps/api COPY ./package-lock.json /ghostfolio/dist/apps/api/ RUN npm install +RUN npm install @langfuse/otel @opentelemetry/sdk-node --save 2>/dev/null || true COPY .config /ghostfolio/dist/apps/api/.config/ COPY prisma /ghostfolio/dist/apps/api/prisma/ COPY package.json /ghostfolio/dist/apps/api/ diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index a65e6f694..33504c836 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -19,16 +19,23 @@ import helmet from 'helmet'; import { AppModule } from './app/app.module'; import { environment } from './environments/environment'; -import { NodeSDK } from '@opentelemetry/sdk-node'; -import { LangfuseSpanProcessor } from '@langfuse/otel'; // Initialize Langfuse OpenTelemetry tracing (must happen before NestJS bootstrap) if (process.env.LANGFUSE_SECRET_KEY) { - const sdk = new NodeSDK({ - spanProcessors: [new LangfuseSpanProcessor()] - }); - sdk.start(); - console.log('Langfuse tracing initialized'); + try { + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { NodeSDK } = require('@opentelemetry/sdk-node'); + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { LangfuseSpanProcessor } = require('@langfuse/otel'); + + const sdk = new NodeSDK({ + spanProcessors: [new LangfuseSpanProcessor()] + }); + sdk.start(); + console.log('Langfuse tracing initialized'); + } catch (error) { + console.warn('Langfuse tracing not available:', error.message); + } } async function bootstrap() {