autotel
Version:
Write Once, Observe Anywhere
55 lines (53 loc) • 2.41 kB
JavaScript
const require_chunk = require('./chunk-C_NdSu1c.cjs');
const require_init = require('./init-BXiuPK6j.cjs');
const require_yaml_config = require('./yaml-config.cjs');
let node_module = require("node:module");
node_module = require_chunk.__toESM(node_module, 1);
let import_in_the_middle = require("import-in-the-middle");
//#region src/auto.ts
/**
* Zero-config ESM instrumentation with auto-init from YAML/environment variables
*
* This module provides the simplest possible setup for OpenTelemetry instrumentation.
* Just import it and everything is configured from autotel.yaml or environment variables.
*
* Usage with YAML config (recommended):
* ```bash
* # Create autotel.yaml in project root, then:
* tsx --import autotel/auto src/index.ts
* ```
*
* Usage with environment variables:
* ```bash
* OTEL_SERVICE_NAME=my-app tsx --import autotel/auto src/index.ts
* ```
*
* No instrumentation.ts file needed!
*
* Configuration Priority (highest to lowest):
* 1. YAML file (autotel.yaml or AUTOTEL_CONFIG_FILE)
* 2. Environment variables (OTEL_*, AUTOTEL_*)
* 3. Built-in defaults
*
* Environment Variables:
* - OTEL_SERVICE_NAME: Service name (required for meaningful traces)
* - OTEL_EXPORTER_OTLP_ENDPOINT: OTLP collector endpoint (e.g., http://localhost:4318)
* - OTEL_EXPORTER_OTLP_HEADERS: Auth headers (e.g., x-honeycomb-team=YOUR_KEY)
* - AUTOTEL_INTEGRATIONS: Comma-separated list or 'true' for all (default: http,express)
* - AUTOTEL_DEBUG: Set to 'true' to enable console span output
* - AUTOTEL_CONFIG_FILE: Path to YAML config file (overrides autotel.yaml discovery)
*
* @requires Node.js 20.6.0 or later
*/
const { registerOptions } = (0, import_in_the_middle.createAddHookMessageChannel)();
node_module.register("import-in-the-middle/hook.mjs", require("url").pathToFileURL(__filename).href, registerOptions);
const yamlConfig = require_yaml_config.loadYamlConfig();
const autoInstrumentationsEnv = process.env.AUTOTEL_INTEGRATIONS;
const autoInstrumentations = autoInstrumentationsEnv === "true" ? true : autoInstrumentationsEnv ? autoInstrumentationsEnv.split(",").map((s) => s.trim()) : yamlConfig?.autoInstrumentations ?? ["http", "express"];
require_init.init({
service: yamlConfig?.service ?? process.env.OTEL_SERVICE_NAME ?? "unknown-service",
debug: yamlConfig?.debug ?? process.env.AUTOTEL_DEBUG === "true",
autoInstrumentations
});
//#endregion
//# sourceMappingURL=auto.cjs.map