autotel
Version:
Write Once, Observe Anywhere
1 lines • 3.48 kB
Source Map (JSON)
{"version":3,"sources":["../src/auto.ts"],"names":["createAddHookMessageChannel","register","loadYamlConfig","init"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyCA,IAAM,EAAE,eAAA,EAAgB,GAAIA,6CAAA,EAA4B;AACxDC,iBAAA,CAAS,+BAAA,EAAiC,0PAAY,EAAK,eAAe,CAAA;AAG1E,IAAM,aAAaC,gCAAA,EAAe;AAGlC,IAAM,uBAAA,GAA0B,QAAQ,GAAA,CAAI,oBAAA;AAC5C,IAAM,oBAAA,GAIJ,4BAA4B,MAAA,GACxB,IAAA,GACA,0BACE,uBAAA,CAAwB,KAAA,CAAM,GAAG,CAAA,CAAE,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,MAAM,CAAA,GACrD,YAAY,oBAAA,IAAwB,CAAC,QAAQ,SAAS,CAAA;AAI/DC,sBAAA,CAAK;AAAA,EACH,OAAA,EACE,UAAA,EAAY,OAAA,IAAW,OAAA,CAAQ,IAAI,iBAAA,IAAqB,iBAAA;AAAA,EAC1D,KAAA,EAAO,UAAA,EAAY,KAAA,IAAS,OAAA,CAAQ,IAAI,aAAA,KAAkB,MAAA;AAAA,EAC1D;AACF,CAAC,CAAA","file":"auto.cjs","sourcesContent":["/**\n * Zero-config ESM instrumentation with auto-init from YAML/environment variables\n *\n * This module provides the simplest possible setup for OpenTelemetry instrumentation.\n * Just import it and everything is configured from autotel.yaml or environment variables.\n *\n * Usage with YAML config (recommended):\n * ```bash\n * # Create autotel.yaml in project root, then:\n * tsx --import autotel/auto src/index.ts\n * ```\n *\n * Usage with environment variables:\n * ```bash\n * OTEL_SERVICE_NAME=my-app tsx --import autotel/auto src/index.ts\n * ```\n *\n * No instrumentation.ts file needed!\n *\n * Configuration Priority (highest to lowest):\n * 1. YAML file (autotel.yaml or AUTOTEL_CONFIG_FILE)\n * 2. Environment variables (OTEL_*, AUTOTEL_*)\n * 3. Built-in defaults\n *\n * Environment Variables:\n * - OTEL_SERVICE_NAME: Service name (required for meaningful traces)\n * - OTEL_EXPORTER_OTLP_ENDPOINT: OTLP collector endpoint (e.g., http://localhost:4318)\n * - OTEL_EXPORTER_OTLP_HEADERS: Auth headers (e.g., x-honeycomb-team=YOUR_KEY)\n * - AUTOTEL_INTEGRATIONS: Comma-separated list or 'true' for all (default: http,express)\n * - AUTOTEL_DEBUG: Set to 'true' to enable console span output\n * - AUTOTEL_CONFIG_FILE: Path to YAML config file (overrides autotel.yaml discovery)\n *\n * @requires Node.js 20.6.0 or later\n */\n\nimport { register } from 'node:module';\nimport { createAddHookMessageChannel } from 'import-in-the-middle';\nimport { init } from './init';\nimport { loadYamlConfig } from './yaml-config';\n\n// Register ESM hooks first (must happen before any instrumented modules load)\nconst { registerOptions } = createAddHookMessageChannel();\nregister('import-in-the-middle/hook.mjs', import.meta.url, registerOptions);\n\n// Load YAML config if present (init.ts will also load it, but we need values here)\nconst yamlConfig = loadYamlConfig();\n\n// Parse auto-instrumentations from environment variable (fallback if not in YAML)\nconst autoInstrumentationsEnv = process.env.AUTOTEL_INTEGRATIONS;\nconst autoInstrumentations:\n | string[]\n | boolean\n | Record<string, { enabled?: boolean }> =\n autoInstrumentationsEnv === 'true'\n ? true // Enable all auto-instrumentations\n : autoInstrumentationsEnv\n ? autoInstrumentationsEnv.split(',').map((s) => s.trim())\n : (yamlConfig?.autoInstrumentations ?? ['http', 'express']); // YAML > default\n\n// Auto-initialize with YAML config merged with env var defaults\n// init() will load YAML again and merge properly, but we pass overrides here\ninit({\n service:\n yamlConfig?.service ?? process.env.OTEL_SERVICE_NAME ?? 'unknown-service',\n debug: yamlConfig?.debug ?? process.env.AUTOTEL_DEBUG === 'true',\n autoInstrumentations,\n});\n"]}