autotel
Version:
Write Once, Observe Anywhere
121 lines (119 loc) • 3.46 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_tracer_provider = require('./tracer-provider.cjs');
let _opentelemetry_api = require("@opentelemetry/api");
//#region src/config.ts
/**
* Global configuration for OpenTelemetry decorators
*
* Allows users to inject custom loggers, tracers, and meters
* while maintaining sensible defaults.
*/
/**
* Environment-based feature flags for performance optimization
*
* Disables expensive features in development while maintaining
* full observability in production.
*/
const IS_PRODUCTION = process.env.NODE_ENV === "production";
const IS_DEV = process.env.NODE_ENV === "development";
process.env.NODE_ENV;
const FEATURE_FLAGS = {
/** Enable full auto-instrumentation (expensive, production only) */
ENABLE_AUTO_INSTRUMENTATION: IS_PRODUCTION && process.env.autotel_AUTO_INSTRUMENT !== "false",
/** Enable verbose logging (development only) */
ENABLE_VERBOSE_LOGGING: IS_DEV || process.env.autotel_VERBOSE === "true",
/** Enable metrics collection (production only) */
ENABLE_METRICS_BY_DEFAULT: IS_PRODUCTION && process.env.autotel_METRICS !== "false",
/** Enable async resource detection (production only) */
ENABLE_RESOURCE_DETECTION: IS_PRODUCTION && process.env.autotel_RESOURCE_DETECTION === "true",
/** Enable tracing in all environments (can be disabled via autotel_TRACING=false) */
ENABLE_TRACING: process.env.autotel_TRACING !== "false",
/** Enable log redaction for sensitive fields (can be disabled via autotel_REDACTION=false) */
ENABLE_REDACTION: process.env.autotel_REDACTION !== "false"
};
/**
* Internal configuration state
*/
var Config = class {
config = {
tracerName: "app",
meterName: "app",
tracer: require_tracer_provider.getAutotelTracer("app"),
meter: _opentelemetry_api.metrics.getMeter("app")
};
/**
* Get feature flags
*/
get featureFlags() {
return FEATURE_FLAGS;
}
/**
* Update global configuration
*/
configure(options) {
if (options.tracerName) {
this.config.tracerName = options.tracerName;
this.config.tracer = require_tracer_provider.getAutotelTracer(options.tracerName);
}
if (options.meterName) {
this.config.meterName = options.meterName;
this.config.meter = _opentelemetry_api.metrics.getMeter(options.meterName);
}
if (options.tracer) this.config.tracer = options.tracer;
if (options.meter) this.config.meter = options.meter;
}
/**
* Get current configuration
*/
get() {
return this.config;
}
/**
* Reset to defaults (mainly for testing)
*/
reset() {
this.config = {
tracerName: "app",
meterName: "app",
tracer: _opentelemetry_api.trace.getTracer("app"),
meter: _opentelemetry_api.metrics.getMeter("app")
};
}
};
const globalConfig = new Config();
/**
* Configure global instrumentation behavior
*
* @example
* ```typescript
* import { configure } from 'autotel/config'
*
* configure({
* tracerName: 'my-app'
* })
* ```
*/
function configure(options) {
globalConfig.configure(options);
}
/**
* Get current configuration (internal use)
*/
function getConfig() {
return {
...globalConfig.get(),
featureFlags: FEATURE_FLAGS
};
}
/**
* Reset configuration to defaults (internal use - mainly for testing)
*/
function resetConfig() {
globalConfig.reset();
}
//#endregion
exports.FEATURE_FLAGS = FEATURE_FLAGS;
exports.configure = configure;
exports.getConfig = getConfig;
exports.resetConfig = resetConfig;
//# sourceMappingURL=config.cjs.map