Node.js: ESM-Supported Init

๐Ÿ“˜

In order to support ESM instrumentation, hud's auto init uses --import to be loaded before any other module. This makes sure we can instrument any forthcoming module's functions.

โš ๏ธ

Partial Support: Some functionality is unavailable when using ESM-supported initialization, including limited support for certain endpoint frameworks. For more information contact [email protected].

Copy the code snippet based on your preferred framework.

Fill in the API key provided to you, and your unique service name. Learn more about Hud Configuration.

HUD_ENABLE=true \
HUD_KEY=[YOUR_API_KEY] \
HUD_SERVICE=[YOUR_SERVICE_NAME] \
node --import hud-sdk/register [YOUR_ENTRY_POINT].js
HUD_ENABLE=true \
HUD_KEY=[YOUR_API_KEY] \
HUD_SERVICE=[YOUR_SERVICE_NAME] \
nest start --exec "node --import hud-sdk/register"
HUD_ENABLE=true \
HUD_KEY=[YOUR_API_KEY] \
HUD_SERVICE=[YOUR_SERVICE_NAME] \
NODE_OPTIONS='--import=hud-sdk/register' next start
HUD_ENABLE=true \
HUD_KEY=[YOUR_API_KEY] \
HUD_SERVICE=[YOUR_SERVICE_NAME] \
NODE_OPTIONS='--import=hud-sdk/register' npm run start
//project.json

"my-app": {
  "targets": {
    "serve": {
      "executor": "@nx/js:node",
      "options": {
        "runtimeArgs": ["--import", "hud-sdk/register"],
        //...
      },
    },
  }
}

Note: We use register as the entry point, which is a different entry point than common js.