autotel
Version:
Write Once, Observe Anywhere
1 lines • 3.37 kB
Source Map (JSON)
{"version":3,"file":"auto.cjs","names":["nodeModule","loadYamlConfig","init"],"sources":["../src/auto.ts"],"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\n// namespace import for browser-bundler compat — see node-require.ts\nimport * as nodeModule 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();\nnodeModule.register(\n 'import-in-the-middle/hook.mjs',\n import.meta.url,\n registerOptions,\n);\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAM,EAAE,0EAAgD;AACxDA,YAAW,SACT,gFAEA,eACF;AAGA,MAAM,aAAaC,mCAAe;AAGlC,MAAM,0BAA0B,QAAQ,IAAI;AAC5C,MAAM,uBAIJ,4BAA4B,SACxB,OACA,0BACE,wBAAwB,MAAM,GAAG,CAAC,CAAC,KAAK,MAAM,EAAE,KAAK,CAAC,IACrD,YAAY,wBAAwB,CAAC,QAAQ,SAAS;AAI/DC,kBAAK;CACH,SACE,YAAY,WAAW,QAAQ,IAAI,qBAAqB;CAC1D,OAAO,YAAY,SAAS,QAAQ,IAAI,kBAAkB;CAC1D;AACF,CAAC"}