autotel
Version:
Write Once, Observe Anywhere
54 lines (52 loc) • 2.22 kB
JavaScript
import { s as init } from "./init-BS2JVkrL.js";
import { loadYamlConfig } from "./yaml-config.js";
import * as nodeModule from "node:module";
import { createAddHookMessageChannel } from "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 } = createAddHookMessageChannel();
nodeModule.register("import-in-the-middle/hook.mjs", import.meta.url, registerOptions);
const yamlConfig = loadYamlConfig();
const autoInstrumentationsEnv = process.env.AUTOTEL_INTEGRATIONS;
const autoInstrumentations = autoInstrumentationsEnv === "true" ? true : autoInstrumentationsEnv ? autoInstrumentationsEnv.split(",").map((s) => s.trim()) : yamlConfig?.autoInstrumentations ?? ["http", "express"];
init({
service: yamlConfig?.service ?? process.env.OTEL_SERVICE_NAME ?? "unknown-service",
debug: yamlConfig?.debug ?? process.env.AUTOTEL_DEBUG === "true",
autoInstrumentations
});
//#endregion
export { };
//# sourceMappingURL=auto.js.map