Files
SnapOtter/apps/api/package.json
T
SnapOtterandGitHub 3fb8164fa5 feat: add OpenTelemetry distributed tracing (enterprise) (#232)
* feat(tracing): add OpenTelemetry dependencies and --import preload flag

* feat(enterprise): add distributed_tracing feature gate

* feat(tracing): add SDK bootstrap with enterprise gating

* fix(tracing): correct test coverage for enterprise-unavailable path and prevent double-init

Test 2 now mocks @snapotter/enterprise to throw an import error, exercising
the catch block in the preload. Test 3 imports with no endpoint so the preload
is a no-op, avoiding leaked SDK from double-initialization. Added idempotency
guard to initTracing() as a safety net.

* feat(tracing): add Pino trace mixin and shared logger

When OTel tracing is active, every Pino log line now includes traceId,
spanId, and traceFlags fields for log-to-trace correlation. The mixin
is a no-op when no SDK is registered (community users).

* feat(tracing): add _otel to ToolJobData and inject trace context at enqueue

Add optional _otel carrier field to ToolJobData for W3C trace context
propagation across BullMQ job boundaries. When an active OTel span exists,
propagation.inject() writes traceparent/tracestate into the job data before
queue.add(). When no SDK is registered (community edition), the carrier
stays empty and _otel remains undefined -- zero overhead.

* feat(tracing): extract trace context and create spans in BullMQ worker

* feat(tracing): inject trace context into Python sidecar calls

* feat(tracing): add trace context extraction to Python sidecar

* feat(tracing): add shutdownTracing to graceful shutdown sequence

* feat(tracing): enrich HTTP spans with tool_id and user_id attributes

* docs: add OpenTelemetry env var documentation to .env.example

* test(tracing): add lifecycle integration tests for trace propagation

* fix(tracing): inject trace context into pipeline and batch flow jobs

* fix(tracing): add sidecar.execute Node-side span and remove unnecessary comment

Wraps PythonDispatcher.run() with a sidecar.execute span on the Node
side so traces show the full round-trip (Node span -> Python span).
Also removes an obvious comment from logger.ts.
2026-06-15 12:53:06 +08:00

95 lines
2.9 KiB
JSON

{
"name": "@snapotter/api",
"version": "1.17.1",
"private": true,
"type": "module",
"scripts": {
"dev": "PORT=13490 tsx watch --import ./src/tracing.ts src/index.ts",
"build": "tsc",
"start": "tsx --import ./src/tracing.ts src/index.ts",
"lint": "biome check src/",
"typecheck": "tsc --noEmit",
"clean": "rm -rf dist",
"migrate:sqlite": "tsx src/db/migrate-from-sqlite.ts"
},
"dependencies": {
"@fastify/cookie": "^11.0.2",
"@fastify/cors": "^11.0.0",
"@fastify/multipart": "^9.0.0",
"@fastify/rate-limit": "^10.2.0",
"@fastify/static": "^9.1.3",
"@neplex/vectorizer": "^0.1.0",
"@node-saml/node-saml": "^5.1.0",
"@opentelemetry/api": "^1.9.1",
"@opentelemetry/exporter-trace-otlp-http": "^0.219.0",
"@opentelemetry/instrumentation-aws-sdk": "^0.74.0",
"@opentelemetry/instrumentation-fastify": "^0.57.0",
"@opentelemetry/instrumentation-http": "^0.219.0",
"@opentelemetry/instrumentation-ioredis": "^0.67.0",
"@opentelemetry/instrumentation-pg": "^0.71.0",
"@opentelemetry/resources": "^2.8.0",
"@opentelemetry/sdk-node": "^0.219.0",
"@opentelemetry/sdk-trace-base": "^2.8.0",
"@opentelemetry/semantic-conventions": "^1.41.1",
"@scalar/fastify-api-reference": "^1.57.5",
"@sentry/node": "^10.55.0",
"@snapotter/ai": "workspace:*",
"@snapotter/doc-engine": "workspace:*",
"@snapotter/enterprise": "workspace:*",
"@snapotter/image-engine": "workspace:*",
"@snapotter/media-engine": "workspace:*",
"@snapotter/shared": "workspace:*",
"archiver": "^7.0.1",
"better-sqlite3": "^11.7.0",
"bullmq": "^5.78.0",
"bwip-js": "^4.11.1",
"dotenv": "^16.4.0",
"drizzle-orm": "^0.45.2",
"exceljs": "^4.4.0",
"exif-reader": "^2.0.3",
"fast-xml-parser": "^5.8.0",
"fastify": "^5.8.5",
"fflate": "^0.8.3",
"ioredis": "^5.10.1",
"js-yaml": "^4.2.0",
"mupdf": "^1.27.0",
"openid-client": "^6.8.4",
"opentype.js": "^2.0.0",
"otpauth": "^9.5.1",
"p-queue": "^9.3.0",
"papaparse": "^5.5.3",
"pdfkit": "^0.18.0",
"pg": "^8.21.0",
"pino": "^10.3.1",
"pino-roll": "^4.0.0",
"playwright": "^1.60.0",
"posthog-node": "^5.35.9",
"potrace": "^2.1.8",
"prom-client": "^15.1.3",
"qrcode": "^1.5.4",
"sharp": "^0.34.5",
"tar": "^7.5.16",
"tsx": "^4.22.4",
"yauzl": "^3.4.0",
"zod": "^3.24.0",
"zxing-wasm": "^3.1.0"
},
"devDependencies": {
"@types/archiver": "^7.0.0",
"@types/better-sqlite3": "^7.6.0",
"@types/js-yaml": "^4.0.9",
"@types/node": "^22.19.19",
"@types/opentype.js": "^1.3.10",
"@types/papaparse": "^5.5.2",
"@types/pdfkit": "^0.17.6",
"@types/pg": "^8.20.0",
"@types/potrace": "^2.1.5",
"@types/qrcode": "^1.5.6",
"@types/tar": "^7.0.87",
"@types/yauzl": "^3.3.0",
"drizzle-kit": "^0.31.0",
"typescript": "^5.7.0"
},
"license": "AGPL-3.0"
}