autotel-backends 2.12.40 → 2.12.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/datadog.cjs CHANGED
@@ -122,10 +122,10 @@ function createDatadogConfig(config) {
122
122
  const pkgRequire = (0, node_module.createRequire)(typeof __filename === "string" ? __filename : require("url").pathToFileURL(__filename).href);
123
123
  const { BatchLogRecordProcessor } = pkgRequire("@opentelemetry/sdk-logs");
124
124
  const { OTLPLogExporter } = pkgRequire("@opentelemetry/exporter-logs-otlp-http");
125
- cloudConfig.logRecordProcessors = [new BatchLogRecordProcessor(new OTLPLogExporter({
125
+ cloudConfig.logRecordProcessors = [new BatchLogRecordProcessor({ exporter: new OTLPLogExporter({
126
126
  url: `${otlpEndpoint}/v1/logs`,
127
127
  headers: { "dd-api-key": apiKey }
128
- }))];
128
+ }) })];
129
129
  } catch {
130
130
  throw new Error("Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. Install them or set enableLogs: false.");
131
131
  }
@@ -1 +1 @@
1
- {"version":3,"file":"datadog.cjs","names":[],"sources":["../src/datadog.ts"],"sourcesContent":["/**\n * Datadog preset for autotel\n *\n * Provides a simplified configuration helper for Datadog integration\n * with best practices built-in.\n *\n * @example Direct cloud ingestion (serverless, edge)\n * ```typescript\n * import { init } from 'autotel';\n * import { createDatadogConfig } from 'autotel-backends/datadog';\n *\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-lambda',\n * enableLogs: true,\n * }));\n * ```\n *\n * @example Local Datadog Agent (long-running services, Kubernetes)\n * ```typescript\n * import { init } from 'autotel';\n * import { createDatadogConfig } from 'autotel-backends/datadog';\n *\n * init(createDatadogConfig({\n * service: 'my-api',\n * useAgent: true, // No API key needed - Agent handles it\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\nimport type { LogRecordProcessor } from '@opentelemetry/sdk-logs';\n\n// `__filename` exists under CJS (including esbuild's CJS output wrapper) but\n// not pure ESM. `typeof` is safe against an undeclared identifier and lets\n// the conditional pick the working URL in either format.\ndeclare const __filename: string | undefined;\n\n/**\n * Datadog site regions\n */\nexport type DatadogSite =\n | 'datadoghq.com' // US1 (default)\n | 'datadoghq.eu' // EU\n | 'us3.datadoghq.com' // US3\n | 'us5.datadoghq.com' // US5\n | 'ap1.datadoghq.com' // AP1\n | 'ddog-gov.com'; // US1-FED\n\n/**\n * Configuration options for Datadog preset\n */\nexport interface DatadogPresetConfig {\n /**\n * Datadog API key (required for direct cloud ingestion).\n * Not needed if using local Datadog Agent (useAgent: true).\n *\n * Get your API key from:\n * https://app.datadoghq.com/organization-settings/api-keys\n */\n apiKey?: string;\n\n /**\n * Datadog site/region.\n * Determines which Datadog intake endpoint to use.\n *\n * @default 'datadoghq.com' (US1)\n */\n site?: DatadogSite;\n\n /**\n * Service name (required).\n * Appears in Datadog APM, Service Catalog, and all telemetry.\n */\n service: string;\n\n /**\n * Deployment environment (e.g., 'production', 'staging', 'development').\n * Used for environment filtering in Datadog.\n *\n * @default process.env.DD_ENV || process.env.NODE_ENV || 'development'\n */\n environment?: string;\n\n /**\n * Service version for deployment tracking.\n * Enables Deployment Tracking in Datadog APM.\n *\n * @default process.env.DD_VERSION || auto-detected from package.json\n */\n version?: string;\n\n /**\n * Enable log export to Datadog via OTLP.\n *\n * When enabled, this:\n * 1. Sets up OTel Logs SDK with OTLP exporter (for direct OTel logs API usage)\n * 2. Auto-configures OTEL_EXPORTER_OTLP_LOGS_* env vars for pino-opentelemetry-transport\n *\n * For Pino users: Just add pino-opentelemetry-transport to your logger config:\n * ```typescript\n * const logger = pino({\n * transport: {\n * targets: [\n * { target: 'pino-pretty' },\n * { target: 'pino-opentelemetry-transport' }, // Auto-configured!\n * ],\n * },\n * });\n * ```\n *\n * @default false\n */\n enableLogs?: boolean;\n\n /**\n * Use local Datadog Agent instead of direct cloud ingestion.\n *\n * Benefits:\n * - Lower egress costs (Agent aggregates locally)\n * - Advanced features: trace-log correlation, multi-line logs, data scrubbing\n * - 500+ integrations for enrichment\n * - Infrastructure metrics collection\n *\n * Requires: Datadog Agent 7.35+ with OTLP enabled\n *\n * @default false\n */\n useAgent?: boolean;\n\n /**\n * Datadog Agent hostname (when useAgent: true).\n *\n * @default 'localhost'\n */\n agentHost?: string;\n\n /**\n * Datadog Agent OTLP port (when useAgent: true).\n *\n * @default 4318 (OTLP HTTP)\n */\n agentPort?: number;\n\n /**\n * Custom log record processors (advanced).\n * Overrides the default log processor if enableLogs is true.\n */\n logRecordProcessors?: LogRecordProcessor[];\n}\n\n/**\n * Create an autotel configuration optimized for Datadog.\n *\n * This preset handles:\n * - Proper OTLP endpoint configuration (Agent vs direct ingestion)\n * - Direct: https://otlp.{site} → SDK appends /v1/traces, /v1/metrics, /v1/logs\n * - Agent: http://localhost:4318 (default)\n * - Datadog API key authentication headers (direct ingestion only)\n * - Unified service tagging (service, env, version)\n * - Resource attribute best practices\n * - Optional log export configuration\n *\n * @param config - Datadog-specific configuration options\n * @returns AutotelConfig ready to pass to init()\n *\n * @example Simple cloud ingestion\n * ```typescript\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With logs and custom environment\n * ```typescript\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-app',\n * environment: 'production',\n * version: '2.1.0',\n * enableLogs: true,\n * }));\n * ```\n *\n * @example Using local Datadog Agent\n * ```typescript\n * init(createDatadogConfig({\n * service: 'my-api',\n * useAgent: true,\n * agentHost: 'datadog-agent.default.svc.cluster.local', // Kubernetes\n * }));\n * ```\n */\nexport function createDatadogConfig(\n config: DatadogPresetConfig,\n): AutotelConfig {\n const {\n apiKey,\n site = 'datadoghq.com',\n service,\n environment,\n version,\n enableLogs = false,\n useAgent = false,\n agentHost = 'localhost',\n agentPort = 4318,\n logRecordProcessors,\n } = config;\n\n // Validation: API key required for direct ingestion\n if (!useAgent && !apiKey) {\n throw new Error(\n 'Datadog API key is required for direct cloud ingestion. ' +\n 'Either provide apiKey or set useAgent: true to use local Datadog Agent.',\n );\n }\n\n const baseConfig: AutotelConfig = {\n service,\n environment,\n version,\n };\n\n // Local Datadog Agent configuration\n if (useAgent) {\n const agentEndpoint = `http://${agentHost}:${agentPort}`;\n\n // Auto-configure env vars for pino-opentelemetry-transport in agent mode\n if (enableLogs) {\n const logsEndpoint = `http://${agentHost}:${agentPort}/v1/logs`;\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;\n }\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = 'http/protobuf';\n }\n\n // No API key header needed for agent mode - Agent handles authentication\n\n const resourceAttrs = [\n `service.name=${service}`,\n environment ? `deployment.environment=${environment}` : null,\n version ? `service.version=${version}` : null,\n ]\n .filter(Boolean)\n .join(',');\n\n if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {\n process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;\n }\n }\n\n return {\n ...baseConfig,\n endpoint: agentEndpoint,\n // No API key or headers needed - Agent handles authentication\n };\n }\n\n // Direct cloud ingestion configuration\n // Datadog OTLP endpoint: base URL without path (SDK appends /v1/traces, /v1/metrics, /v1/logs)\n const otlpEndpoint = `https://otlp.${site}`;\n const authHeaders = `dd-api-key=${apiKey}`;\n\n const cloudConfig: AutotelConfig = {\n ...baseConfig,\n endpoint: otlpEndpoint,\n headers: authHeaders,\n };\n\n // Add log export if enabled\n if (enableLogs) {\n // Auto-configure env vars for pino-opentelemetry-transport and other OTel log transports\n // These are read by pino-opentelemetry-transport, otlp-logger, and similar libraries\n const logsEndpoint = useAgent\n ? `http://${agentHost}:${agentPort}/v1/logs`\n : `https://otlp.${site}/v1/logs`;\n\n // Only set if not already configured (allow user override)\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;\n }\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = 'http/protobuf';\n }\n\n // Only set API key header for direct cloud ingestion (not agent mode)\n if (!useAgent && apiKey && !process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS = `dd-api-key=${apiKey}`;\n }\n\n // Set resource attributes for service identification\n const resourceAttrs = [\n `service.name=${service}`,\n environment ? `deployment.environment=${environment}` : null,\n version ? `service.version=${version}` : null,\n ]\n .filter(Boolean)\n .join(',');\n\n if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {\n process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;\n }\n\n if (logRecordProcessors) {\n // Use custom processors if provided\n cloudConfig.logRecordProcessors = logRecordProcessors;\n } else {\n // Create default OTLP log exporter\n try {\n const pkgRequire = createRequire(\n typeof __filename === 'string' ? __filename : import.meta.url,\n );\n const { BatchLogRecordProcessor } = pkgRequire(\n '@opentelemetry/sdk-logs',\n );\n const { OTLPLogExporter } = pkgRequire(\n '@opentelemetry/exporter-logs-otlp-http',\n );\n\n cloudConfig.logRecordProcessors = [\n new BatchLogRecordProcessor(\n new OTLPLogExporter({\n url: `${otlpEndpoint}/v1/logs`,\n headers: {\n 'dd-api-key': apiKey,\n },\n }),\n ),\n ];\n } catch {\n throw new Error(\n 'Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. ' +\n 'Install them or set enableLogs: false.',\n );\n }\n }\n }\n\n return cloudConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmMA,SAAgB,oBACd,QACe;CACf,MAAM,EACJ,QACA,OAAO,iBACP,SACA,aACA,SACA,aAAa,OACb,WAAW,OACX,YAAY,aACZ,YAAY,MACZ,wBACE;CAGJ,IAAI,CAAC,YAAY,CAAC,QAChB,MAAM,IAAI,MACR,iIAEF;CAGF,MAAM,aAA4B;EAChC;EACA;EACA;CACF;CAGA,IAAI,UAAU;EACZ,MAAM,gBAAgB,UAAU,UAAU,GAAG;EAG7C,IAAI,YAAY;GACd,MAAM,eAAe,UAAU,UAAU,GAAG,UAAU;GAEtD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;GAGjD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;GAKjD,MAAM,gBAAgB;IACpB,gBAAgB;IAChB,cAAc,0BAA0B,gBAAgB;IACxD,UAAU,mBAAmB,YAAY;GAC3C,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;GAEX,IAAI,CAAC,QAAQ,IAAI,0BACf,QAAQ,IAAI,2BAA2B;EAE3C;EAEA,OAAO;GACL,GAAG;GACH,UAAU;EAEZ;CACF;CAIA,MAAM,eAAe,gBAAgB;CACrC,MAAM,cAAc,cAAc;CAElC,MAAM,cAA6B;EACjC,GAAG;EACH,UAAU;EACV,SAAS;CACX;CAGA,IAAI,YAAY;EAGd,MAAM,eAAe,WACjB,UAAU,UAAU,GAAG,UAAU,YACjC,gBAAgB,KAAK;EAGzB,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;EAGjD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;EAIjD,IAAI,CAAC,YAAY,UAAU,CAAC,QAAQ,IAAI,iCACtC,QAAQ,IAAI,kCAAkC,cAAc;EAI9D,MAAM,gBAAgB;GACpB,gBAAgB;GAChB,cAAc,0BAA0B,gBAAgB;GACxD,UAAU,mBAAmB,YAAY;EAC3C,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;EAEX,IAAI,CAAC,QAAQ,IAAI,0BACf,QAAQ,IAAI,2BAA2B;EAGzC,IAAI,qBAEF,YAAY,sBAAsB;OAGlC,IAAI;GACF,MAAM,cAAA,GAAA,YAAA,cAAA,CACJ,OAAO,eAAe,WAAW,aAAA,QAAA,KAAA,CAAA,CAAA,cAAA,UAAA,CAAA,CAAA,IACnC;GACA,MAAM,EAAE,4BAA4B,WAClC,yBACF;GACA,MAAM,EAAE,oBAAoB,WAC1B,wCACF;GAEA,YAAY,sBAAsB,CAChC,IAAI,wBACF,IAAI,gBAAgB;IAClB,KAAK,GAAG,aAAa;IACrB,SAAS,EACP,cAAc,OAChB;GACF,CAAC,CACH,CACF;EACF,QAAQ;GACN,MAAM,IAAI,MACR,gIAEF;EACF;CAEJ;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"datadog.cjs","names":[],"sources":["../src/datadog.ts"],"sourcesContent":["/**\n * Datadog preset for autotel\n *\n * Provides a simplified configuration helper for Datadog integration\n * with best practices built-in.\n *\n * @example Direct cloud ingestion (serverless, edge)\n * ```typescript\n * import { init } from 'autotel';\n * import { createDatadogConfig } from 'autotel-backends/datadog';\n *\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-lambda',\n * enableLogs: true,\n * }));\n * ```\n *\n * @example Local Datadog Agent (long-running services, Kubernetes)\n * ```typescript\n * import { init } from 'autotel';\n * import { createDatadogConfig } from 'autotel-backends/datadog';\n *\n * init(createDatadogConfig({\n * service: 'my-api',\n * useAgent: true, // No API key needed - Agent handles it\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\nimport type { LogRecordProcessor } from '@opentelemetry/sdk-logs';\n\n// `__filename` exists under CJS (including esbuild's CJS output wrapper) but\n// not pure ESM. `typeof` is safe against an undeclared identifier and lets\n// the conditional pick the working URL in either format.\ndeclare const __filename: string | undefined;\n\n/**\n * Datadog site regions\n */\nexport type DatadogSite =\n | 'datadoghq.com' // US1 (default)\n | 'datadoghq.eu' // EU\n | 'us3.datadoghq.com' // US3\n | 'us5.datadoghq.com' // US5\n | 'ap1.datadoghq.com' // AP1\n | 'ddog-gov.com'; // US1-FED\n\n/**\n * Configuration options for Datadog preset\n */\nexport interface DatadogPresetConfig {\n /**\n * Datadog API key (required for direct cloud ingestion).\n * Not needed if using local Datadog Agent (useAgent: true).\n *\n * Get your API key from:\n * https://app.datadoghq.com/organization-settings/api-keys\n */\n apiKey?: string;\n\n /**\n * Datadog site/region.\n * Determines which Datadog intake endpoint to use.\n *\n * @default 'datadoghq.com' (US1)\n */\n site?: DatadogSite;\n\n /**\n * Service name (required).\n * Appears in Datadog APM, Service Catalog, and all telemetry.\n */\n service: string;\n\n /**\n * Deployment environment (e.g., 'production', 'staging', 'development').\n * Used for environment filtering in Datadog.\n *\n * @default process.env.DD_ENV || process.env.NODE_ENV || 'development'\n */\n environment?: string;\n\n /**\n * Service version for deployment tracking.\n * Enables Deployment Tracking in Datadog APM.\n *\n * @default process.env.DD_VERSION || auto-detected from package.json\n */\n version?: string;\n\n /**\n * Enable log export to Datadog via OTLP.\n *\n * When enabled, this:\n * 1. Sets up OTel Logs SDK with OTLP exporter (for direct OTel logs API usage)\n * 2. Auto-configures OTEL_EXPORTER_OTLP_LOGS_* env vars for pino-opentelemetry-transport\n *\n * For Pino users: Just add pino-opentelemetry-transport to your logger config:\n * ```typescript\n * const logger = pino({\n * transport: {\n * targets: [\n * { target: 'pino-pretty' },\n * { target: 'pino-opentelemetry-transport' }, // Auto-configured!\n * ],\n * },\n * });\n * ```\n *\n * @default false\n */\n enableLogs?: boolean;\n\n /**\n * Use local Datadog Agent instead of direct cloud ingestion.\n *\n * Benefits:\n * - Lower egress costs (Agent aggregates locally)\n * - Advanced features: trace-log correlation, multi-line logs, data scrubbing\n * - 500+ integrations for enrichment\n * - Infrastructure metrics collection\n *\n * Requires: Datadog Agent 7.35+ with OTLP enabled\n *\n * @default false\n */\n useAgent?: boolean;\n\n /**\n * Datadog Agent hostname (when useAgent: true).\n *\n * @default 'localhost'\n */\n agentHost?: string;\n\n /**\n * Datadog Agent OTLP port (when useAgent: true).\n *\n * @default 4318 (OTLP HTTP)\n */\n agentPort?: number;\n\n /**\n * Custom log record processors (advanced).\n * Overrides the default log processor if enableLogs is true.\n */\n logRecordProcessors?: LogRecordProcessor[];\n}\n\n/**\n * Create an autotel configuration optimized for Datadog.\n *\n * This preset handles:\n * - Proper OTLP endpoint configuration (Agent vs direct ingestion)\n * - Direct: https://otlp.{site} → SDK appends /v1/traces, /v1/metrics, /v1/logs\n * - Agent: http://localhost:4318 (default)\n * - Datadog API key authentication headers (direct ingestion only)\n * - Unified service tagging (service, env, version)\n * - Resource attribute best practices\n * - Optional log export configuration\n *\n * @param config - Datadog-specific configuration options\n * @returns AutotelConfig ready to pass to init()\n *\n * @example Simple cloud ingestion\n * ```typescript\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With logs and custom environment\n * ```typescript\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-app',\n * environment: 'production',\n * version: '2.1.0',\n * enableLogs: true,\n * }));\n * ```\n *\n * @example Using local Datadog Agent\n * ```typescript\n * init(createDatadogConfig({\n * service: 'my-api',\n * useAgent: true,\n * agentHost: 'datadog-agent.default.svc.cluster.local', // Kubernetes\n * }));\n * ```\n */\nexport function createDatadogConfig(\n config: DatadogPresetConfig,\n): AutotelConfig {\n const {\n apiKey,\n site = 'datadoghq.com',\n service,\n environment,\n version,\n enableLogs = false,\n useAgent = false,\n agentHost = 'localhost',\n agentPort = 4318,\n logRecordProcessors,\n } = config;\n\n // Validation: API key required for direct ingestion\n if (!useAgent && !apiKey) {\n throw new Error(\n 'Datadog API key is required for direct cloud ingestion. ' +\n 'Either provide apiKey or set useAgent: true to use local Datadog Agent.',\n );\n }\n\n const baseConfig: AutotelConfig = {\n service,\n environment,\n version,\n };\n\n // Local Datadog Agent configuration\n if (useAgent) {\n const agentEndpoint = `http://${agentHost}:${agentPort}`;\n\n // Auto-configure env vars for pino-opentelemetry-transport in agent mode\n if (enableLogs) {\n const logsEndpoint = `http://${agentHost}:${agentPort}/v1/logs`;\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;\n }\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = 'http/protobuf';\n }\n\n // No API key header needed for agent mode - Agent handles authentication\n\n const resourceAttrs = [\n `service.name=${service}`,\n environment ? `deployment.environment=${environment}` : null,\n version ? `service.version=${version}` : null,\n ]\n .filter(Boolean)\n .join(',');\n\n if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {\n process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;\n }\n }\n\n return {\n ...baseConfig,\n endpoint: agentEndpoint,\n // No API key or headers needed - Agent handles authentication\n };\n }\n\n // Direct cloud ingestion configuration\n // Datadog OTLP endpoint: base URL without path (SDK appends /v1/traces, /v1/metrics, /v1/logs)\n const otlpEndpoint = `https://otlp.${site}`;\n const authHeaders = `dd-api-key=${apiKey}`;\n\n const cloudConfig: AutotelConfig = {\n ...baseConfig,\n endpoint: otlpEndpoint,\n headers: authHeaders,\n };\n\n // Add log export if enabled\n if (enableLogs) {\n // Auto-configure env vars for pino-opentelemetry-transport and other OTel log transports\n // These are read by pino-opentelemetry-transport, otlp-logger, and similar libraries\n const logsEndpoint = useAgent\n ? `http://${agentHost}:${agentPort}/v1/logs`\n : `https://otlp.${site}/v1/logs`;\n\n // Only set if not already configured (allow user override)\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;\n }\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = 'http/protobuf';\n }\n\n // Only set API key header for direct cloud ingestion (not agent mode)\n if (!useAgent && apiKey && !process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS = `dd-api-key=${apiKey}`;\n }\n\n // Set resource attributes for service identification\n const resourceAttrs = [\n `service.name=${service}`,\n environment ? `deployment.environment=${environment}` : null,\n version ? `service.version=${version}` : null,\n ]\n .filter(Boolean)\n .join(',');\n\n if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {\n process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;\n }\n\n if (logRecordProcessors) {\n // Use custom processors if provided\n cloudConfig.logRecordProcessors = logRecordProcessors;\n } else {\n // Create default OTLP log exporter\n try {\n const pkgRequire = createRequire(\n typeof __filename === 'string' ? __filename : import.meta.url,\n );\n const { BatchLogRecordProcessor } = pkgRequire(\n '@opentelemetry/sdk-logs',\n );\n const { OTLPLogExporter } = pkgRequire(\n '@opentelemetry/exporter-logs-otlp-http',\n );\n\n cloudConfig.logRecordProcessors = [\n new BatchLogRecordProcessor({\n exporter: new OTLPLogExporter({\n url: `${otlpEndpoint}/v1/logs`,\n headers: {\n 'dd-api-key': apiKey,\n },\n }),\n }),\n ];\n } catch {\n throw new Error(\n 'Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. ' +\n 'Install them or set enableLogs: false.',\n );\n }\n }\n }\n\n return cloudConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmMA,SAAgB,oBACd,QACe;CACf,MAAM,EACJ,QACA,OAAO,iBACP,SACA,aACA,SACA,aAAa,OACb,WAAW,OACX,YAAY,aACZ,YAAY,MACZ,wBACE;CAGJ,IAAI,CAAC,YAAY,CAAC,QAChB,MAAM,IAAI,MACR,iIAEF;CAGF,MAAM,aAA4B;EAChC;EACA;EACA;CACF;CAGA,IAAI,UAAU;EACZ,MAAM,gBAAgB,UAAU,UAAU,GAAG;EAG7C,IAAI,YAAY;GACd,MAAM,eAAe,UAAU,UAAU,GAAG,UAAU;GAEtD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;GAGjD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;GAKjD,MAAM,gBAAgB;IACpB,gBAAgB;IAChB,cAAc,0BAA0B,gBAAgB;IACxD,UAAU,mBAAmB,YAAY;GAC3C,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;GAEX,IAAI,CAAC,QAAQ,IAAI,0BACf,QAAQ,IAAI,2BAA2B;EAE3C;EAEA,OAAO;GACL,GAAG;GACH,UAAU;EAEZ;CACF;CAIA,MAAM,eAAe,gBAAgB;CACrC,MAAM,cAAc,cAAc;CAElC,MAAM,cAA6B;EACjC,GAAG;EACH,UAAU;EACV,SAAS;CACX;CAGA,IAAI,YAAY;EAGd,MAAM,eAAe,WACjB,UAAU,UAAU,GAAG,UAAU,YACjC,gBAAgB,KAAK;EAGzB,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;EAGjD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;EAIjD,IAAI,CAAC,YAAY,UAAU,CAAC,QAAQ,IAAI,iCACtC,QAAQ,IAAI,kCAAkC,cAAc;EAI9D,MAAM,gBAAgB;GACpB,gBAAgB;GAChB,cAAc,0BAA0B,gBAAgB;GACxD,UAAU,mBAAmB,YAAY;EAC3C,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;EAEX,IAAI,CAAC,QAAQ,IAAI,0BACf,QAAQ,IAAI,2BAA2B;EAGzC,IAAI,qBAEF,YAAY,sBAAsB;OAGlC,IAAI;GACF,MAAM,cAAA,GAAA,YAAA,cAAA,CACJ,OAAO,eAAe,WAAW,aAAA,QAAA,KAAA,CAAA,CAAA,cAAA,UAAA,CAAA,CAAA,IACnC;GACA,MAAM,EAAE,4BAA4B,WAClC,yBACF;GACA,MAAM,EAAE,oBAAoB,WAC1B,wCACF;GAEA,YAAY,sBAAsB,CAChC,IAAI,wBAAwB,EAC1B,UAAU,IAAI,gBAAgB;IAC5B,KAAK,GAAG,aAAa;IACrB,SAAS,EACP,cAAc,OAChB;GACF,CAAC,EACH,CAAC,CACH;EACF,QAAQ;GACN,MAAM,IAAI,MACR,gIAEF;EACF;CAEJ;CAEA,OAAO;AACT"}
@@ -1,6 +1,5 @@
1
1
  import { AutotelConfig } from "autotel";
2
2
  import { LogRecordProcessor } from "@opentelemetry/sdk-logs";
3
-
4
3
  //#region src/datadog.d.ts
5
4
  /**
6
5
  * Datadog site regions
@@ -1 +1 @@
1
- {"version":3,"file":"datadog.d.cts","names":[],"sources":["../src/datadog.ts"],"mappings":";;;;;;;KA0CY,WAAA;AA2JI;;;AAAA,UAhJC,mBAAA;;;;;;;;EAQf,MAAA;;;;;;;EAQA,IAAA,GAAO,WAAA;;;;;EAMP,OAAA;;;;;;;EAQA,WAAA;;;;;;;EAQA,OAAA;;;;;;;;;;;;;;;;;;;;;;EAuBA,UAAA;;;;;;;;;;;;;;EAeA,QAAA;;;;;;EAOA,SAAA;;;;;;EAOA,SAAA;;;;;EAMA,mBAAA,GAAsB,kBAAkB;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8C1B,mBAAA,CACd,MAAA,EAAQ,mBAAA,GACP,aAAa"}
1
+ {"version":3,"file":"datadog.d.cts","names":[],"sources":["../src/datadog.ts"],"mappings":";;;;;;KA0CY;;;;UAWK;;;;;;;;EAQf;;;;;;;EAQA,OAAO;;;;;EAMP;;;;;;;EAQA;;;;;;;EAQA;;;;;;;;;;;;;;;;;;;;;;EAuBA;;;;;;;;;;;;;;EAeA;;;;;;EAOA;;;;;;EAOA;;;;;EAMA,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8CR,oBACd,QAAQ,sBACP"}
package/dist/datadog.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { AutotelConfig } from "autotel";
2
2
  import { LogRecordProcessor } from "@opentelemetry/sdk-logs";
3
-
4
3
  //#region src/datadog.d.ts
5
4
  /**
6
5
  * Datadog site regions
@@ -1 +1 @@
1
- {"version":3,"file":"datadog.d.ts","names":[],"sources":["../src/datadog.ts"],"mappings":";;;;;;;KA0CY,WAAA;AA2JI;;;AAAA,UAhJC,mBAAA;;;;;;;;EAQf,MAAA;;;;;;;EAQA,IAAA,GAAO,WAAA;;;;;EAMP,OAAA;;;;;;;EAQA,WAAA;;;;;;;EAQA,OAAA;;;;;;;;;;;;;;;;;;;;;;EAuBA,UAAA;;;;;;;;;;;;;;EAeA,QAAA;;;;;;EAOA,SAAA;;;;;;EAOA,SAAA;;;;;EAMA,mBAAA,GAAsB,kBAAkB;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8C1B,mBAAA,CACd,MAAA,EAAQ,mBAAA,GACP,aAAa"}
1
+ {"version":3,"file":"datadog.d.ts","names":[],"sources":["../src/datadog.ts"],"mappings":";;;;;;KA0CY;;;;UAWK;;;;;;;;EAQf;;;;;;;EAQA,OAAO;;;;;EAMP;;;;;;;EAQA;;;;;;;EAQA;;;;;;;;;;;;;;;;;;;;;;EAuBA;;;;;;;;;;;;;;EAeA;;;;;;EAOA;;;;;;EAOA;;;;;EAMA,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8CR,oBACd,QAAQ,sBACP"}
package/dist/datadog.js CHANGED
@@ -121,10 +121,10 @@ function createDatadogConfig(config) {
121
121
  const pkgRequire = createRequire(typeof __filename === "string" ? __filename : import.meta.url);
122
122
  const { BatchLogRecordProcessor } = pkgRequire("@opentelemetry/sdk-logs");
123
123
  const { OTLPLogExporter } = pkgRequire("@opentelemetry/exporter-logs-otlp-http");
124
- cloudConfig.logRecordProcessors = [new BatchLogRecordProcessor(new OTLPLogExporter({
124
+ cloudConfig.logRecordProcessors = [new BatchLogRecordProcessor({ exporter: new OTLPLogExporter({
125
125
  url: `${otlpEndpoint}/v1/logs`,
126
126
  headers: { "dd-api-key": apiKey }
127
- }))];
127
+ }) })];
128
128
  } catch {
129
129
  throw new Error("Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. Install them or set enableLogs: false.");
130
130
  }
@@ -1 +1 @@
1
- {"version":3,"file":"datadog.js","names":[],"sources":["../src/datadog.ts"],"sourcesContent":["/**\n * Datadog preset for autotel\n *\n * Provides a simplified configuration helper for Datadog integration\n * with best practices built-in.\n *\n * @example Direct cloud ingestion (serverless, edge)\n * ```typescript\n * import { init } from 'autotel';\n * import { createDatadogConfig } from 'autotel-backends/datadog';\n *\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-lambda',\n * enableLogs: true,\n * }));\n * ```\n *\n * @example Local Datadog Agent (long-running services, Kubernetes)\n * ```typescript\n * import { init } from 'autotel';\n * import { createDatadogConfig } from 'autotel-backends/datadog';\n *\n * init(createDatadogConfig({\n * service: 'my-api',\n * useAgent: true, // No API key needed - Agent handles it\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\nimport type { LogRecordProcessor } from '@opentelemetry/sdk-logs';\n\n// `__filename` exists under CJS (including esbuild's CJS output wrapper) but\n// not pure ESM. `typeof` is safe against an undeclared identifier and lets\n// the conditional pick the working URL in either format.\ndeclare const __filename: string | undefined;\n\n/**\n * Datadog site regions\n */\nexport type DatadogSite =\n | 'datadoghq.com' // US1 (default)\n | 'datadoghq.eu' // EU\n | 'us3.datadoghq.com' // US3\n | 'us5.datadoghq.com' // US5\n | 'ap1.datadoghq.com' // AP1\n | 'ddog-gov.com'; // US1-FED\n\n/**\n * Configuration options for Datadog preset\n */\nexport interface DatadogPresetConfig {\n /**\n * Datadog API key (required for direct cloud ingestion).\n * Not needed if using local Datadog Agent (useAgent: true).\n *\n * Get your API key from:\n * https://app.datadoghq.com/organization-settings/api-keys\n */\n apiKey?: string;\n\n /**\n * Datadog site/region.\n * Determines which Datadog intake endpoint to use.\n *\n * @default 'datadoghq.com' (US1)\n */\n site?: DatadogSite;\n\n /**\n * Service name (required).\n * Appears in Datadog APM, Service Catalog, and all telemetry.\n */\n service: string;\n\n /**\n * Deployment environment (e.g., 'production', 'staging', 'development').\n * Used for environment filtering in Datadog.\n *\n * @default process.env.DD_ENV || process.env.NODE_ENV || 'development'\n */\n environment?: string;\n\n /**\n * Service version for deployment tracking.\n * Enables Deployment Tracking in Datadog APM.\n *\n * @default process.env.DD_VERSION || auto-detected from package.json\n */\n version?: string;\n\n /**\n * Enable log export to Datadog via OTLP.\n *\n * When enabled, this:\n * 1. Sets up OTel Logs SDK with OTLP exporter (for direct OTel logs API usage)\n * 2. Auto-configures OTEL_EXPORTER_OTLP_LOGS_* env vars for pino-opentelemetry-transport\n *\n * For Pino users: Just add pino-opentelemetry-transport to your logger config:\n * ```typescript\n * const logger = pino({\n * transport: {\n * targets: [\n * { target: 'pino-pretty' },\n * { target: 'pino-opentelemetry-transport' }, // Auto-configured!\n * ],\n * },\n * });\n * ```\n *\n * @default false\n */\n enableLogs?: boolean;\n\n /**\n * Use local Datadog Agent instead of direct cloud ingestion.\n *\n * Benefits:\n * - Lower egress costs (Agent aggregates locally)\n * - Advanced features: trace-log correlation, multi-line logs, data scrubbing\n * - 500+ integrations for enrichment\n * - Infrastructure metrics collection\n *\n * Requires: Datadog Agent 7.35+ with OTLP enabled\n *\n * @default false\n */\n useAgent?: boolean;\n\n /**\n * Datadog Agent hostname (when useAgent: true).\n *\n * @default 'localhost'\n */\n agentHost?: string;\n\n /**\n * Datadog Agent OTLP port (when useAgent: true).\n *\n * @default 4318 (OTLP HTTP)\n */\n agentPort?: number;\n\n /**\n * Custom log record processors (advanced).\n * Overrides the default log processor if enableLogs is true.\n */\n logRecordProcessors?: LogRecordProcessor[];\n}\n\n/**\n * Create an autotel configuration optimized for Datadog.\n *\n * This preset handles:\n * - Proper OTLP endpoint configuration (Agent vs direct ingestion)\n * - Direct: https://otlp.{site} → SDK appends /v1/traces, /v1/metrics, /v1/logs\n * - Agent: http://localhost:4318 (default)\n * - Datadog API key authentication headers (direct ingestion only)\n * - Unified service tagging (service, env, version)\n * - Resource attribute best practices\n * - Optional log export configuration\n *\n * @param config - Datadog-specific configuration options\n * @returns AutotelConfig ready to pass to init()\n *\n * @example Simple cloud ingestion\n * ```typescript\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With logs and custom environment\n * ```typescript\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-app',\n * environment: 'production',\n * version: '2.1.0',\n * enableLogs: true,\n * }));\n * ```\n *\n * @example Using local Datadog Agent\n * ```typescript\n * init(createDatadogConfig({\n * service: 'my-api',\n * useAgent: true,\n * agentHost: 'datadog-agent.default.svc.cluster.local', // Kubernetes\n * }));\n * ```\n */\nexport function createDatadogConfig(\n config: DatadogPresetConfig,\n): AutotelConfig {\n const {\n apiKey,\n site = 'datadoghq.com',\n service,\n environment,\n version,\n enableLogs = false,\n useAgent = false,\n agentHost = 'localhost',\n agentPort = 4318,\n logRecordProcessors,\n } = config;\n\n // Validation: API key required for direct ingestion\n if (!useAgent && !apiKey) {\n throw new Error(\n 'Datadog API key is required for direct cloud ingestion. ' +\n 'Either provide apiKey or set useAgent: true to use local Datadog Agent.',\n );\n }\n\n const baseConfig: AutotelConfig = {\n service,\n environment,\n version,\n };\n\n // Local Datadog Agent configuration\n if (useAgent) {\n const agentEndpoint = `http://${agentHost}:${agentPort}`;\n\n // Auto-configure env vars for pino-opentelemetry-transport in agent mode\n if (enableLogs) {\n const logsEndpoint = `http://${agentHost}:${agentPort}/v1/logs`;\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;\n }\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = 'http/protobuf';\n }\n\n // No API key header needed for agent mode - Agent handles authentication\n\n const resourceAttrs = [\n `service.name=${service}`,\n environment ? `deployment.environment=${environment}` : null,\n version ? `service.version=${version}` : null,\n ]\n .filter(Boolean)\n .join(',');\n\n if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {\n process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;\n }\n }\n\n return {\n ...baseConfig,\n endpoint: agentEndpoint,\n // No API key or headers needed - Agent handles authentication\n };\n }\n\n // Direct cloud ingestion configuration\n // Datadog OTLP endpoint: base URL without path (SDK appends /v1/traces, /v1/metrics, /v1/logs)\n const otlpEndpoint = `https://otlp.${site}`;\n const authHeaders = `dd-api-key=${apiKey}`;\n\n const cloudConfig: AutotelConfig = {\n ...baseConfig,\n endpoint: otlpEndpoint,\n headers: authHeaders,\n };\n\n // Add log export if enabled\n if (enableLogs) {\n // Auto-configure env vars for pino-opentelemetry-transport and other OTel log transports\n // These are read by pino-opentelemetry-transport, otlp-logger, and similar libraries\n const logsEndpoint = useAgent\n ? `http://${agentHost}:${agentPort}/v1/logs`\n : `https://otlp.${site}/v1/logs`;\n\n // Only set if not already configured (allow user override)\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;\n }\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = 'http/protobuf';\n }\n\n // Only set API key header for direct cloud ingestion (not agent mode)\n if (!useAgent && apiKey && !process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS = `dd-api-key=${apiKey}`;\n }\n\n // Set resource attributes for service identification\n const resourceAttrs = [\n `service.name=${service}`,\n environment ? `deployment.environment=${environment}` : null,\n version ? `service.version=${version}` : null,\n ]\n .filter(Boolean)\n .join(',');\n\n if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {\n process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;\n }\n\n if (logRecordProcessors) {\n // Use custom processors if provided\n cloudConfig.logRecordProcessors = logRecordProcessors;\n } else {\n // Create default OTLP log exporter\n try {\n const pkgRequire = createRequire(\n typeof __filename === 'string' ? __filename : import.meta.url,\n );\n const { BatchLogRecordProcessor } = pkgRequire(\n '@opentelemetry/sdk-logs',\n );\n const { OTLPLogExporter } = pkgRequire(\n '@opentelemetry/exporter-logs-otlp-http',\n );\n\n cloudConfig.logRecordProcessors = [\n new BatchLogRecordProcessor(\n new OTLPLogExporter({\n url: `${otlpEndpoint}/v1/logs`,\n headers: {\n 'dd-api-key': apiKey,\n },\n }),\n ),\n ];\n } catch {\n throw new Error(\n 'Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. ' +\n 'Install them or set enableLogs: false.',\n );\n }\n }\n }\n\n return cloudConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmMA,SAAgB,oBACd,QACe;CACf,MAAM,EACJ,QACA,OAAO,iBACP,SACA,aACA,SACA,aAAa,OACb,WAAW,OACX,YAAY,aACZ,YAAY,MACZ,wBACE;CAGJ,IAAI,CAAC,YAAY,CAAC,QAChB,MAAM,IAAI,MACR,iIAEF;CAGF,MAAM,aAA4B;EAChC;EACA;EACA;CACF;CAGA,IAAI,UAAU;EACZ,MAAM,gBAAgB,UAAU,UAAU,GAAG;EAG7C,IAAI,YAAY;GACd,MAAM,eAAe,UAAU,UAAU,GAAG,UAAU;GAEtD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;GAGjD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;GAKjD,MAAM,gBAAgB;IACpB,gBAAgB;IAChB,cAAc,0BAA0B,gBAAgB;IACxD,UAAU,mBAAmB,YAAY;GAC3C,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;GAEX,IAAI,CAAC,QAAQ,IAAI,0BACf,QAAQ,IAAI,2BAA2B;EAE3C;EAEA,OAAO;GACL,GAAG;GACH,UAAU;EAEZ;CACF;CAIA,MAAM,eAAe,gBAAgB;CACrC,MAAM,cAAc,cAAc;CAElC,MAAM,cAA6B;EACjC,GAAG;EACH,UAAU;EACV,SAAS;CACX;CAGA,IAAI,YAAY;EAGd,MAAM,eAAe,WACjB,UAAU,UAAU,GAAG,UAAU,YACjC,gBAAgB,KAAK;EAGzB,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;EAGjD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;EAIjD,IAAI,CAAC,YAAY,UAAU,CAAC,QAAQ,IAAI,iCACtC,QAAQ,IAAI,kCAAkC,cAAc;EAI9D,MAAM,gBAAgB;GACpB,gBAAgB;GAChB,cAAc,0BAA0B,gBAAgB;GACxD,UAAU,mBAAmB,YAAY;EAC3C,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;EAEX,IAAI,CAAC,QAAQ,IAAI,0BACf,QAAQ,IAAI,2BAA2B;EAGzC,IAAI,qBAEF,YAAY,sBAAsB;OAGlC,IAAI;GACF,MAAM,aAAa,cACjB,OAAO,eAAe,WAAW,aAAa,OAAO,KAAK,GAC5D;GACA,MAAM,EAAE,4BAA4B,WAClC,yBACF;GACA,MAAM,EAAE,oBAAoB,WAC1B,wCACF;GAEA,YAAY,sBAAsB,CAChC,IAAI,wBACF,IAAI,gBAAgB;IAClB,KAAK,GAAG,aAAa;IACrB,SAAS,EACP,cAAc,OAChB;GACF,CAAC,CACH,CACF;EACF,QAAQ;GACN,MAAM,IAAI,MACR,gIAEF;EACF;CAEJ;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"datadog.js","names":[],"sources":["../src/datadog.ts"],"sourcesContent":["/**\n * Datadog preset for autotel\n *\n * Provides a simplified configuration helper for Datadog integration\n * with best practices built-in.\n *\n * @example Direct cloud ingestion (serverless, edge)\n * ```typescript\n * import { init } from 'autotel';\n * import { createDatadogConfig } from 'autotel-backends/datadog';\n *\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-lambda',\n * enableLogs: true,\n * }));\n * ```\n *\n * @example Local Datadog Agent (long-running services, Kubernetes)\n * ```typescript\n * import { init } from 'autotel';\n * import { createDatadogConfig } from 'autotel-backends/datadog';\n *\n * init(createDatadogConfig({\n * service: 'my-api',\n * useAgent: true, // No API key needed - Agent handles it\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\nimport type { LogRecordProcessor } from '@opentelemetry/sdk-logs';\n\n// `__filename` exists under CJS (including esbuild's CJS output wrapper) but\n// not pure ESM. `typeof` is safe against an undeclared identifier and lets\n// the conditional pick the working URL in either format.\ndeclare const __filename: string | undefined;\n\n/**\n * Datadog site regions\n */\nexport type DatadogSite =\n | 'datadoghq.com' // US1 (default)\n | 'datadoghq.eu' // EU\n | 'us3.datadoghq.com' // US3\n | 'us5.datadoghq.com' // US5\n | 'ap1.datadoghq.com' // AP1\n | 'ddog-gov.com'; // US1-FED\n\n/**\n * Configuration options for Datadog preset\n */\nexport interface DatadogPresetConfig {\n /**\n * Datadog API key (required for direct cloud ingestion).\n * Not needed if using local Datadog Agent (useAgent: true).\n *\n * Get your API key from:\n * https://app.datadoghq.com/organization-settings/api-keys\n */\n apiKey?: string;\n\n /**\n * Datadog site/region.\n * Determines which Datadog intake endpoint to use.\n *\n * @default 'datadoghq.com' (US1)\n */\n site?: DatadogSite;\n\n /**\n * Service name (required).\n * Appears in Datadog APM, Service Catalog, and all telemetry.\n */\n service: string;\n\n /**\n * Deployment environment (e.g., 'production', 'staging', 'development').\n * Used for environment filtering in Datadog.\n *\n * @default process.env.DD_ENV || process.env.NODE_ENV || 'development'\n */\n environment?: string;\n\n /**\n * Service version for deployment tracking.\n * Enables Deployment Tracking in Datadog APM.\n *\n * @default process.env.DD_VERSION || auto-detected from package.json\n */\n version?: string;\n\n /**\n * Enable log export to Datadog via OTLP.\n *\n * When enabled, this:\n * 1. Sets up OTel Logs SDK with OTLP exporter (for direct OTel logs API usage)\n * 2. Auto-configures OTEL_EXPORTER_OTLP_LOGS_* env vars for pino-opentelemetry-transport\n *\n * For Pino users: Just add pino-opentelemetry-transport to your logger config:\n * ```typescript\n * const logger = pino({\n * transport: {\n * targets: [\n * { target: 'pino-pretty' },\n * { target: 'pino-opentelemetry-transport' }, // Auto-configured!\n * ],\n * },\n * });\n * ```\n *\n * @default false\n */\n enableLogs?: boolean;\n\n /**\n * Use local Datadog Agent instead of direct cloud ingestion.\n *\n * Benefits:\n * - Lower egress costs (Agent aggregates locally)\n * - Advanced features: trace-log correlation, multi-line logs, data scrubbing\n * - 500+ integrations for enrichment\n * - Infrastructure metrics collection\n *\n * Requires: Datadog Agent 7.35+ with OTLP enabled\n *\n * @default false\n */\n useAgent?: boolean;\n\n /**\n * Datadog Agent hostname (when useAgent: true).\n *\n * @default 'localhost'\n */\n agentHost?: string;\n\n /**\n * Datadog Agent OTLP port (when useAgent: true).\n *\n * @default 4318 (OTLP HTTP)\n */\n agentPort?: number;\n\n /**\n * Custom log record processors (advanced).\n * Overrides the default log processor if enableLogs is true.\n */\n logRecordProcessors?: LogRecordProcessor[];\n}\n\n/**\n * Create an autotel configuration optimized for Datadog.\n *\n * This preset handles:\n * - Proper OTLP endpoint configuration (Agent vs direct ingestion)\n * - Direct: https://otlp.{site} → SDK appends /v1/traces, /v1/metrics, /v1/logs\n * - Agent: http://localhost:4318 (default)\n * - Datadog API key authentication headers (direct ingestion only)\n * - Unified service tagging (service, env, version)\n * - Resource attribute best practices\n * - Optional log export configuration\n *\n * @param config - Datadog-specific configuration options\n * @returns AutotelConfig ready to pass to init()\n *\n * @example Simple cloud ingestion\n * ```typescript\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With logs and custom environment\n * ```typescript\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-app',\n * environment: 'production',\n * version: '2.1.0',\n * enableLogs: true,\n * }));\n * ```\n *\n * @example Using local Datadog Agent\n * ```typescript\n * init(createDatadogConfig({\n * service: 'my-api',\n * useAgent: true,\n * agentHost: 'datadog-agent.default.svc.cluster.local', // Kubernetes\n * }));\n * ```\n */\nexport function createDatadogConfig(\n config: DatadogPresetConfig,\n): AutotelConfig {\n const {\n apiKey,\n site = 'datadoghq.com',\n service,\n environment,\n version,\n enableLogs = false,\n useAgent = false,\n agentHost = 'localhost',\n agentPort = 4318,\n logRecordProcessors,\n } = config;\n\n // Validation: API key required for direct ingestion\n if (!useAgent && !apiKey) {\n throw new Error(\n 'Datadog API key is required for direct cloud ingestion. ' +\n 'Either provide apiKey or set useAgent: true to use local Datadog Agent.',\n );\n }\n\n const baseConfig: AutotelConfig = {\n service,\n environment,\n version,\n };\n\n // Local Datadog Agent configuration\n if (useAgent) {\n const agentEndpoint = `http://${agentHost}:${agentPort}`;\n\n // Auto-configure env vars for pino-opentelemetry-transport in agent mode\n if (enableLogs) {\n const logsEndpoint = `http://${agentHost}:${agentPort}/v1/logs`;\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;\n }\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = 'http/protobuf';\n }\n\n // No API key header needed for agent mode - Agent handles authentication\n\n const resourceAttrs = [\n `service.name=${service}`,\n environment ? `deployment.environment=${environment}` : null,\n version ? `service.version=${version}` : null,\n ]\n .filter(Boolean)\n .join(',');\n\n if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {\n process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;\n }\n }\n\n return {\n ...baseConfig,\n endpoint: agentEndpoint,\n // No API key or headers needed - Agent handles authentication\n };\n }\n\n // Direct cloud ingestion configuration\n // Datadog OTLP endpoint: base URL without path (SDK appends /v1/traces, /v1/metrics, /v1/logs)\n const otlpEndpoint = `https://otlp.${site}`;\n const authHeaders = `dd-api-key=${apiKey}`;\n\n const cloudConfig: AutotelConfig = {\n ...baseConfig,\n endpoint: otlpEndpoint,\n headers: authHeaders,\n };\n\n // Add log export if enabled\n if (enableLogs) {\n // Auto-configure env vars for pino-opentelemetry-transport and other OTel log transports\n // These are read by pino-opentelemetry-transport, otlp-logger, and similar libraries\n const logsEndpoint = useAgent\n ? `http://${agentHost}:${agentPort}/v1/logs`\n : `https://otlp.${site}/v1/logs`;\n\n // Only set if not already configured (allow user override)\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;\n }\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = 'http/protobuf';\n }\n\n // Only set API key header for direct cloud ingestion (not agent mode)\n if (!useAgent && apiKey && !process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS = `dd-api-key=${apiKey}`;\n }\n\n // Set resource attributes for service identification\n const resourceAttrs = [\n `service.name=${service}`,\n environment ? `deployment.environment=${environment}` : null,\n version ? `service.version=${version}` : null,\n ]\n .filter(Boolean)\n .join(',');\n\n if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {\n process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;\n }\n\n if (logRecordProcessors) {\n // Use custom processors if provided\n cloudConfig.logRecordProcessors = logRecordProcessors;\n } else {\n // Create default OTLP log exporter\n try {\n const pkgRequire = createRequire(\n typeof __filename === 'string' ? __filename : import.meta.url,\n );\n const { BatchLogRecordProcessor } = pkgRequire(\n '@opentelemetry/sdk-logs',\n );\n const { OTLPLogExporter } = pkgRequire(\n '@opentelemetry/exporter-logs-otlp-http',\n );\n\n cloudConfig.logRecordProcessors = [\n new BatchLogRecordProcessor({\n exporter: new OTLPLogExporter({\n url: `${otlpEndpoint}/v1/logs`,\n headers: {\n 'dd-api-key': apiKey,\n },\n }),\n }),\n ];\n } catch {\n throw new Error(\n 'Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. ' +\n 'Install them or set enableLogs: false.',\n );\n }\n }\n }\n\n return cloudConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmMA,SAAgB,oBACd,QACe;CACf,MAAM,EACJ,QACA,OAAO,iBACP,SACA,aACA,SACA,aAAa,OACb,WAAW,OACX,YAAY,aACZ,YAAY,MACZ,wBACE;CAGJ,IAAI,CAAC,YAAY,CAAC,QAChB,MAAM,IAAI,MACR,iIAEF;CAGF,MAAM,aAA4B;EAChC;EACA;EACA;CACF;CAGA,IAAI,UAAU;EACZ,MAAM,gBAAgB,UAAU,UAAU,GAAG;EAG7C,IAAI,YAAY;GACd,MAAM,eAAe,UAAU,UAAU,GAAG,UAAU;GAEtD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;GAGjD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;GAKjD,MAAM,gBAAgB;IACpB,gBAAgB;IAChB,cAAc,0BAA0B,gBAAgB;IACxD,UAAU,mBAAmB,YAAY;GAC3C,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;GAEX,IAAI,CAAC,QAAQ,IAAI,0BACf,QAAQ,IAAI,2BAA2B;EAE3C;EAEA,OAAO;GACL,GAAG;GACH,UAAU;EAEZ;CACF;CAIA,MAAM,eAAe,gBAAgB;CACrC,MAAM,cAAc,cAAc;CAElC,MAAM,cAA6B;EACjC,GAAG;EACH,UAAU;EACV,SAAS;CACX;CAGA,IAAI,YAAY;EAGd,MAAM,eAAe,WACjB,UAAU,UAAU,GAAG,UAAU,YACjC,gBAAgB,KAAK;EAGzB,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;EAGjD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;EAIjD,IAAI,CAAC,YAAY,UAAU,CAAC,QAAQ,IAAI,iCACtC,QAAQ,IAAI,kCAAkC,cAAc;EAI9D,MAAM,gBAAgB;GACpB,gBAAgB;GAChB,cAAc,0BAA0B,gBAAgB;GACxD,UAAU,mBAAmB,YAAY;EAC3C,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;EAEX,IAAI,CAAC,QAAQ,IAAI,0BACf,QAAQ,IAAI,2BAA2B;EAGzC,IAAI,qBAEF,YAAY,sBAAsB;OAGlC,IAAI;GACF,MAAM,aAAa,cACjB,OAAO,eAAe,WAAW,aAAa,OAAO,KAAK,GAC5D;GACA,MAAM,EAAE,4BAA4B,WAClC,yBACF;GACA,MAAM,EAAE,oBAAoB,WAC1B,wCACF;GAEA,YAAY,sBAAsB,CAChC,IAAI,wBAAwB,EAC1B,UAAU,IAAI,gBAAgB;IAC5B,KAAK,GAAG,aAAa;IACrB,SAAS,EACP,cAAc,OAChB;GACF,CAAC,EACH,CAAC,CACH;EACF,QAAQ;GACN,MAAM,IAAI,MACR,gIAEF;EACF;CAEJ;CAEA,OAAO;AACT"}
@@ -1,5 +1,4 @@
1
1
  import { AutotelConfig } from "autotel";
2
-
3
2
  //#region src/google-cloud.d.ts
4
3
  /**
5
4
  * Configuration options for Google Cloud preset
@@ -1 +1 @@
1
- {"version":3,"file":"google-cloud.d.cts","names":[],"sources":["../src/google-cloud.ts"],"mappings":";;;;;;UA+CiB,uBAAA;;;;;;;;EAQf,SAAA;;;;;EAMA,OAAA;;;;;;EAOA,WAAA;;;;;;EAOA,OAAA;;;;;;;;EASA,YAAA;;;;;;EAOA,iBAAA;;;;;;;EAQA,QAAA;AAAA;;;;;;;;;;;;;;iBAgBc,uBAAA,CACd,MAAA,EAAQ,uBAAA,GACP,aAAa"}
1
+ {"version":3,"file":"google-cloud.d.cts","names":[],"sources":["../src/google-cloud.ts"],"mappings":";;;;;UA+CiB;;;;;;;;EAQf;;;;;EAMA;;;;;;EAOA;;;;;;EAOA;;;;;;;;EASA;;;;;;EAOA;;;;;;;EAQA;;;;;;;;;;;;;;;iBAgBc,wBACd,QAAQ,0BACP"}
@@ -1,5 +1,4 @@
1
1
  import { AutotelConfig } from "autotel";
2
-
3
2
  //#region src/google-cloud.d.ts
4
3
  /**
5
4
  * Configuration options for Google Cloud preset
@@ -1 +1 @@
1
- {"version":3,"file":"google-cloud.d.ts","names":[],"sources":["../src/google-cloud.ts"],"mappings":";;;;;;UA+CiB,uBAAA;;;;;;;;EAQf,SAAA;;;;;EAMA,OAAA;;;;;;EAOA,WAAA;;;;;;EAOA,OAAA;;;;;;;;EASA,YAAA;;;;;;EAOA,iBAAA;;;;;;;EAQA,QAAA;AAAA;;;;;;;;;;;;;;iBAgBc,uBAAA,CACd,MAAA,EAAQ,uBAAA,GACP,aAAa"}
1
+ {"version":3,"file":"google-cloud.d.ts","names":[],"sources":["../src/google-cloud.ts"],"mappings":";;;;;UA+CiB;;;;;;;;EAQf;;;;;EAMA;;;;;;EAOA;;;;;;EAOA;;;;;;;;EASA;;;;;;EAOA;;;;;;;EAQA;;;;;;;;;;;;;;;iBAgBc,wBACd,QAAQ,0BACP"}
package/dist/grafana.cjs CHANGED
@@ -66,10 +66,10 @@ function createGrafanaConfig(config) {
66
66
  const pkgRequire = (0, node_module.createRequire)(typeof __filename === "string" ? __filename : require("url").pathToFileURL(__filename).href);
67
67
  const { BatchLogRecordProcessor } = pkgRequire("@opentelemetry/sdk-logs");
68
68
  const { OTLPLogExporter } = pkgRequire("@opentelemetry/exporter-logs-otlp-http");
69
- result.logRecordProcessors = [new BatchLogRecordProcessor(new OTLPLogExporter({
69
+ result.logRecordProcessors = [new BatchLogRecordProcessor({ exporter: new OTLPLogExporter({
70
70
  url: logsUrl,
71
71
  headers
72
- }))];
72
+ }) })];
73
73
  } catch {
74
74
  throw new Error("Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. Install them or set enableLogs: false.");
75
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"grafana.cjs","names":[],"sources":["../src/grafana.ts"],"sourcesContent":["/**\n * Grafana Cloud preset for autotel\n *\n * Provides a simplified configuration helper for sending traces, metrics,\n * and logs to Grafana Cloud via the OTLP gateway.\n *\n * Get your endpoint and headers from:\n * Grafana Cloud Portal → your stack → Connections → OpenTelemetry → Configure\n *\n * @example\n * ```typescript\n * import { init } from 'autotel';\n * import { createGrafanaConfig } from 'autotel-backends/grafana';\n *\n * init(createGrafanaConfig({\n * endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT!,\n * headers: process.env.OTEL_EXPORTER_OTLP_HEADERS,\n * service: 'my-app',\n * enableLogs: true,\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\nimport type { LogRecordProcessor } from '@opentelemetry/sdk-logs';\n\n// See packages/autotel/src/node-require.ts for why the __filename fallback\n// is necessary alongside import.meta.url.\ndeclare const __filename: string | undefined;\n\n/**\n * Configuration options for Grafana Cloud preset\n */\nexport interface GrafanaPresetConfig {\n /**\n * OTLP gateway endpoint (required).\n * From Grafana Cloud: Stack → Connections → OpenTelemetry → Configure.\n * Example: https://otlp-gateway-prod-gb-south-1.grafana.net/otlp\n */\n endpoint: string;\n\n /**\n * OTLP authentication headers.\n * From the same Configure tile; usually Basic auth.\n * Example: \"Authorization=Basic%20BASE64_INSTANCE_ID_AND_TOKEN\"\n * or object: { Authorization: 'Basic ...' }\n */\n headers?: string | Record<string, string>;\n\n /**\n * Service name (required).\n * Appears in Tempo, Mimir, and Loki as service_name.\n */\n service: string;\n\n /**\n * Deployment environment (e.g. 'production', 'staging').\n *\n * @default process.env.NODE_ENV || 'development'\n */\n environment?: string;\n\n /**\n * Service version for deployment tracking.\n *\n * @default process.env.OTEL_SERVICE_VERSION\n */\n version?: string;\n\n /**\n * Enable log export to Grafana Cloud (Loki) via OTLP.\n * When true, configures logRecordProcessors so OTel Logs API records are exported.\n *\n * @default true\n */\n enableLogs?: boolean;\n\n /**\n * Custom log record processors (advanced).\n * Overrides the default OTLP log processor when enableLogs is true.\n */\n logRecordProcessors?: LogRecordProcessor[];\n}\n\nfunction normalizeHeaders(\n headers: string | Record<string, string> | undefined,\n): Record<string, string> | undefined {\n if (!headers) return undefined;\n if (typeof headers === 'object') return headers;\n const out: Record<string, string> = {};\n for (const pair of headers.split(',')) {\n const [key, ...valueParts] = pair.split('=');\n if (key && valueParts.length > 0) {\n let value = valueParts.join('=').trim();\n value = value.replaceAll('%20', ' ');\n out[key.trim()] = value;\n }\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\n/**\n * Create an autotel configuration for Grafana Cloud OTLP.\n *\n * Sends traces (Tempo), metrics (Mimir), and optionally logs (Loki) to the\n * Grafana Cloud OTLP gateway. Endpoint and headers come from the stack's\n * Connections → OpenTelemetry → Configure tile.\n *\n * @param config - Grafana Cloud configuration options\n * @returns AutotelConfig ready to pass to init()\n */\nexport function createGrafanaConfig(\n config: GrafanaPresetConfig,\n): AutotelConfig {\n const {\n endpoint,\n headers: headersInput,\n service,\n environment,\n version,\n enableLogs = true,\n logRecordProcessors,\n } = config;\n\n if (!endpoint) {\n throw new Error(\n 'Grafana Cloud endpoint is required. Get it from: Grafana Cloud → your stack → Connections → OpenTelemetry → Configure',\n );\n }\n\n const headers = normalizeHeaders(headersInput);\n const base = endpoint.replace(/\\/v1\\/(traces|metrics|logs)$/, '');\n const logsUrl = `${base}${base.endsWith('/') ? '' : '/'}v1/logs`;\n\n const result: AutotelConfig = {\n service,\n environment,\n version,\n endpoint,\n headers,\n metrics: true,\n };\n\n if (enableLogs) {\n if (logRecordProcessors) {\n result.logRecordProcessors = logRecordProcessors;\n } else {\n try {\n const pkgRequire = createRequire(\n typeof __filename === 'string' ? __filename : import.meta.url,\n );\n const { BatchLogRecordProcessor } = pkgRequire(\n '@opentelemetry/sdk-logs',\n );\n const { OTLPLogExporter } = pkgRequire(\n '@opentelemetry/exporter-logs-otlp-http',\n );\n result.logRecordProcessors = [\n new BatchLogRecordProcessor(\n new OTLPLogExporter({\n url: logsUrl,\n headers,\n }),\n ),\n ];\n } catch {\n throw new Error(\n 'Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. ' +\n 'Install them or set enableLogs: false.',\n );\n }\n }\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,SAAS,iBACP,SACoC;CACpC,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,IAAI,OAAO,YAAY,UAAU,OAAO;CACxC,MAAM,MAA8B,CAAC;CACrC,KAAK,MAAM,QAAQ,QAAQ,MAAM,GAAG,GAAG;EACrC,MAAM,CAAC,KAAK,GAAG,cAAc,KAAK,MAAM,GAAG;EAC3C,IAAI,OAAO,WAAW,SAAS,GAAG;GAChC,IAAI,QAAQ,WAAW,KAAK,GAAG,CAAC,CAAC,KAAK;GACtC,QAAQ,MAAM,WAAW,OAAO,GAAG;GACnC,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;CACA,OAAO,OAAO,KAAK,GAAG,CAAC,CAAC,SAAS,IAAI,MAAM,KAAA;AAC7C;;;;;;;;;;;AAYA,SAAgB,oBACd,QACe;CACf,MAAM,EACJ,UACA,SAAS,cACT,SACA,aACA,SACA,aAAa,MACb,wBACE;CAEJ,IAAI,CAAC,UACH,MAAM,IAAI,MACR,uHACF;CAGF,MAAM,UAAU,iBAAiB,YAAY;CAC7C,MAAM,OAAO,SAAS,QAAQ,gCAAgC,EAAE;CAChE,MAAM,UAAU,GAAG,OAAO,KAAK,SAAS,GAAG,IAAI,KAAK,IAAI;CAExD,MAAM,SAAwB;EAC5B;EACA;EACA;EACA;EACA;EACA,SAAS;CACX;CAEA,IAAI,YACF,IAAI,qBACF,OAAO,sBAAsB;MAE7B,IAAI;EACF,MAAM,cAAA,GAAA,YAAA,cAAA,CACJ,OAAO,eAAe,WAAW,aAAA,QAAA,KAAA,CAAA,CAAA,cAAA,UAAA,CAAA,CAAA,IACnC;EACA,MAAM,EAAE,4BAA4B,WAClC,yBACF;EACA,MAAM,EAAE,oBAAoB,WAC1B,wCACF;EACA,OAAO,sBAAsB,CAC3B,IAAI,wBACF,IAAI,gBAAgB;GAClB,KAAK;GACL;EACF,CAAC,CACH,CACF;CACF,QAAQ;EACN,MAAM,IAAI,MACR,gIAEF;CACF;CAIJ,OAAO;AACT"}
1
+ {"version":3,"file":"grafana.cjs","names":[],"sources":["../src/grafana.ts"],"sourcesContent":["/**\n * Grafana Cloud preset for autotel\n *\n * Provides a simplified configuration helper for sending traces, metrics,\n * and logs to Grafana Cloud via the OTLP gateway.\n *\n * Get your endpoint and headers from:\n * Grafana Cloud Portal → your stack → Connections → OpenTelemetry → Configure\n *\n * @example\n * ```typescript\n * import { init } from 'autotel';\n * import { createGrafanaConfig } from 'autotel-backends/grafana';\n *\n * init(createGrafanaConfig({\n * endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT!,\n * headers: process.env.OTEL_EXPORTER_OTLP_HEADERS,\n * service: 'my-app',\n * enableLogs: true,\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\nimport type { LogRecordProcessor } from '@opentelemetry/sdk-logs';\n\n// See packages/autotel/src/node-require.ts for why the __filename fallback\n// is necessary alongside import.meta.url.\ndeclare const __filename: string | undefined;\n\n/**\n * Configuration options for Grafana Cloud preset\n */\nexport interface GrafanaPresetConfig {\n /**\n * OTLP gateway endpoint (required).\n * From Grafana Cloud: Stack → Connections → OpenTelemetry → Configure.\n * Example: https://otlp-gateway-prod-gb-south-1.grafana.net/otlp\n */\n endpoint: string;\n\n /**\n * OTLP authentication headers.\n * From the same Configure tile; usually Basic auth.\n * Example: \"Authorization=Basic%20BASE64_INSTANCE_ID_AND_TOKEN\"\n * or object: { Authorization: 'Basic ...' }\n */\n headers?: string | Record<string, string>;\n\n /**\n * Service name (required).\n * Appears in Tempo, Mimir, and Loki as service_name.\n */\n service: string;\n\n /**\n * Deployment environment (e.g. 'production', 'staging').\n *\n * @default process.env.NODE_ENV || 'development'\n */\n environment?: string;\n\n /**\n * Service version for deployment tracking.\n *\n * @default process.env.OTEL_SERVICE_VERSION\n */\n version?: string;\n\n /**\n * Enable log export to Grafana Cloud (Loki) via OTLP.\n * When true, configures logRecordProcessors so OTel Logs API records are exported.\n *\n * @default true\n */\n enableLogs?: boolean;\n\n /**\n * Custom log record processors (advanced).\n * Overrides the default OTLP log processor when enableLogs is true.\n */\n logRecordProcessors?: LogRecordProcessor[];\n}\n\nfunction normalizeHeaders(\n headers: string | Record<string, string> | undefined,\n): Record<string, string> | undefined {\n if (!headers) return undefined;\n if (typeof headers === 'object') return headers;\n const out: Record<string, string> = {};\n for (const pair of headers.split(',')) {\n const [key, ...valueParts] = pair.split('=');\n if (key && valueParts.length > 0) {\n let value = valueParts.join('=').trim();\n value = value.replaceAll('%20', ' ');\n out[key.trim()] = value;\n }\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\n/**\n * Create an autotel configuration for Grafana Cloud OTLP.\n *\n * Sends traces (Tempo), metrics (Mimir), and optionally logs (Loki) to the\n * Grafana Cloud OTLP gateway. Endpoint and headers come from the stack's\n * Connections → OpenTelemetry → Configure tile.\n *\n * @param config - Grafana Cloud configuration options\n * @returns AutotelConfig ready to pass to init()\n */\nexport function createGrafanaConfig(\n config: GrafanaPresetConfig,\n): AutotelConfig {\n const {\n endpoint,\n headers: headersInput,\n service,\n environment,\n version,\n enableLogs = true,\n logRecordProcessors,\n } = config;\n\n if (!endpoint) {\n throw new Error(\n 'Grafana Cloud endpoint is required. Get it from: Grafana Cloud → your stack → Connections → OpenTelemetry → Configure',\n );\n }\n\n const headers = normalizeHeaders(headersInput);\n const base = endpoint.replace(/\\/v1\\/(traces|metrics|logs)$/, '');\n const logsUrl = `${base}${base.endsWith('/') ? '' : '/'}v1/logs`;\n\n const result: AutotelConfig = {\n service,\n environment,\n version,\n endpoint,\n headers,\n metrics: true,\n };\n\n if (enableLogs) {\n if (logRecordProcessors) {\n result.logRecordProcessors = logRecordProcessors;\n } else {\n try {\n const pkgRequire = createRequire(\n typeof __filename === 'string' ? __filename : import.meta.url,\n );\n const { BatchLogRecordProcessor } = pkgRequire(\n '@opentelemetry/sdk-logs',\n );\n const { OTLPLogExporter } = pkgRequire(\n '@opentelemetry/exporter-logs-otlp-http',\n );\n result.logRecordProcessors = [\n new BatchLogRecordProcessor({\n exporter: new OTLPLogExporter({\n url: logsUrl,\n headers,\n }),\n }),\n ];\n } catch {\n throw new Error(\n 'Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. ' +\n 'Install them or set enableLogs: false.',\n );\n }\n }\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,SAAS,iBACP,SACoC;CACpC,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,IAAI,OAAO,YAAY,UAAU,OAAO;CACxC,MAAM,MAA8B,CAAC;CACrC,KAAK,MAAM,QAAQ,QAAQ,MAAM,GAAG,GAAG;EACrC,MAAM,CAAC,KAAK,GAAG,cAAc,KAAK,MAAM,GAAG;EAC3C,IAAI,OAAO,WAAW,SAAS,GAAG;GAChC,IAAI,QAAQ,WAAW,KAAK,GAAG,CAAC,CAAC,KAAK;GACtC,QAAQ,MAAM,WAAW,OAAO,GAAG;GACnC,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;CACA,OAAO,OAAO,KAAK,GAAG,CAAC,CAAC,SAAS,IAAI,MAAM,KAAA;AAC7C;;;;;;;;;;;AAYA,SAAgB,oBACd,QACe;CACf,MAAM,EACJ,UACA,SAAS,cACT,SACA,aACA,SACA,aAAa,MACb,wBACE;CAEJ,IAAI,CAAC,UACH,MAAM,IAAI,MACR,uHACF;CAGF,MAAM,UAAU,iBAAiB,YAAY;CAC7C,MAAM,OAAO,SAAS,QAAQ,gCAAgC,EAAE;CAChE,MAAM,UAAU,GAAG,OAAO,KAAK,SAAS,GAAG,IAAI,KAAK,IAAI;CAExD,MAAM,SAAwB;EAC5B;EACA;EACA;EACA;EACA;EACA,SAAS;CACX;CAEA,IAAI,YACF,IAAI,qBACF,OAAO,sBAAsB;MAE7B,IAAI;EACF,MAAM,cAAA,GAAA,YAAA,cAAA,CACJ,OAAO,eAAe,WAAW,aAAA,QAAA,KAAA,CAAA,CAAA,cAAA,UAAA,CAAA,CAAA,IACnC;EACA,MAAM,EAAE,4BAA4B,WAClC,yBACF;EACA,MAAM,EAAE,oBAAoB,WAC1B,wCACF;EACA,OAAO,sBAAsB,CAC3B,IAAI,wBAAwB,EAC1B,UAAU,IAAI,gBAAgB;GAC5B,KAAK;GACL;EACF,CAAC,EACH,CAAC,CACH;CACF,QAAQ;EACN,MAAM,IAAI,MACR,gIAEF;CACF;CAIJ,OAAO;AACT"}
@@ -1,6 +1,5 @@
1
1
  import { AutotelConfig } from "autotel";
2
2
  import { LogRecordProcessor } from "@opentelemetry/sdk-logs";
3
-
4
3
  //#region src/grafana.d.ts
5
4
  /**
6
5
  * Configuration options for Grafana Cloud preset
@@ -1 +1 @@
1
- {"version":3,"file":"grafana.d.cts","names":[],"sources":["../src/grafana.ts"],"mappings":";;;;;;;UAkCiB,mBAAA;;;;;;EAMf,QAAA;;;;;;;EAQA,OAAA,YAAmB,MAAA;;;;;EAMnB,OAAA;;;;;;EAOA,WAAA;;;;;;EAOA,OAAA;;;;;;;EAQA,UAAA;;;;;EAMA,mBAAA,GAAsB,kBAAkB;AAAA;;;;;;;;;;;iBA8B1B,mBAAA,CACd,MAAA,EAAQ,mBAAA,GACP,aAAa"}
1
+ {"version":3,"file":"grafana.d.cts","names":[],"sources":["../src/grafana.ts"],"mappings":";;;;;;UAkCiB;;;;;;EAMf;;;;;;;EAQA,mBAAmB;;;;;EAMnB;;;;;;EAOA;;;;;;EAOA;;;;;;;EAQA;;;;;EAMA,sBAAsB;;;;;;;;;;;;iBA8BR,oBACd,QAAQ,sBACP"}
package/dist/grafana.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { AutotelConfig } from "autotel";
2
2
  import { LogRecordProcessor } from "@opentelemetry/sdk-logs";
3
-
4
3
  //#region src/grafana.d.ts
5
4
  /**
6
5
  * Configuration options for Grafana Cloud preset
@@ -1 +1 @@
1
- {"version":3,"file":"grafana.d.ts","names":[],"sources":["../src/grafana.ts"],"mappings":";;;;;;;UAkCiB,mBAAA;;;;;;EAMf,QAAA;;;;;;;EAQA,OAAA,YAAmB,MAAA;;;;;EAMnB,OAAA;;;;;;EAOA,WAAA;;;;;;EAOA,OAAA;;;;;;;EAQA,UAAA;;;;;EAMA,mBAAA,GAAsB,kBAAkB;AAAA;;;;;;;;;;;iBA8B1B,mBAAA,CACd,MAAA,EAAQ,mBAAA,GACP,aAAa"}
1
+ {"version":3,"file":"grafana.d.ts","names":[],"sources":["../src/grafana.ts"],"mappings":";;;;;;UAkCiB;;;;;;EAMf;;;;;;;EAQA,mBAAmB;;;;;EAMnB;;;;;;EAOA;;;;;;EAOA;;;;;;;EAQA;;;;;EAMA,sBAAsB;;;;;;;;;;;;iBA8BR,oBACd,QAAQ,sBACP"}
package/dist/grafana.js CHANGED
@@ -65,10 +65,10 @@ function createGrafanaConfig(config) {
65
65
  const pkgRequire = createRequire(typeof __filename === "string" ? __filename : import.meta.url);
66
66
  const { BatchLogRecordProcessor } = pkgRequire("@opentelemetry/sdk-logs");
67
67
  const { OTLPLogExporter } = pkgRequire("@opentelemetry/exporter-logs-otlp-http");
68
- result.logRecordProcessors = [new BatchLogRecordProcessor(new OTLPLogExporter({
68
+ result.logRecordProcessors = [new BatchLogRecordProcessor({ exporter: new OTLPLogExporter({
69
69
  url: logsUrl,
70
70
  headers
71
- }))];
71
+ }) })];
72
72
  } catch {
73
73
  throw new Error("Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. Install them or set enableLogs: false.");
74
74
  }
@@ -1 +1 @@
1
- {"version":3,"file":"grafana.js","names":[],"sources":["../src/grafana.ts"],"sourcesContent":["/**\n * Grafana Cloud preset for autotel\n *\n * Provides a simplified configuration helper for sending traces, metrics,\n * and logs to Grafana Cloud via the OTLP gateway.\n *\n * Get your endpoint and headers from:\n * Grafana Cloud Portal → your stack → Connections → OpenTelemetry → Configure\n *\n * @example\n * ```typescript\n * import { init } from 'autotel';\n * import { createGrafanaConfig } from 'autotel-backends/grafana';\n *\n * init(createGrafanaConfig({\n * endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT!,\n * headers: process.env.OTEL_EXPORTER_OTLP_HEADERS,\n * service: 'my-app',\n * enableLogs: true,\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\nimport type { LogRecordProcessor } from '@opentelemetry/sdk-logs';\n\n// See packages/autotel/src/node-require.ts for why the __filename fallback\n// is necessary alongside import.meta.url.\ndeclare const __filename: string | undefined;\n\n/**\n * Configuration options for Grafana Cloud preset\n */\nexport interface GrafanaPresetConfig {\n /**\n * OTLP gateway endpoint (required).\n * From Grafana Cloud: Stack → Connections → OpenTelemetry → Configure.\n * Example: https://otlp-gateway-prod-gb-south-1.grafana.net/otlp\n */\n endpoint: string;\n\n /**\n * OTLP authentication headers.\n * From the same Configure tile; usually Basic auth.\n * Example: \"Authorization=Basic%20BASE64_INSTANCE_ID_AND_TOKEN\"\n * or object: { Authorization: 'Basic ...' }\n */\n headers?: string | Record<string, string>;\n\n /**\n * Service name (required).\n * Appears in Tempo, Mimir, and Loki as service_name.\n */\n service: string;\n\n /**\n * Deployment environment (e.g. 'production', 'staging').\n *\n * @default process.env.NODE_ENV || 'development'\n */\n environment?: string;\n\n /**\n * Service version for deployment tracking.\n *\n * @default process.env.OTEL_SERVICE_VERSION\n */\n version?: string;\n\n /**\n * Enable log export to Grafana Cloud (Loki) via OTLP.\n * When true, configures logRecordProcessors so OTel Logs API records are exported.\n *\n * @default true\n */\n enableLogs?: boolean;\n\n /**\n * Custom log record processors (advanced).\n * Overrides the default OTLP log processor when enableLogs is true.\n */\n logRecordProcessors?: LogRecordProcessor[];\n}\n\nfunction normalizeHeaders(\n headers: string | Record<string, string> | undefined,\n): Record<string, string> | undefined {\n if (!headers) return undefined;\n if (typeof headers === 'object') return headers;\n const out: Record<string, string> = {};\n for (const pair of headers.split(',')) {\n const [key, ...valueParts] = pair.split('=');\n if (key && valueParts.length > 0) {\n let value = valueParts.join('=').trim();\n value = value.replaceAll('%20', ' ');\n out[key.trim()] = value;\n }\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\n/**\n * Create an autotel configuration for Grafana Cloud OTLP.\n *\n * Sends traces (Tempo), metrics (Mimir), and optionally logs (Loki) to the\n * Grafana Cloud OTLP gateway. Endpoint and headers come from the stack's\n * Connections → OpenTelemetry → Configure tile.\n *\n * @param config - Grafana Cloud configuration options\n * @returns AutotelConfig ready to pass to init()\n */\nexport function createGrafanaConfig(\n config: GrafanaPresetConfig,\n): AutotelConfig {\n const {\n endpoint,\n headers: headersInput,\n service,\n environment,\n version,\n enableLogs = true,\n logRecordProcessors,\n } = config;\n\n if (!endpoint) {\n throw new Error(\n 'Grafana Cloud endpoint is required. Get it from: Grafana Cloud → your stack → Connections → OpenTelemetry → Configure',\n );\n }\n\n const headers = normalizeHeaders(headersInput);\n const base = endpoint.replace(/\\/v1\\/(traces|metrics|logs)$/, '');\n const logsUrl = `${base}${base.endsWith('/') ? '' : '/'}v1/logs`;\n\n const result: AutotelConfig = {\n service,\n environment,\n version,\n endpoint,\n headers,\n metrics: true,\n };\n\n if (enableLogs) {\n if (logRecordProcessors) {\n result.logRecordProcessors = logRecordProcessors;\n } else {\n try {\n const pkgRequire = createRequire(\n typeof __filename === 'string' ? __filename : import.meta.url,\n );\n const { BatchLogRecordProcessor } = pkgRequire(\n '@opentelemetry/sdk-logs',\n );\n const { OTLPLogExporter } = pkgRequire(\n '@opentelemetry/exporter-logs-otlp-http',\n );\n result.logRecordProcessors = [\n new BatchLogRecordProcessor(\n new OTLPLogExporter({\n url: logsUrl,\n headers,\n }),\n ),\n ];\n } catch {\n throw new Error(\n 'Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. ' +\n 'Install them or set enableLogs: false.',\n );\n }\n }\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAqFA,SAAS,iBACP,SACoC;CACpC,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,IAAI,OAAO,YAAY,UAAU,OAAO;CACxC,MAAM,MAA8B,CAAC;CACrC,KAAK,MAAM,QAAQ,QAAQ,MAAM,GAAG,GAAG;EACrC,MAAM,CAAC,KAAK,GAAG,cAAc,KAAK,MAAM,GAAG;EAC3C,IAAI,OAAO,WAAW,SAAS,GAAG;GAChC,IAAI,QAAQ,WAAW,KAAK,GAAG,CAAC,CAAC,KAAK;GACtC,QAAQ,MAAM,WAAW,OAAO,GAAG;GACnC,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;CACA,OAAO,OAAO,KAAK,GAAG,CAAC,CAAC,SAAS,IAAI,MAAM,KAAA;AAC7C;;;;;;;;;;;AAYA,SAAgB,oBACd,QACe;CACf,MAAM,EACJ,UACA,SAAS,cACT,SACA,aACA,SACA,aAAa,MACb,wBACE;CAEJ,IAAI,CAAC,UACH,MAAM,IAAI,MACR,uHACF;CAGF,MAAM,UAAU,iBAAiB,YAAY;CAC7C,MAAM,OAAO,SAAS,QAAQ,gCAAgC,EAAE;CAChE,MAAM,UAAU,GAAG,OAAO,KAAK,SAAS,GAAG,IAAI,KAAK,IAAI;CAExD,MAAM,SAAwB;EAC5B;EACA;EACA;EACA;EACA;EACA,SAAS;CACX;CAEA,IAAI,YACF,IAAI,qBACF,OAAO,sBAAsB;MAE7B,IAAI;EACF,MAAM,aAAa,cACjB,OAAO,eAAe,WAAW,aAAa,OAAO,KAAK,GAC5D;EACA,MAAM,EAAE,4BAA4B,WAClC,yBACF;EACA,MAAM,EAAE,oBAAoB,WAC1B,wCACF;EACA,OAAO,sBAAsB,CAC3B,IAAI,wBACF,IAAI,gBAAgB;GAClB,KAAK;GACL;EACF,CAAC,CACH,CACF;CACF,QAAQ;EACN,MAAM,IAAI,MACR,gIAEF;CACF;CAIJ,OAAO;AACT"}
1
+ {"version":3,"file":"grafana.js","names":[],"sources":["../src/grafana.ts"],"sourcesContent":["/**\n * Grafana Cloud preset for autotel\n *\n * Provides a simplified configuration helper for sending traces, metrics,\n * and logs to Grafana Cloud via the OTLP gateway.\n *\n * Get your endpoint and headers from:\n * Grafana Cloud Portal → your stack → Connections → OpenTelemetry → Configure\n *\n * @example\n * ```typescript\n * import { init } from 'autotel';\n * import { createGrafanaConfig } from 'autotel-backends/grafana';\n *\n * init(createGrafanaConfig({\n * endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT!,\n * headers: process.env.OTEL_EXPORTER_OTLP_HEADERS,\n * service: 'my-app',\n * enableLogs: true,\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\nimport type { LogRecordProcessor } from '@opentelemetry/sdk-logs';\n\n// See packages/autotel/src/node-require.ts for why the __filename fallback\n// is necessary alongside import.meta.url.\ndeclare const __filename: string | undefined;\n\n/**\n * Configuration options for Grafana Cloud preset\n */\nexport interface GrafanaPresetConfig {\n /**\n * OTLP gateway endpoint (required).\n * From Grafana Cloud: Stack → Connections → OpenTelemetry → Configure.\n * Example: https://otlp-gateway-prod-gb-south-1.grafana.net/otlp\n */\n endpoint: string;\n\n /**\n * OTLP authentication headers.\n * From the same Configure tile; usually Basic auth.\n * Example: \"Authorization=Basic%20BASE64_INSTANCE_ID_AND_TOKEN\"\n * or object: { Authorization: 'Basic ...' }\n */\n headers?: string | Record<string, string>;\n\n /**\n * Service name (required).\n * Appears in Tempo, Mimir, and Loki as service_name.\n */\n service: string;\n\n /**\n * Deployment environment (e.g. 'production', 'staging').\n *\n * @default process.env.NODE_ENV || 'development'\n */\n environment?: string;\n\n /**\n * Service version for deployment tracking.\n *\n * @default process.env.OTEL_SERVICE_VERSION\n */\n version?: string;\n\n /**\n * Enable log export to Grafana Cloud (Loki) via OTLP.\n * When true, configures logRecordProcessors so OTel Logs API records are exported.\n *\n * @default true\n */\n enableLogs?: boolean;\n\n /**\n * Custom log record processors (advanced).\n * Overrides the default OTLP log processor when enableLogs is true.\n */\n logRecordProcessors?: LogRecordProcessor[];\n}\n\nfunction normalizeHeaders(\n headers: string | Record<string, string> | undefined,\n): Record<string, string> | undefined {\n if (!headers) return undefined;\n if (typeof headers === 'object') return headers;\n const out: Record<string, string> = {};\n for (const pair of headers.split(',')) {\n const [key, ...valueParts] = pair.split('=');\n if (key && valueParts.length > 0) {\n let value = valueParts.join('=').trim();\n value = value.replaceAll('%20', ' ');\n out[key.trim()] = value;\n }\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\n/**\n * Create an autotel configuration for Grafana Cloud OTLP.\n *\n * Sends traces (Tempo), metrics (Mimir), and optionally logs (Loki) to the\n * Grafana Cloud OTLP gateway. Endpoint and headers come from the stack's\n * Connections → OpenTelemetry → Configure tile.\n *\n * @param config - Grafana Cloud configuration options\n * @returns AutotelConfig ready to pass to init()\n */\nexport function createGrafanaConfig(\n config: GrafanaPresetConfig,\n): AutotelConfig {\n const {\n endpoint,\n headers: headersInput,\n service,\n environment,\n version,\n enableLogs = true,\n logRecordProcessors,\n } = config;\n\n if (!endpoint) {\n throw new Error(\n 'Grafana Cloud endpoint is required. Get it from: Grafana Cloud → your stack → Connections → OpenTelemetry → Configure',\n );\n }\n\n const headers = normalizeHeaders(headersInput);\n const base = endpoint.replace(/\\/v1\\/(traces|metrics|logs)$/, '');\n const logsUrl = `${base}${base.endsWith('/') ? '' : '/'}v1/logs`;\n\n const result: AutotelConfig = {\n service,\n environment,\n version,\n endpoint,\n headers,\n metrics: true,\n };\n\n if (enableLogs) {\n if (logRecordProcessors) {\n result.logRecordProcessors = logRecordProcessors;\n } else {\n try {\n const pkgRequire = createRequire(\n typeof __filename === 'string' ? __filename : import.meta.url,\n );\n const { BatchLogRecordProcessor } = pkgRequire(\n '@opentelemetry/sdk-logs',\n );\n const { OTLPLogExporter } = pkgRequire(\n '@opentelemetry/exporter-logs-otlp-http',\n );\n result.logRecordProcessors = [\n new BatchLogRecordProcessor({\n exporter: new OTLPLogExporter({\n url: logsUrl,\n headers,\n }),\n }),\n ];\n } catch {\n throw new Error(\n 'Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. ' +\n 'Install them or set enableLogs: false.',\n );\n }\n }\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAqFA,SAAS,iBACP,SACoC;CACpC,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,IAAI,OAAO,YAAY,UAAU,OAAO;CACxC,MAAM,MAA8B,CAAC;CACrC,KAAK,MAAM,QAAQ,QAAQ,MAAM,GAAG,GAAG;EACrC,MAAM,CAAC,KAAK,GAAG,cAAc,KAAK,MAAM,GAAG;EAC3C,IAAI,OAAO,WAAW,SAAS,GAAG;GAChC,IAAI,QAAQ,WAAW,KAAK,GAAG,CAAC,CAAC,KAAK;GACtC,QAAQ,MAAM,WAAW,OAAO,GAAG;GACnC,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;CACA,OAAO,OAAO,KAAK,GAAG,CAAC,CAAC,SAAS,IAAI,MAAM,KAAA;AAC7C;;;;;;;;;;;AAYA,SAAgB,oBACd,QACe;CACf,MAAM,EACJ,UACA,SAAS,cACT,SACA,aACA,SACA,aAAa,MACb,wBACE;CAEJ,IAAI,CAAC,UACH,MAAM,IAAI,MACR,uHACF;CAGF,MAAM,UAAU,iBAAiB,YAAY;CAC7C,MAAM,OAAO,SAAS,QAAQ,gCAAgC,EAAE;CAChE,MAAM,UAAU,GAAG,OAAO,KAAK,SAAS,GAAG,IAAI,KAAK,IAAI;CAExD,MAAM,SAAwB;EAC5B;EACA;EACA;EACA;EACA;EACA,SAAS;CACX;CAEA,IAAI,YACF,IAAI,qBACF,OAAO,sBAAsB;MAE7B,IAAI;EACF,MAAM,aAAa,cACjB,OAAO,eAAe,WAAW,aAAa,OAAO,KAAK,GAC5D;EACA,MAAM,EAAE,4BAA4B,WAClC,yBACF;EACA,MAAM,EAAE,oBAAoB,WAC1B,wCACF;EACA,OAAO,sBAAsB,CAC3B,IAAI,wBAAwB,EAC1B,UAAU,IAAI,gBAAgB;GAC5B,KAAK;GACL;EACF,CAAC,EACH,CAAC,CACH;CACF,QAAQ;EACN,MAAM,IAAI,MACR,gIAEF;CACF;CAIJ,OAAO;AACT"}
@@ -1,5 +1,4 @@
1
1
  import { AutotelConfig } from "autotel";
2
-
3
2
  //#region src/honeycomb.d.ts
4
3
  /**
5
4
  * Configuration options for Honeycomb preset
@@ -1 +1 @@
1
- {"version":3,"file":"honeycomb.d.cts","names":[],"sources":["../src/honeycomb.ts"],"mappings":";;;;;;UAmCiB,qBAAA;;;;;;;;;;EAUf,MAAA;;;;;EAMA,OAAA;;;;;;;;EASA,OAAA;;;;;;;EAQA,WAAA;;;;;;EAOA,OAAA;;;;;;;EAQA,QAAA;;;;;;;;;;EAWA,UAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8Cc,qBAAA,CACd,MAAA,EAAQ,qBAAA,GACP,aAAa"}
1
+ {"version":3,"file":"honeycomb.d.cts","names":[],"sources":["../src/honeycomb.ts"],"mappings":";;;;;UAmCiB;;;;;;;;;;EAUf;;;;;EAMA;;;;;;;;EASA;;;;;;;EAQA;;;;;;EAOA;;;;;;;EAQA;;;;;;;;;;EAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8Cc,sBACd,QAAQ,wBACP"}
@@ -1,5 +1,4 @@
1
1
  import { AutotelConfig } from "autotel";
2
-
3
2
  //#region src/honeycomb.d.ts
4
3
  /**
5
4
  * Configuration options for Honeycomb preset
@@ -1 +1 @@
1
- {"version":3,"file":"honeycomb.d.ts","names":[],"sources":["../src/honeycomb.ts"],"mappings":";;;;;;UAmCiB,qBAAA;;;;;;;;;;EAUf,MAAA;;;;;EAMA,OAAA;;;;;;;;EASA,OAAA;;;;;;;EAQA,WAAA;;;;;;EAOA,OAAA;;;;;;;EAQA,QAAA;;;;;;;;;;EAWA,UAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8Cc,qBAAA,CACd,MAAA,EAAQ,qBAAA,GACP,aAAa"}
1
+ {"version":3,"file":"honeycomb.d.ts","names":[],"sources":["../src/honeycomb.ts"],"mappings":";;;;;UAmCiB;;;;;;;;;;EAUf;;;;;EAMA;;;;;;;;EASA;;;;;;;EAQA;;;;;;EAOA;;;;;;;EAQA;;;;;;;;;;EAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8Cc,sBACd,QAAQ,wBACP"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autotel-backends",
3
- "version": "2.12.40",
3
+ "version": "2.12.42",
4
4
  "description": "Vendor backend configurations for Autotel (Honeycomb, Datadog, etc.)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -35,8 +35,7 @@
35
35
  },
36
36
  "files": [
37
37
  "dist",
38
- "README.md",
39
- "skills"
38
+ "README.md"
40
39
  ],
41
40
  "keywords": [
42
41
  "opentelemetry",
@@ -56,14 +55,14 @@
56
55
  "author": "Jag Reehal <jag@jagreehal.com> (https://jagreehal.com)",
57
56
  "license": "Apache-2.0",
58
57
  "dependencies": {
59
- "@opentelemetry/exporter-logs-otlp-http": ">=0.218.0",
60
- "@opentelemetry/sdk-logs": ">=0.218.0",
61
- "autotel": "4.3.0"
58
+ "@opentelemetry/exporter-logs-otlp-http": ">=0.220.0",
59
+ "@opentelemetry/sdk-logs": ">=0.220.0",
60
+ "autotel": "6.0.0"
62
61
  },
63
62
  "peerDependencies": {
64
- "@opentelemetry/exporter-metrics-otlp-http": ">=0.218.0",
65
- "@opentelemetry/exporter-trace-otlp-http": ">=0.218.0",
66
- "@opentelemetry/sdk-metrics": ">=2.7.1",
63
+ "@opentelemetry/exporter-metrics-otlp-http": ">=0.220.0",
64
+ "@opentelemetry/exporter-trace-otlp-http": ">=0.220.0",
65
+ "@opentelemetry/sdk-metrics": ">=2.9.0",
67
66
  "google-auth-library": ">=10.9.0"
68
67
  },
69
68
  "peerDependenciesMeta": {
@@ -81,12 +80,12 @@
81
80
  }
82
81
  },
83
82
  "devDependencies": {
84
- "@types/node": "^26.1.0",
85
- "@typescript-eslint/eslint-plugin": "^8.63.0",
86
- "@typescript-eslint/parser": "^8.63.0",
83
+ "@types/node": "^26.1.1",
84
+ "@typescript-eslint/eslint-plugin": "^8.65.0",
85
+ "@typescript-eslint/parser": "^8.65.0",
87
86
  "eslint-config-prettier": "^10.1.8",
88
87
  "eslint-plugin-unicorn": "^64.0.0",
89
- "tsdown": "^0.22.3",
88
+ "tsdown": "^0.22.12",
90
89
  "typescript": "^6.0.3",
91
90
  "vitest": "^4.1.10"
92
91
  },
@@ -105,7 +104,6 @@
105
104
  "dev": "tsdown --watch",
106
105
  "lint": "eslint src/**/*.ts",
107
106
  "lint:fix": "eslint src/**/*.ts --fix",
108
- "format": "prettier --write .",
109
107
  "format:check": "prettier --check src/**/*.ts",
110
108
  "type-check": "tsc --noEmit",
111
109
  "test": "vitest run --config vitest.unit.config.ts",
@@ -1,281 +0,0 @@
1
- ---
2
- name: autotel-backends
3
- description: >
4
- Vendor preset configs for autotel that produce a ready-to-use AutotelConfig for Honeycomb, Datadog, Google Cloud, and Grafana Cloud with best-practice defaults already baked in.
5
- ---
6
-
7
- # autotel-backends
8
-
9
- Drop-in configuration presets for popular observability backends. Each preset returns an `AutotelConfig` you pass directly to `autotel`'s `init()`. All vendor-specific concerns (endpoints, auth headers, protocol selection, log processors) are handled for you.
10
-
11
- Available backends:
12
-
13
- | Preset | Subpath | Function |
14
- | ------------- | ------------------------------- | ------------------------- |
15
- | Honeycomb | `autotel-backends/honeycomb` | `createHoneycombConfig` |
16
- | Datadog | `autotel-backends/datadog` | `createDatadogConfig` |
17
- | Google Cloud | `autotel-backends/google-cloud` | `createGoogleCloudConfig` |
18
- | Grafana Cloud | `autotel-backends/grafana` | `createGrafanaConfig` |
19
-
20
- ## Setup
21
-
22
- ```bash
23
- pnpm add autotel-backends autotel
24
- ```
25
-
26
- No additional peer dependencies are required for Honeycomb and most Datadog configurations. Google Cloud direct export requires `google-auth-library`. Log export for Datadog and Grafana requires `@opentelemetry/sdk-logs` and `@opentelemetry/exporter-logs-otlp-http` (bundled as direct dependencies).
27
-
28
- ## Configuration / Core Patterns
29
-
30
- ### Honeycomb
31
-
32
- ```typescript
33
- import { init } from 'autotel';
34
- import { createHoneycombConfig } from 'autotel-backends/honeycomb';
35
-
36
- init(
37
- createHoneycombConfig({
38
- apiKey: process.env.HONEYCOMB_API_KEY!,
39
- service: 'my-app',
40
- }),
41
- );
42
- ```
43
-
44
- Uses gRPC to `api.honeycomb.io:443`. Sets `x-honeycomb-team` header automatically.
45
-
46
- **All options:**
47
-
48
- | Option | Required | Default | Description |
49
- | ------------- | -------- | ----------------------------- | ------------------------------------------------------------ |
50
- | `apiKey` | yes | — | Team API key |
51
- | `service` | yes | — | Service name (= dataset in modern accounts) |
52
- | `dataset` | no | — | Classic Honeycomb dataset; sets `x-honeycomb-dataset` header |
53
- | `environment` | no | `NODE_ENV \|\| 'development'` | Deployment environment |
54
- | `version` | no | auto | Service version |
55
- | `endpoint` | no | `'api.honeycomb.io:443'` | Override for custom regions or on-prem |
56
- | `sampleRate` | no | — | Head-based sample rate; sets `x-honeycomb-samplerate` header |
57
-
58
- ### Datadog
59
-
60
- Two modes: **direct cloud ingestion** (API key required) and **local Datadog Agent** (no key needed).
61
-
62
- **Direct cloud ingestion:**
63
-
64
- ```typescript
65
- import { init } from 'autotel';
66
- import { createDatadogConfig } from 'autotel-backends/datadog';
67
-
68
- init(
69
- createDatadogConfig({
70
- apiKey: process.env.DATADOG_API_KEY!,
71
- service: 'my-app',
72
- environment: 'production',
73
- enableLogs: true,
74
- }),
75
- );
76
- ```
77
-
78
- **Local Datadog Agent (Kubernetes / long-running services):**
79
-
80
- ```typescript
81
- init(
82
- createDatadogConfig({
83
- service: 'my-api',
84
- useAgent: true,
85
- agentHost: 'datadog-agent.default.svc.cluster.local',
86
- }),
87
- );
88
- ```
89
-
90
- **All options:**
91
-
92
- | Option | Required | Default | Description |
93
- | --------------------- | -------------- | ---------------------- | ------------------------------------------------------------------------- |
94
- | `apiKey` | if `!useAgent` | — | Datadog API key |
95
- | `service` | yes | — | Service name |
96
- | `site` | no | `'datadoghq.com'` | Datadog site region (`datadoghq.eu`, `us3.datadoghq.com`, etc.) |
97
- | `environment` | no | `DD_ENV \|\| NODE_ENV` | Deployment environment |
98
- | `version` | no | `DD_VERSION \|\| auto` | Service version |
99
- | `enableLogs` | no | `false` | Export OTel logs via OTLP; also sets `OTEL_EXPORTER_OTLP_LOGS_*` env vars |
100
- | `useAgent` | no | `false` | Route telemetry to local Datadog Agent instead of direct cloud ingestion |
101
- | `agentHost` | no | `'localhost'` | Agent hostname (when `useAgent: true`) |
102
- | `agentPort` | no | `4318` | Agent OTLP HTTP port (when `useAgent: true`) |
103
- | `logRecordProcessors` | no | — | Override default log processor (advanced) |
104
-
105
- When `enableLogs: true`, the preset auto-sets `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`, `OTEL_EXPORTER_OTLP_LOGS_PROTOCOL`, and `OTEL_EXPORTER_OTLP_LOGS_HEADERS` environment variables (only if not already set), enabling `pino-opentelemetry-transport` without extra configuration.
106
-
107
- ### Google Cloud
108
-
109
- **Via OpenTelemetry Collector (recommended — no auth in app):**
110
-
111
- ```typescript
112
- import { init } from 'autotel';
113
- import { createGoogleCloudConfig } from 'autotel-backends/google-cloud';
114
-
115
- init(
116
- createGoogleCloudConfig({
117
- projectId: process.env.GOOGLE_CLOUD_PROJECT!,
118
- service: 'my-app',
119
- useCollector: true,
120
- collectorEndpoint: 'http://localhost:4318',
121
- }),
122
- );
123
- ```
124
-
125
- **Direct export (requires `google-auth-library`):**
126
-
127
- ```bash
128
- pnpm add google-auth-library
129
- ```
130
-
131
- ```typescript
132
- init(
133
- createGoogleCloudConfig({
134
- projectId: process.env.GOOGLE_CLOUD_PROJECT!,
135
- service: 'my-app',
136
- }),
137
- );
138
- // Uses Application Default Credentials (ADC) automatically
139
- ```
140
-
141
- **All options:**
142
-
143
- | Option | Required | Default | Description |
144
- | ------------------- | -------- | ------------------------------------ | --------------------------------------------------- |
145
- | `projectId` | yes | — | GCP project ID (also from `GOOGLE_CLOUD_PROJECT`) |
146
- | `service` | yes | — | Service name |
147
- | `environment` | no | `NODE_ENV` | Deployment environment |
148
- | `version` | no | `GCP_VERSION \|\| VERSION` | Service version |
149
- | `useCollector` | no | `false` | Send to local Collector; Collector handles GCP auth |
150
- | `collectorEndpoint` | no | `'http://localhost:4318'` | OTLP Collector address |
151
- | `endpoint` | no | `'https://telemetry.googleapis.com'` | Override Telemetry API base URL |
152
-
153
- ### Grafana Cloud
154
-
155
- ```typescript
156
- import { init } from 'autotel';
157
- import { createGrafanaConfig } from 'autotel-backends/grafana';
158
-
159
- init(
160
- createGrafanaConfig({
161
- endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT!,
162
- headers: process.env.OTEL_EXPORTER_OTLP_HEADERS,
163
- service: 'my-app',
164
- enableLogs: true,
165
- }),
166
- );
167
- ```
168
-
169
- Get `endpoint` and `headers` from: Grafana Cloud portal → your stack → Connections → OpenTelemetry → Configure.
170
-
171
- **All options:**
172
-
173
- | Option | Required | Default | Description |
174
- | --------------------- | -------- | ---------------------- | ------------------------------------------------------------------- |
175
- | `endpoint` | yes | — | OTLP gateway endpoint |
176
- | `headers` | no | — | Auth headers; accepts `"Key=Value,Key2=Value2"` string or an object |
177
- | `service` | yes | — | Service name |
178
- | `environment` | no | `NODE_ENV` | Deployment environment |
179
- | `version` | no | `OTEL_SERVICE_VERSION` | Service version |
180
- | `enableLogs` | no | `true` | Export logs to Grafana Loki via OTLP |
181
- | `logRecordProcessors` | no | — | Override default log processor (advanced) |
182
-
183
- Grafana preset also enables `metrics: true` by default. Logs go to `/v1/logs` on the same gateway.
184
-
185
- ## Common Mistakes
186
-
187
- ### HIGH — Passing apiKey to Datadog with useAgent: true
188
-
189
- ```typescript
190
- // WRONG: apiKey is ignored and Agent mode doesn't use it
191
- init(
192
- createDatadogConfig({
193
- apiKey: process.env.DATADOG_API_KEY!,
194
- service: 'my-api',
195
- useAgent: true,
196
- }),
197
- );
198
- ```
199
-
200
- ```typescript
201
- // CORRECT: omit apiKey when using Agent — Agent handles authentication
202
- init(
203
- createDatadogConfig({
204
- service: 'my-api',
205
- useAgent: true,
206
- }),
207
- );
208
- ```
209
-
210
- ### HIGH — Calling init() without apiKey in direct Datadog mode
211
-
212
- `createDatadogConfig` throws at call-time if `!useAgent && !apiKey`. This is a startup crash, not a runtime one.
213
-
214
- ```typescript
215
- // WRONG: missing apiKey
216
- init(createDatadogConfig({ service: 'my-app' }));
217
- // throws: "Datadog API key is required..."
218
- ```
219
-
220
- ### HIGH — Trying Google Cloud direct export without google-auth-library installed
221
-
222
- ```typescript
223
- // WRONG: throws at runtime if package is absent
224
- init(createGoogleCloudConfig({ projectId: 'my-project', service: 'my-app' }));
225
- // throws: "Direct export to Google Cloud requires google-auth-library..."
226
- ```
227
-
228
- ```typescript
229
- // CORRECT: either install the package or use useCollector: true
230
- pnpm add google-auth-library
231
- // or:
232
- init(createGoogleCloudConfig({
233
- projectId: 'my-project',
234
- service: 'my-app',
235
- useCollector: true,
236
- }));
237
- ```
238
-
239
- ### MEDIUM — Using wrong Honeycomb API key type
240
-
241
- Modern Honeycomb environments use a team-level API key. Classic environments use dataset-specific keys. If traces are missing, verify key type in Honeycomb's account settings. The `dataset` option is only needed for classic accounts.
242
-
243
- ### MEDIUM — Setting OTEL*EXPORTER_OTLP_LOGS*\* env vars before calling createDatadogConfig with enableLogs
244
-
245
- The Datadog preset respects existing env vars and skips overwriting them. If you set `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` manually to the wrong value before calling the preset, the preset's correct value is silently skipped.
246
-
247
- ```typescript
248
- // RISKY: if this env var is already set incorrectly, the preset won't fix it
249
- process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = 'http://wrong-host';
250
- init(createDatadogConfig({ apiKey: key, service: 'app', enableLogs: true }));
251
- ```
252
-
253
- Clear or unset conflicting env vars before calling the preset, or pass `logRecordProcessors` directly.
254
-
255
- ### MEDIUM — Stripping the /v1/traces suffix from Grafana endpoint
256
-
257
- ```typescript
258
- // WRONG: Grafana gateway expects the full base URL; the SDK appends /v1/traces
259
- init(
260
- createGrafanaConfig({
261
- endpoint: 'https://otlp-gateway-prod-gb-south-1.grafana.net/otlp/v1/traces',
262
- // ...
263
- }),
264
- );
265
- ```
266
-
267
- ```typescript
268
- // CORRECT: base endpoint without signal path
269
- init(
270
- createGrafanaConfig({
271
- endpoint: 'https://otlp-gateway-prod-gb-south-1.grafana.net/otlp',
272
- // ...
273
- }),
274
- );
275
- ```
276
-
277
- The preset automatically derives `/v1/logs` for log export by stripping any trailing signal path.
278
-
279
- ## Version
280
-
281
- Targets autotel-backends v2.12.4. Direct deps: `@opentelemetry/exporter-logs-otlp-http` >=0.213.0, `@opentelemetry/sdk-logs` >=0.213.0. Optional peers: `google-auth-library` >=10.6.2 (Google Cloud direct export only). See also: `autotel` (core `init()`), `autotel-adapters` (HTTP framework adapters), `autotel-aws` (AWS instrumentation).