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
11 changes: 11 additions & 0 deletions apps/api/instrument.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Installs the import-in-the-middle ESM loader hook before any user code
// runs. OpenTelemetry's auto-instrumentation patches modules at require/
// import time, so the hook has to be registered via Node's `--import`
// mechanism — registering it from inside an already-loaded module is too
// late for built-ins like `node:http`. Without this, `getNodeAutoInstrumentations`
// loads but silently never wraps anything in ESM mode.
//
// Usage: node --import ./instrument.mjs --import ./tracing.ts server.ts
import { register } from 'node:module';

register('import-in-the-middle/hook.mjs', import.meta.url);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Declare import-in-the-middle as a direct dependency

instrument.mjs now imports import-in-the-middle/hook.mjs, but apps/api/package.json does not declare import-in-the-middle directly. This currently works only when the package manager hoists that transitive dependency; in non-hoisted or isolated installs (common in CI/deploy/container builds), startup will fail with ERR_MODULE_NOT_FOUND before the API boots. Please add import-in-the-middle to dependencies so the new boot path is deterministic across install environments.

Useful? React with 👍 / 👎.

4 changes: 2 additions & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"description": "REST + state-machine service for pagent",
"main": "server.ts",
"scripts": {
"dev": "node --watch --env-file=.env --experimental-strip-types --import ./tracing.ts server.ts",
"start": "node --experimental-strip-types --import ./tracing.ts server.ts"
"dev": "node --watch --env-file=.env --experimental-strip-types --import ./instrument.mjs --import ./tracing.ts server.ts",
"start": "node --experimental-strip-types --import ./instrument.mjs --import ./tracing.ts server.ts"
},
"dependencies": {
"@hono/node-server": "^1.13.7",
Expand Down
Loading