autotel-backends 2.12.6 → 2.12.8

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.
@@ -76,6 +76,10 @@ var GcpAuthSpanExporter = class {
76
76
  this.auth = auth;
77
77
  this.OTLPTraceExporterCtor = OTLPTraceExporterCtor;
78
78
  }
79
+ url;
80
+ projectId;
81
+ auth;
82
+ OTLPTraceExporterCtor;
79
83
  async export(spans, resultCallback) {
80
84
  try {
81
85
  const client = await this.auth.getClient();
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/google-cloud.ts"],"names":["createRequire"],"mappings":";;;;;AA0CA,IAAM,gBAAA,GAAmB,kCAAA;AAyElB,SAAS,wBACd,MAAA,EACe;AACf,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,OAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,YAAA,GAAe,KAAA;AAAA,IACf,iBAAA,GAAoB,uBAAA;AAAA,IACpB,QAAA,GAAW;AAAA,GACb,GAAI,MAAA;AAEJ,EAAA,IAAI,CAAC,SAAA,EAAW;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAEA,EAAA,MAAM,UAAA,GAA4B;AAAA,IAChC,OAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,OAAO;AAAA,MACL,GAAG,UAAA;AAAA,MACH,QAAA,EAAU,iBAAA;AAAA;AAAA,MAEV,OAAA,EAAS,EAAE,qBAAA,EAAuB,SAAA;AAAU,KAC9C;AAAA,EACF;AAGA,EAAA,IAAI;AACF,IAAA,MAAM,WAAA,GAAcA,sBAAA,CAAc,OAAA,CAAQ,GAAA,KAAQ,eAAe,CAAA;AACjE,IAAA,MAAM,EAAE,UAAA,EAAW,GAAI,WAAA,CAAY,qBAAqB,CAAA;AACxD,IAAA,MAAM,EAAE,mBAAkB,GAAI,WAA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A,EACA,cAAA,EACe;AACf,IAAA,IAAI;AACF,MAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,IAAA,CAAK,SAAA,EAAU;AACzC,MAAA,MAAM,aAAA,GAAgB,MAAM,MAAA,CAAO,cAAA,EAAe;AAClD,MAAA,MAAM,QAAQ,aAAA,CAAc,KAAA;AAC5B,MAAA,IAAI,CAAC,KAAA,EAAO;AACV,QAAA,cAAA,CAAe;AAAA,UACb,IAAA,EAAM,CAAA;AAAA,UACN,KAAA,EAAO,IAAI,KAAA,CAAM,0BAA0B;AAAA,SAC5C,CAAA;AACD,QAAA;AAAA,MACF;AACA,MAAA,MAAM,QAAA,GAAW,IAAI,IAAA,CAAK,qBAAA,CAAsB;AAAA,QAC9C,KAAK,IAAA,CAAK,GAAA;AAAA,QACV,OAAA,EAAS;AAAA,UACP,aAAA,EAAe,UAAU,KAAK,CAAA,CAAA;AAAA,UAC9B,uBAAuB,IAAA,CAAK;AAAA;AAC9B,OACD,CAAA;AACD,MAAA,QAAA,CAAS,MAAA,CAAO,OAAO,cAAc,CAAA;AAAA,IACvC,SAAS,KAAA,EAAO;AACd,MAAA,cAAA,CAAe;AAAA,QACb,IAAA,EAAM,CAAA;AAAA,QACN,KAAA,EAAO,iBAAiB,KAAA,GAAQ,KAAA,GAAQ,IAAI,KAAA,CAAM,MAAA,CAAO,KAAK,CAAC;AAAA,OAChE,CAAA;AAAA,IACH;AAAA,EACF;AAAA,EAEA,UAAA,GAA4B;AAC1B,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AAAA,EAEA,QAAA,GAA0B;AACxB,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AACF,CAAA","file":"google-cloud.cjs","sourcesContent":["/**\n * Google Cloud preset for autotel\n *\n * Sends traces (and optionally metrics) to Google Cloud Observability via the\n * Telemetry (OTLP) API. Uses Application Default Credentials (ADC) for auth.\n *\n * @example Direct export to GCP (with google-auth-library)\n * ```typescript\n * import { init } from 'autotel';\n * import { createGoogleCloudConfig } from 'autotel-backends/google-cloud';\n *\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example Via OpenTelemetry Collector (no auth in app)\n * ```typescript\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * useCollector: true,\n * collectorEndpoint: 'http://localhost:4318',\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\n\n/** Minimal SpanExporter-compatible interface (avoids @opentelemetry/sdk-trace-base peer at build time). */\ninterface SpanExporterLike {\n export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): void | Promise<void>;\n forceFlush?(): Promise<void>;\n shutdown?(): Promise<void>;\n}\n\n/** Default Telemetry API base URL (OTLP). */\nconst DEFAULT_ENDPOINT = 'https://telemetry.googleapis.com';\n\n/**\n * Configuration options for Google Cloud preset\n */\nexport interface GoogleCloudPresetConfig {\n /**\n * Google Cloud project ID (required for direct export).\n * Used for quota and resource attribution. Set GOOGLE_CLOUD_PROJECT or\n * GOOGLE_APPLICATION_CREDENTIALS for ADC.\n *\n * @default process.env.GOOGLE_CLOUD_PROJECT\n */\n projectId: string;\n\n /**\n * Service name (required).\n * Appears as service.name in Cloud Trace and Monitoring.\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.GCP_VERSION || process.env.VERSION\n */\n version?: string;\n\n /**\n * Use an OpenTelemetry Collector instead of exporting directly to GCP.\n * When true, the app sends OTLP to collectorEndpoint; the Collector\n * handles authentication to the Telemetry API. No google-auth-library needed.\n *\n * @default false\n */\n useCollector?: boolean;\n\n /**\n * Collector OTLP endpoint (when useCollector is true).\n *\n * @default 'http://localhost:4318'\n */\n collectorEndpoint?: string;\n\n /**\n * Telemetry API base URL (when useCollector is false).\n * Only override for testing or special endpoints.\n *\n * @default 'https://telemetry.googleapis.com'\n */\n endpoint?: string;\n}\n\n/**\n * Create an autotel configuration for Google Cloud Observability (Telemetry API).\n *\n * - With useCollector: false (default), exports directly to the Telemetry API\n * using Application Default Credentials. Requires optional peer dependency\n * google-auth-library for auth. Install: pnpm add google-auth-library\n *\n * - With useCollector: true, sends OTLP to a local Collector; the Collector\n * forwards to GCP with ADC. No google-auth-library needed in the app.\n *\n * @param config - Google Cloud preset options\n * @returns AutotelConfig ready to pass to init()\n */\nexport function createGoogleCloudConfig(\n config: GoogleCloudPresetConfig,\n): AutotelConfig {\n const {\n projectId,\n service,\n environment,\n version,\n useCollector = false,\n collectorEndpoint = 'http://localhost:4318',\n endpoint = DEFAULT_ENDPOINT,\n } = config;\n\n if (!projectId) {\n throw new Error(\n 'Google Cloud projectId is required. Set it or use process.env.GOOGLE_CLOUD_PROJECT.',\n );\n }\n\n const baseConfig: AutotelConfig = {\n service,\n environment,\n version,\n };\n\n if (useCollector) {\n return {\n ...baseConfig,\n endpoint: collectorEndpoint,\n // x-goog-user-project for quota when Collector forwards to GCP\n headers: { 'x-goog-user-project': projectId },\n };\n }\n\n // Direct export: need ADC via google-auth-library\n try {\n const userRequire = createRequire(process.cwd() + '/package.json');\n const { GoogleAuth } = userRequire('google-auth-library');\n const { OTLPTraceExporter } = userRequire(\n '@opentelemetry/exporter-trace-otlp-http',\n );\n\n const tracesUrl = `${endpoint}/v1/traces`;\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n });\n\n const gcpTraceExporter = createGcpAuthTraceExporter(\n tracesUrl,\n projectId,\n auth,\n OTLPTraceExporter,\n );\n\n return {\n ...baseConfig,\n // Structurally compatible with SpanExporter from @opentelemetry/sdk-trace-base\n spanExporters: [\n gcpTraceExporter as NonNullable<AutotelConfig['spanExporters']>[number],\n ],\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (\n message.includes('google-auth-library') ||\n message.includes('Cannot find module')\n ) {\n throw new Error(\n 'Direct export to Google Cloud requires google-auth-library. ' +\n 'Install it: pnpm add google-auth-library. ' +\n 'Or use useCollector: true and run an OpenTelemetry Collector with GCP auth.',\n { cause: error },\n );\n }\n throw error;\n }\n}\n\n/** Minimal auth client: getClient() returns a client with getAccessToken(). */\ninterface GoogleAuthLike {\n getClient(): Promise<{ getAccessToken(): Promise<{ token: string | null }> }>;\n}\n\ntype OTLPTraceExporterCtor = new (config: {\n url: string;\n headers?: Record<string, string>;\n}) => SpanExporterLike;\n\nfunction createGcpAuthTraceExporter(\n url: string,\n projectId: string,\n auth: GoogleAuthLike,\n OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n): SpanExporterLike {\n return new GcpAuthSpanExporter(url, projectId, auth, OTLPTraceExporterCtor);\n}\n\nclass GcpAuthSpanExporter implements SpanExporterLike {\n constructor(\n private readonly url: string,\n private readonly projectId: string,\n private readonly auth: GoogleAuthLike,\n private readonly OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n ) {}\n\n async export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): Promise<void> {\n try {\n const client = await this.auth.getClient();\n const tokenResponse = await client.getAccessToken();\n const token = tokenResponse.token;\n if (!token) {\n resultCallback({\n code: 1,\n error: new Error('No access token from ADC'),\n });\n return;\n }\n const exporter = new this.OTLPTraceExporterCtor({\n url: this.url,\n headers: {\n Authorization: `Bearer ${token}`,\n 'x-goog-user-project': this.projectId,\n },\n });\n exporter.export(spans, resultCallback);\n } catch (error) {\n resultCallback({\n code: 1,\n error: error instanceof Error ? error : new Error(String(error)),\n });\n }\n }\n\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/google-cloud.ts"],"names":["createRequire"],"mappings":";;;;;AA0CA,IAAM,gBAAA,GAAmB,kCAAA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AC5C,CAAA;AACD,QAAA;AAAA,MACF;AACA,MAAA,MAAM,QAAA,GAAW,IAAI,IAAA,CAAK,qBAAA,CAAsB;AAAA,QAC9C,KAAK,IAAA,CAAK,GAAA;AAAA,QACV,OAAA,EAAS;AAAA,UACP,aAAA,EAAe,UAAU,KAAK,CAAA,CAAA;AAAA,UAC9B,uBAAuB,IAAA,CAAK;AAAA;AAC9B,OACD,CAAA;AACD,MAAA,QAAA,CAAS,MAAA,CAAO,OAAO,cAAc,CAAA;AAAA,IACvC,SAAS,KAAA,EAAO;AACd,MAAA,cAAA,CAAe;AAAA,QACb,IAAA,EAAM,CAAA;AAAA,QACN,KAAA,EAAO,iBAAiB,KAAA,GAAQ,KAAA,GAAQ,IAAI,KAAA,CAAM,MAAA,CAAO,KAAK,CAAC;AAAA,OAChE,CAAA;AAAA,IACH;AAAA,EACF;AAAA,EAEA,UAAA,GAA4B;AAC1B,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AAAA,EAEA,QAAA,GAA0B;AACxB,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AACF,CAAA","file":"google-cloud.cjs","sourcesContent":["/**\n * Google Cloud preset for autotel\n *\n * Sends traces (and optionally metrics) to Google Cloud Observability via the\n * Telemetry (OTLP) API. Uses Application Default Credentials (ADC) for auth.\n *\n * @example Direct export to GCP (with google-auth-library)\n * ```typescript\n * import { init } from 'autotel';\n * import { createGoogleCloudConfig } from 'autotel-backends/google-cloud';\n *\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example Via OpenTelemetry Collector (no auth in app)\n * ```typescript\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * useCollector: true,\n * collectorEndpoint: 'http://localhost:4318',\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\n\n/** Minimal SpanExporter-compatible interface (avoids @opentelemetry/sdk-trace-base peer at build time). */\ninterface SpanExporterLike {\n export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): void | Promise<void>;\n forceFlush?(): Promise<void>;\n shutdown?(): Promise<void>;\n}\n\n/** Default Telemetry API base URL (OTLP). */\nconst DEFAULT_ENDPOINT = 'https://telemetry.googleapis.com';\n\n/**\n * Configuration options for Google Cloud preset\n */\nexport interface GoogleCloudPresetConfig {\n /**\n * Google Cloud project ID (required for direct export).\n * Used for quota and resource attribution. Set GOOGLE_CLOUD_PROJECT or\n * GOOGLE_APPLICATION_CREDENTIALS for ADC.\n *\n * @default process.env.GOOGLE_CLOUD_PROJECT\n */\n projectId: string;\n\n /**\n * Service name (required).\n * Appears as service.name in Cloud Trace and Monitoring.\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.GCP_VERSION || process.env.VERSION\n */\n version?: string;\n\n /**\n * Use an OpenTelemetry Collector instead of exporting directly to GCP.\n * When true, the app sends OTLP to collectorEndpoint; the Collector\n * handles authentication to the Telemetry API. No google-auth-library needed.\n *\n * @default false\n */\n useCollector?: boolean;\n\n /**\n * Collector OTLP endpoint (when useCollector is true).\n *\n * @default 'http://localhost:4318'\n */\n collectorEndpoint?: string;\n\n /**\n * Telemetry API base URL (when useCollector is false).\n * Only override for testing or special endpoints.\n *\n * @default 'https://telemetry.googleapis.com'\n */\n endpoint?: string;\n}\n\n/**\n * Create an autotel configuration for Google Cloud Observability (Telemetry API).\n *\n * - With useCollector: false (default), exports directly to the Telemetry API\n * using Application Default Credentials. Requires optional peer dependency\n * google-auth-library for auth. Install: pnpm add google-auth-library\n *\n * - With useCollector: true, sends OTLP to a local Collector; the Collector\n * forwards to GCP with ADC. No google-auth-library needed in the app.\n *\n * @param config - Google Cloud preset options\n * @returns AutotelConfig ready to pass to init()\n */\nexport function createGoogleCloudConfig(\n config: GoogleCloudPresetConfig,\n): AutotelConfig {\n const {\n projectId,\n service,\n environment,\n version,\n useCollector = false,\n collectorEndpoint = 'http://localhost:4318',\n endpoint = DEFAULT_ENDPOINT,\n } = config;\n\n if (!projectId) {\n throw new Error(\n 'Google Cloud projectId is required. Set it or use process.env.GOOGLE_CLOUD_PROJECT.',\n );\n }\n\n const baseConfig: AutotelConfig = {\n service,\n environment,\n version,\n };\n\n if (useCollector) {\n return {\n ...baseConfig,\n endpoint: collectorEndpoint,\n // x-goog-user-project for quota when Collector forwards to GCP\n headers: { 'x-goog-user-project': projectId },\n };\n }\n\n // Direct export: need ADC via google-auth-library\n try {\n const userRequire = createRequire(process.cwd() + '/package.json');\n const { GoogleAuth } = userRequire('google-auth-library');\n const { OTLPTraceExporter } = userRequire(\n '@opentelemetry/exporter-trace-otlp-http',\n );\n\n const tracesUrl = `${endpoint}/v1/traces`;\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n });\n\n const gcpTraceExporter = createGcpAuthTraceExporter(\n tracesUrl,\n projectId,\n auth,\n OTLPTraceExporter,\n );\n\n return {\n ...baseConfig,\n // Structurally compatible with SpanExporter from @opentelemetry/sdk-trace-base\n spanExporters: [\n gcpTraceExporter as NonNullable<AutotelConfig['spanExporters']>[number],\n ],\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (\n message.includes('google-auth-library') ||\n message.includes('Cannot find module')\n ) {\n throw new Error(\n 'Direct export to Google Cloud requires google-auth-library. ' +\n 'Install it: pnpm add google-auth-library. ' +\n 'Or use useCollector: true and run an OpenTelemetry Collector with GCP auth.',\n { cause: error },\n );\n }\n throw error;\n }\n}\n\n/** Minimal auth client: getClient() returns a client with getAccessToken(). */\ninterface GoogleAuthLike {\n getClient(): Promise<{ getAccessToken(): Promise<{ token: string | null }> }>;\n}\n\ntype OTLPTraceExporterCtor = new (config: {\n url: string;\n headers?: Record<string, string>;\n}) => SpanExporterLike;\n\nfunction createGcpAuthTraceExporter(\n url: string,\n projectId: string,\n auth: GoogleAuthLike,\n OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n): SpanExporterLike {\n return new GcpAuthSpanExporter(url, projectId, auth, OTLPTraceExporterCtor);\n}\n\nclass GcpAuthSpanExporter implements SpanExporterLike {\n constructor(\n private readonly url: string,\n private readonly projectId: string,\n private readonly auth: GoogleAuthLike,\n private readonly OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n ) {}\n\n async export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): Promise<void> {\n try {\n const client = await this.auth.getClient();\n const tokenResponse = await client.getAccessToken();\n const token = tokenResponse.token;\n if (!token) {\n resultCallback({\n code: 1,\n error: new Error('No access token from ADC'),\n });\n return;\n }\n const exporter = new this.OTLPTraceExporterCtor({\n url: this.url,\n headers: {\n Authorization: `Bearer ${token}`,\n 'x-goog-user-project': this.projectId,\n },\n });\n exporter.export(spans, resultCallback);\n } catch (error) {\n resultCallback({\n code: 1,\n error: error instanceof Error ? error : new Error(String(error)),\n });\n }\n }\n\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}
@@ -74,6 +74,10 @@ var GcpAuthSpanExporter = class {
74
74
  this.auth = auth;
75
75
  this.OTLPTraceExporterCtor = OTLPTraceExporterCtor;
76
76
  }
77
+ url;
78
+ projectId;
79
+ auth;
80
+ OTLPTraceExporterCtor;
77
81
  async export(spans, resultCallback) {
78
82
  try {
79
83
  const client = await this.auth.getClient();
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/google-cloud.ts"],"names":[],"mappings":";;;AA0CA,IAAM,gBAAA,GAAmB,kCAAA;AAyElB,SAAS,wBACd,MAAA,EACe;AACf,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,OAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,YAAA,GA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C9B,uBAAuB,IAAA,CAAK;AAAA;AAC9B,OACD,CAAA;AACD,MAAA,QAAA,CAAS,MAAA,CAAO,OAAO,cAAc,CAAA;AAAA,IACvC,SAAS,KAAA,EAAO;AACd,MAAA,cAAA,CAAe;AAAA,QACb,IAAA,EAAM,CAAA;AAAA,QACN,KAAA,EAAO,iBAAiB,KAAA,GAAQ,KAAA,GAAQ,IAAI,KAAA,CAAM,MAAA,CAAO,KAAK,CAAC;AAAA,OAChE,CAAA;AAAA,IACH;AAAA,EACF;AAAA,EAEA,UAAA,GAA4B;AAC1B,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AAAA,EAEA,QAAA,GAA0B;AACxB,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AACF,CAAA","file":"google-cloud.js","sourcesContent":["/**\n * Google Cloud preset for autotel\n *\n * Sends traces (and optionally metrics) to Google Cloud Observability via the\n * Telemetry (OTLP) API. Uses Application Default Credentials (ADC) for auth.\n *\n * @example Direct export to GCP (with google-auth-library)\n * ```typescript\n * import { init } from 'autotel';\n * import { createGoogleCloudConfig } from 'autotel-backends/google-cloud';\n *\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example Via OpenTelemetry Collector (no auth in app)\n * ```typescript\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * useCollector: true,\n * collectorEndpoint: 'http://localhost:4318',\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\n\n/** Minimal SpanExporter-compatible interface (avoids @opentelemetry/sdk-trace-base peer at build time). */\ninterface SpanExporterLike {\n export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): void | Promise<void>;\n forceFlush?(): Promise<void>;\n shutdown?(): Promise<void>;\n}\n\n/** Default Telemetry API base URL (OTLP). */\nconst DEFAULT_ENDPOINT = 'https://telemetry.googleapis.com';\n\n/**\n * Configuration options for Google Cloud preset\n */\nexport interface GoogleCloudPresetConfig {\n /**\n * Google Cloud project ID (required for direct export).\n * Used for quota and resource attribution. Set GOOGLE_CLOUD_PROJECT or\n * GOOGLE_APPLICATION_CREDENTIALS for ADC.\n *\n * @default process.env.GOOGLE_CLOUD_PROJECT\n */\n projectId: string;\n\n /**\n * Service name (required).\n * Appears as service.name in Cloud Trace and Monitoring.\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.GCP_VERSION || process.env.VERSION\n */\n version?: string;\n\n /**\n * Use an OpenTelemetry Collector instead of exporting directly to GCP.\n * When true, the app sends OTLP to collectorEndpoint; the Collector\n * handles authentication to the Telemetry API. No google-auth-library needed.\n *\n * @default false\n */\n useCollector?: boolean;\n\n /**\n * Collector OTLP endpoint (when useCollector is true).\n *\n * @default 'http://localhost:4318'\n */\n collectorEndpoint?: string;\n\n /**\n * Telemetry API base URL (when useCollector is false).\n * Only override for testing or special endpoints.\n *\n * @default 'https://telemetry.googleapis.com'\n */\n endpoint?: string;\n}\n\n/**\n * Create an autotel configuration for Google Cloud Observability (Telemetry API).\n *\n * - With useCollector: false (default), exports directly to the Telemetry API\n * using Application Default Credentials. Requires optional peer dependency\n * google-auth-library for auth. Install: pnpm add google-auth-library\n *\n * - With useCollector: true, sends OTLP to a local Collector; the Collector\n * forwards to GCP with ADC. No google-auth-library needed in the app.\n *\n * @param config - Google Cloud preset options\n * @returns AutotelConfig ready to pass to init()\n */\nexport function createGoogleCloudConfig(\n config: GoogleCloudPresetConfig,\n): AutotelConfig {\n const {\n projectId,\n service,\n environment,\n version,\n useCollector = false,\n collectorEndpoint = 'http://localhost:4318',\n endpoint = DEFAULT_ENDPOINT,\n } = config;\n\n if (!projectId) {\n throw new Error(\n 'Google Cloud projectId is required. Set it or use process.env.GOOGLE_CLOUD_PROJECT.',\n );\n }\n\n const baseConfig: AutotelConfig = {\n service,\n environment,\n version,\n };\n\n if (useCollector) {\n return {\n ...baseConfig,\n endpoint: collectorEndpoint,\n // x-goog-user-project for quota when Collector forwards to GCP\n headers: { 'x-goog-user-project': projectId },\n };\n }\n\n // Direct export: need ADC via google-auth-library\n try {\n const userRequire = createRequire(process.cwd() + '/package.json');\n const { GoogleAuth } = userRequire('google-auth-library');\n const { OTLPTraceExporter } = userRequire(\n '@opentelemetry/exporter-trace-otlp-http',\n );\n\n const tracesUrl = `${endpoint}/v1/traces`;\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n });\n\n const gcpTraceExporter = createGcpAuthTraceExporter(\n tracesUrl,\n projectId,\n auth,\n OTLPTraceExporter,\n );\n\n return {\n ...baseConfig,\n // Structurally compatible with SpanExporter from @opentelemetry/sdk-trace-base\n spanExporters: [\n gcpTraceExporter as NonNullable<AutotelConfig['spanExporters']>[number],\n ],\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (\n message.includes('google-auth-library') ||\n message.includes('Cannot find module')\n ) {\n throw new Error(\n 'Direct export to Google Cloud requires google-auth-library. ' +\n 'Install it: pnpm add google-auth-library. ' +\n 'Or use useCollector: true and run an OpenTelemetry Collector with GCP auth.',\n { cause: error },\n );\n }\n throw error;\n }\n}\n\n/** Minimal auth client: getClient() returns a client with getAccessToken(). */\ninterface GoogleAuthLike {\n getClient(): Promise<{ getAccessToken(): Promise<{ token: string | null }> }>;\n}\n\ntype OTLPTraceExporterCtor = new (config: {\n url: string;\n headers?: Record<string, string>;\n}) => SpanExporterLike;\n\nfunction createGcpAuthTraceExporter(\n url: string,\n projectId: string,\n auth: GoogleAuthLike,\n OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n): SpanExporterLike {\n return new GcpAuthSpanExporter(url, projectId, auth, OTLPTraceExporterCtor);\n}\n\nclass GcpAuthSpanExporter implements SpanExporterLike {\n constructor(\n private readonly url: string,\n private readonly projectId: string,\n private readonly auth: GoogleAuthLike,\n private readonly OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n ) {}\n\n async export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): Promise<void> {\n try {\n const client = await this.auth.getClient();\n const tokenResponse = await client.getAccessToken();\n const token = tokenResponse.token;\n if (!token) {\n resultCallback({\n code: 1,\n error: new Error('No access token from ADC'),\n });\n return;\n }\n const exporter = new this.OTLPTraceExporterCtor({\n url: this.url,\n headers: {\n Authorization: `Bearer ${token}`,\n 'x-goog-user-project': this.projectId,\n },\n });\n exporter.export(spans, resultCallback);\n } catch (error) {\n resultCallback({\n code: 1,\n error: error instanceof Error ? error : new Error(String(error)),\n });\n }\n }\n\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/google-cloud.ts"],"names":[],"mappings":";;;AA0CA,IAAM,gBAAA,GAAmB,kCAAA;AAyElB,SAAS,wBACd,MAAA,EACe;AACf,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,OAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,YAAA,GAAe,KAAA;AAAA,IACf,iBAAA,GAAoB,uBAAA;AAAA,IACpB,QAAA,GAAW;AAAA,GACb,GAAI,MAAA;AAEJ,EAAA,IAAI,CAAC,SAAA,EAAW;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAEA,EAAA,MAAM,UAAA,GAA4B;AAAA,IAChC,OAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,OAAO;AAAA,MACL,GAAG,UAAA;AAAA,MACH,QAAA,EAAU,iBAAA;AAAA;AAAA,MAEV,OAAA,EAAS,EAAE,qBAAA,EAAuB,SAAA;AAAU,KA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AAQ,OAAA,EAAQ;AAAA,EACzB;AAAA,EAEA,QAAA,GAA0B;AACxB,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AACF,CAAA","file":"google-cloud.js","sourcesContent":["/**\n * Google Cloud preset for autotel\n *\n * Sends traces (and optionally metrics) to Google Cloud Observability via the\n * Telemetry (OTLP) API. Uses Application Default Credentials (ADC) for auth.\n *\n * @example Direct export to GCP (with google-auth-library)\n * ```typescript\n * import { init } from 'autotel';\n * import { createGoogleCloudConfig } from 'autotel-backends/google-cloud';\n *\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example Via OpenTelemetry Collector (no auth in app)\n * ```typescript\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * useCollector: true,\n * collectorEndpoint: 'http://localhost:4318',\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\n\n/** Minimal SpanExporter-compatible interface (avoids @opentelemetry/sdk-trace-base peer at build time). */\ninterface SpanExporterLike {\n export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): void | Promise<void>;\n forceFlush?(): Promise<void>;\n shutdown?(): Promise<void>;\n}\n\n/** Default Telemetry API base URL (OTLP). */\nconst DEFAULT_ENDPOINT = 'https://telemetry.googleapis.com';\n\n/**\n * Configuration options for Google Cloud preset\n */\nexport interface GoogleCloudPresetConfig {\n /**\n * Google Cloud project ID (required for direct export).\n * Used for quota and resource attribution. Set GOOGLE_CLOUD_PROJECT or\n * GOOGLE_APPLICATION_CREDENTIALS for ADC.\n *\n * @default process.env.GOOGLE_CLOUD_PROJECT\n */\n projectId: string;\n\n /**\n * Service name (required).\n * Appears as service.name in Cloud Trace and Monitoring.\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.GCP_VERSION || process.env.VERSION\n */\n version?: string;\n\n /**\n * Use an OpenTelemetry Collector instead of exporting directly to GCP.\n * When true, the app sends OTLP to collectorEndpoint; the Collector\n * handles authentication to the Telemetry API. No google-auth-library needed.\n *\n * @default false\n */\n useCollector?: boolean;\n\n /**\n * Collector OTLP endpoint (when useCollector is true).\n *\n * @default 'http://localhost:4318'\n */\n collectorEndpoint?: string;\n\n /**\n * Telemetry API base URL (when useCollector is false).\n * Only override for testing or special endpoints.\n *\n * @default 'https://telemetry.googleapis.com'\n */\n endpoint?: string;\n}\n\n/**\n * Create an autotel configuration for Google Cloud Observability (Telemetry API).\n *\n * - With useCollector: false (default), exports directly to the Telemetry API\n * using Application Default Credentials. Requires optional peer dependency\n * google-auth-library for auth. Install: pnpm add google-auth-library\n *\n * - With useCollector: true, sends OTLP to a local Collector; the Collector\n * forwards to GCP with ADC. No google-auth-library needed in the app.\n *\n * @param config - Google Cloud preset options\n * @returns AutotelConfig ready to pass to init()\n */\nexport function createGoogleCloudConfig(\n config: GoogleCloudPresetConfig,\n): AutotelConfig {\n const {\n projectId,\n service,\n environment,\n version,\n useCollector = false,\n collectorEndpoint = 'http://localhost:4318',\n endpoint = DEFAULT_ENDPOINT,\n } = config;\n\n if (!projectId) {\n throw new Error(\n 'Google Cloud projectId is required. Set it or use process.env.GOOGLE_CLOUD_PROJECT.',\n );\n }\n\n const baseConfig: AutotelConfig = {\n service,\n environment,\n version,\n };\n\n if (useCollector) {\n return {\n ...baseConfig,\n endpoint: collectorEndpoint,\n // x-goog-user-project for quota when Collector forwards to GCP\n headers: { 'x-goog-user-project': projectId },\n };\n }\n\n // Direct export: need ADC via google-auth-library\n try {\n const userRequire = createRequire(process.cwd() + '/package.json');\n const { GoogleAuth } = userRequire('google-auth-library');\n const { OTLPTraceExporter } = userRequire(\n '@opentelemetry/exporter-trace-otlp-http',\n );\n\n const tracesUrl = `${endpoint}/v1/traces`;\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n });\n\n const gcpTraceExporter = createGcpAuthTraceExporter(\n tracesUrl,\n projectId,\n auth,\n OTLPTraceExporter,\n );\n\n return {\n ...baseConfig,\n // Structurally compatible with SpanExporter from @opentelemetry/sdk-trace-base\n spanExporters: [\n gcpTraceExporter as NonNullable<AutotelConfig['spanExporters']>[number],\n ],\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (\n message.includes('google-auth-library') ||\n message.includes('Cannot find module')\n ) {\n throw new Error(\n 'Direct export to Google Cloud requires google-auth-library. ' +\n 'Install it: pnpm add google-auth-library. ' +\n 'Or use useCollector: true and run an OpenTelemetry Collector with GCP auth.',\n { cause: error },\n );\n }\n throw error;\n }\n}\n\n/** Minimal auth client: getClient() returns a client with getAccessToken(). */\ninterface GoogleAuthLike {\n getClient(): Promise<{ getAccessToken(): Promise<{ token: string | null }> }>;\n}\n\ntype OTLPTraceExporterCtor = new (config: {\n url: string;\n headers?: Record<string, string>;\n}) => SpanExporterLike;\n\nfunction createGcpAuthTraceExporter(\n url: string,\n projectId: string,\n auth: GoogleAuthLike,\n OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n): SpanExporterLike {\n return new GcpAuthSpanExporter(url, projectId, auth, OTLPTraceExporterCtor);\n}\n\nclass GcpAuthSpanExporter implements SpanExporterLike {\n constructor(\n private readonly url: string,\n private readonly projectId: string,\n private readonly auth: GoogleAuthLike,\n private readonly OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n ) {}\n\n async export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): Promise<void> {\n try {\n const client = await this.auth.getClient();\n const tokenResponse = await client.getAccessToken();\n const token = tokenResponse.token;\n if (!token) {\n resultCallback({\n code: 1,\n error: new Error('No access token from ADC'),\n });\n return;\n }\n const exporter = new this.OTLPTraceExporterCtor({\n url: this.url,\n headers: {\n Authorization: `Bearer ${token}`,\n 'x-goog-user-project': this.projectId,\n },\n });\n exporter.export(spans, resultCallback);\n } catch (error) {\n resultCallback({\n code: 1,\n error: error instanceof Error ? error : new Error(String(error)),\n });\n }\n }\n\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}
package/dist/index.cjs CHANGED
@@ -215,6 +215,10 @@ var GcpAuthSpanExporter = class {
215
215
  this.auth = auth;
216
216
  this.OTLPTraceExporterCtor = OTLPTraceExporterCtor;
217
217
  }
218
+ url;
219
+ projectId;
220
+ auth;
221
+ OTLPTraceExporterCtor;
218
222
  async export(spans, resultCallback) {
219
223
  try {
220
224
  const client = await this.auth.getClient();
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/honeycomb.ts","../src/datadog.ts","../src/google-cloud.ts","../src/grafana.ts"],"names":["createRequire"],"mappings":";;;;;;AA4IO,SAAS,sBACd,MAAA,EACe;AACf,EAAA,MAAM;AAAA,IACJ,MAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,GAAW,sBAAA;AAAA,IACX;AAAA,GACF,GAAI,MAAA;AAGJ,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAGA,EAAA,MAAM,OAAA,GAAkC;AAAA,IACtC,kBAAA,EAAoB;AAAA,GACtB;AAGA,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,OAAA,CAAQ,qBAAqB,CAAA,GAAI,OAAA;AAAA,EACnC;AAGA,EAAA,IAAI,eAAe,MAAA,EAAW;AAC5B,IAAA,OAAA,CAAQ,wBAAwB,CAAA,GAAI,MAAA,CAAO,UAAU,CAAA;AAAA,EACvD;AAEA,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,EAAU,MAAA;AAAA;AAA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AA,UACR;AAAA,SAEF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * Honeycomb preset for autotel\n *\n * Provides a simplified configuration helper for Honeycomb integration\n * with best practices built-in.\n *\n * @example Using Honeycomb with API key\n * ```typescript\n * import { init } from 'autotel';\n * import { createHoneycombConfig } from 'autotel-backends/honeycomb';\n *\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With custom dataset\n * ```typescript\n * import { init } from 'autotel';\n * import { createHoneycombConfig } from 'autotel-backends/honeycomb';\n *\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * dataset: 'production',\n * }));\n * ```\n */\n\nimport type { AutotelConfig } from 'autotel';\n\n/**\n * Configuration options for Honeycomb preset\n */\nexport interface HoneycombPresetConfig {\n /**\n * Honeycomb API key (required).\n *\n * Get your API key from:\n * https://ui.honeycomb.io/account\n *\n * For classic environments, use an environment-specific key.\n * For newer environments, use a team-level API key.\n */\n apiKey: string;\n\n /**\n * Service name (required).\n * Appears as service.name in Honeycomb traces and determines dataset routing.\n */\n service: string;\n\n /**\n * Dataset name (optional).\n * For classic Honeycomb accounts that use datasets.\n * Modern environments route based on service.name instead.\n *\n * @default service name\n */\n dataset?: string;\n\n /**\n * Deployment environment (e.g., 'production', 'staging', 'development').\n * Used for environment filtering in Honeycomb.\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.VERSION || auto-detected from package.json\n */\n version?: string;\n\n /**\n * Honeycomb API endpoint.\n * Use this to configure for different regions or on-premises installations.\n *\n * @default 'api.honeycomb.io:443'\n */\n endpoint?: string;\n\n /**\n * Sample rate for traces (1 = 100%, 10 = 10%, 100 = 1%).\n * Honeycomb's head-based sampling rate.\n *\n * Note: Autotel uses tail-based sampling by default.\n * This setting applies additional head-based sampling if specified.\n *\n * @default undefined (no head-based sampling, relies on tail sampling)\n */\n sampleRate?: number;\n}\n\n/**\n * Create an autotel configuration optimized for Honeycomb.\n *\n * This preset handles:\n * - gRPC protocol configuration (Honeycomb's preferred protocol)\n * - Proper endpoint and authentication headers\n * - Dataset routing (for classic accounts)\n * - Unified service tagging (service, env, version)\n *\n * Honeycomb uses gRPC by default for better performance and lower overhead.\n * This preset automatically configures the gRPC protocol.\n *\n * @param config - Honeycomb-specific configuration options\n * @returns AutotelConfig ready to pass to init()\n *\n * @example Simple configuration\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With custom dataset and environment\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * dataset: 'production',\n * environment: 'production',\n * version: '2.1.0',\n * }));\n * ```\n *\n * @example With sample rate\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * sampleRate: 10, // Sample 10% of traces (head-based sampling)\n * }));\n * ```\n */\nexport function createHoneycombConfig(\n config: HoneycombPresetConfig,\n): AutotelConfig {\n const {\n apiKey,\n service,\n dataset,\n environment,\n version,\n endpoint = 'api.honeycomb.io:443',\n sampleRate,\n } = config;\n\n // Validation: API key is required\n if (!apiKey) {\n throw new Error(\n 'Honeycomb API key is required. Get your API key from: https://ui.honeycomb.io/account',\n );\n }\n\n // Build headers\n const headers: Record<string, string> = {\n 'x-honeycomb-team': apiKey,\n };\n\n // Add dataset header if specified (for classic Honeycomb accounts)\n if (dataset) {\n headers['x-honeycomb-dataset'] = dataset;\n }\n\n // Add sample rate header if specified\n if (sampleRate !== undefined) {\n headers['x-honeycomb-samplerate'] = String(sampleRate);\n }\n\n return {\n service,\n environment,\n version,\n protocol: 'grpc', // Honeycomb uses gRPC for better performance\n endpoint,\n headers,\n };\n}\n","/**\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/**\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(import.meta.url);\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","/**\n * Google Cloud preset for autotel\n *\n * Sends traces (and optionally metrics) to Google Cloud Observability via the\n * Telemetry (OTLP) API. Uses Application Default Credentials (ADC) for auth.\n *\n * @example Direct export to GCP (with google-auth-library)\n * ```typescript\n * import { init } from 'autotel';\n * import { createGoogleCloudConfig } from 'autotel-backends/google-cloud';\n *\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example Via OpenTelemetry Collector (no auth in app)\n * ```typescript\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * useCollector: true,\n * collectorEndpoint: 'http://localhost:4318',\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\n\n/** Minimal SpanExporter-compatible interface (avoids @opentelemetry/sdk-trace-base peer at build time). */\ninterface SpanExporterLike {\n export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): void | Promise<void>;\n forceFlush?(): Promise<void>;\n shutdown?(): Promise<void>;\n}\n\n/** Default Telemetry API base URL (OTLP). */\nconst DEFAULT_ENDPOINT = 'https://telemetry.googleapis.com';\n\n/**\n * Configuration options for Google Cloud preset\n */\nexport interface GoogleCloudPresetConfig {\n /**\n * Google Cloud project ID (required for direct export).\n * Used for quota and resource attribution. Set GOOGLE_CLOUD_PROJECT or\n * GOOGLE_APPLICATION_CREDENTIALS for ADC.\n *\n * @default process.env.GOOGLE_CLOUD_PROJECT\n */\n projectId: string;\n\n /**\n * Service name (required).\n * Appears as service.name in Cloud Trace and Monitoring.\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.GCP_VERSION || process.env.VERSION\n */\n version?: string;\n\n /**\n * Use an OpenTelemetry Collector instead of exporting directly to GCP.\n * When true, the app sends OTLP to collectorEndpoint; the Collector\n * handles authentication to the Telemetry API. No google-auth-library needed.\n *\n * @default false\n */\n useCollector?: boolean;\n\n /**\n * Collector OTLP endpoint (when useCollector is true).\n *\n * @default 'http://localhost:4318'\n */\n collectorEndpoint?: string;\n\n /**\n * Telemetry API base URL (when useCollector is false).\n * Only override for testing or special endpoints.\n *\n * @default 'https://telemetry.googleapis.com'\n */\n endpoint?: string;\n}\n\n/**\n * Create an autotel configuration for Google Cloud Observability (Telemetry API).\n *\n * - With useCollector: false (default), exports directly to the Telemetry API\n * using Application Default Credentials. Requires optional peer dependency\n * google-auth-library for auth. Install: pnpm add google-auth-library\n *\n * - With useCollector: true, sends OTLP to a local Collector; the Collector\n * forwards to GCP with ADC. No google-auth-library needed in the app.\n *\n * @param config - Google Cloud preset options\n * @returns AutotelConfig ready to pass to init()\n */\nexport function createGoogleCloudConfig(\n config: GoogleCloudPresetConfig,\n): AutotelConfig {\n const {\n projectId,\n service,\n environment,\n version,\n useCollector = false,\n collectorEndpoint = 'http://localhost:4318',\n endpoint = DEFAULT_ENDPOINT,\n } = config;\n\n if (!projectId) {\n throw new Error(\n 'Google Cloud projectId is required. Set it or use process.env.GOOGLE_CLOUD_PROJECT.',\n );\n }\n\n const baseConfig: AutotelConfig = {\n service,\n environment,\n version,\n };\n\n if (useCollector) {\n return {\n ...baseConfig,\n endpoint: collectorEndpoint,\n // x-goog-user-project for quota when Collector forwards to GCP\n headers: { 'x-goog-user-project': projectId },\n };\n }\n\n // Direct export: need ADC via google-auth-library\n try {\n const userRequire = createRequire(process.cwd() + '/package.json');\n const { GoogleAuth } = userRequire('google-auth-library');\n const { OTLPTraceExporter } = userRequire(\n '@opentelemetry/exporter-trace-otlp-http',\n );\n\n const tracesUrl = `${endpoint}/v1/traces`;\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n });\n\n const gcpTraceExporter = createGcpAuthTraceExporter(\n tracesUrl,\n projectId,\n auth,\n OTLPTraceExporter,\n );\n\n return {\n ...baseConfig,\n // Structurally compatible with SpanExporter from @opentelemetry/sdk-trace-base\n spanExporters: [\n gcpTraceExporter as NonNullable<AutotelConfig['spanExporters']>[number],\n ],\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (\n message.includes('google-auth-library') ||\n message.includes('Cannot find module')\n ) {\n throw new Error(\n 'Direct export to Google Cloud requires google-auth-library. ' +\n 'Install it: pnpm add google-auth-library. ' +\n 'Or use useCollector: true and run an OpenTelemetry Collector with GCP auth.',\n { cause: error },\n );\n }\n throw error;\n }\n}\n\n/** Minimal auth client: getClient() returns a client with getAccessToken(). */\ninterface GoogleAuthLike {\n getClient(): Promise<{ getAccessToken(): Promise<{ token: string | null }> }>;\n}\n\ntype OTLPTraceExporterCtor = new (config: {\n url: string;\n headers?: Record<string, string>;\n}) => SpanExporterLike;\n\nfunction createGcpAuthTraceExporter(\n url: string,\n projectId: string,\n auth: GoogleAuthLike,\n OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n): SpanExporterLike {\n return new GcpAuthSpanExporter(url, projectId, auth, OTLPTraceExporterCtor);\n}\n\nclass GcpAuthSpanExporter implements SpanExporterLike {\n constructor(\n private readonly url: string,\n private readonly projectId: string,\n private readonly auth: GoogleAuthLike,\n private readonly OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n ) {}\n\n async export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): Promise<void> {\n try {\n const client = await this.auth.getClient();\n const tokenResponse = await client.getAccessToken();\n const token = tokenResponse.token;\n if (!token) {\n resultCallback({\n code: 1,\n error: new Error('No access token from ADC'),\n });\n return;\n }\n const exporter = new this.OTLPTraceExporterCtor({\n url: this.url,\n headers: {\n Authorization: `Bearer ${token}`,\n 'x-goog-user-project': this.projectId,\n },\n });\n exporter.export(spans, resultCallback);\n } catch (error) {\n resultCallback({\n code: 1,\n error: error instanceof Error ? error : new Error(String(error)),\n });\n }\n }\n\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n}\n","/**\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/**\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(import.meta.url);\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"]}
1
+ {"version":3,"sources":["../src/honeycomb.ts","../src/datadog.ts","../src/google-cloud.ts","../src/grafana.ts"],"names":["createRequire"],"mappings":";;;;;;AA4IO,SAAS,sBACd,MAAA,EACe;AACf,EAAA,MAAM;AAAA,IACJ,MAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,GAAW,sBAAA;AAAA,IACX;AAAA,GACF,GAAI,MAAA;AAGJ,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAGA,EAAA,MAAM,OAAA,GAAkC;AAAA,IACtC,kBAAA,EAAoB;AAAA,GACtB;AAGA,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,OAAA,CAAQ,qBAAqB,CAAA,GAAI,OAAA;AAAA,EACnC;AAGA,EAAA,IAAI,eAAe,MAAA,EAAW;AAC5B,IAAA,OAAA,CAAQ,wBAAwB,CAAA,GAAI,MAAA,CAAO,UAAU,CAAA;AAAA,EACvD;AAEA,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,EAAU,MAAA;AAAA;AAAA,IACV,QAAA;AAAA,IACA;AAAA,GACF;AACF;ACOO,SAAS,oBACd,MAAA,EACe;AACf,EAAA,MAAM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A,SAEF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * Honeycomb preset for autotel\n *\n * Provides a simplified configuration helper for Honeycomb integration\n * with best practices built-in.\n *\n * @example Using Honeycomb with API key\n * ```typescript\n * import { init } from 'autotel';\n * import { createHoneycombConfig } from 'autotel-backends/honeycomb';\n *\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With custom dataset\n * ```typescript\n * import { init } from 'autotel';\n * import { createHoneycombConfig } from 'autotel-backends/honeycomb';\n *\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * dataset: 'production',\n * }));\n * ```\n */\n\nimport type { AutotelConfig } from 'autotel';\n\n/**\n * Configuration options for Honeycomb preset\n */\nexport interface HoneycombPresetConfig {\n /**\n * Honeycomb API key (required).\n *\n * Get your API key from:\n * https://ui.honeycomb.io/account\n *\n * For classic environments, use an environment-specific key.\n * For newer environments, use a team-level API key.\n */\n apiKey: string;\n\n /**\n * Service name (required).\n * Appears as service.name in Honeycomb traces and determines dataset routing.\n */\n service: string;\n\n /**\n * Dataset name (optional).\n * For classic Honeycomb accounts that use datasets.\n * Modern environments route based on service.name instead.\n *\n * @default service name\n */\n dataset?: string;\n\n /**\n * Deployment environment (e.g., 'production', 'staging', 'development').\n * Used for environment filtering in Honeycomb.\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.VERSION || auto-detected from package.json\n */\n version?: string;\n\n /**\n * Honeycomb API endpoint.\n * Use this to configure for different regions or on-premises installations.\n *\n * @default 'api.honeycomb.io:443'\n */\n endpoint?: string;\n\n /**\n * Sample rate for traces (1 = 100%, 10 = 10%, 100 = 1%).\n * Honeycomb's head-based sampling rate.\n *\n * Note: Autotel uses tail-based sampling by default.\n * This setting applies additional head-based sampling if specified.\n *\n * @default undefined (no head-based sampling, relies on tail sampling)\n */\n sampleRate?: number;\n}\n\n/**\n * Create an autotel configuration optimized for Honeycomb.\n *\n * This preset handles:\n * - gRPC protocol configuration (Honeycomb's preferred protocol)\n * - Proper endpoint and authentication headers\n * - Dataset routing (for classic accounts)\n * - Unified service tagging (service, env, version)\n *\n * Honeycomb uses gRPC by default for better performance and lower overhead.\n * This preset automatically configures the gRPC protocol.\n *\n * @param config - Honeycomb-specific configuration options\n * @returns AutotelConfig ready to pass to init()\n *\n * @example Simple configuration\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With custom dataset and environment\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * dataset: 'production',\n * environment: 'production',\n * version: '2.1.0',\n * }));\n * ```\n *\n * @example With sample rate\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * sampleRate: 10, // Sample 10% of traces (head-based sampling)\n * }));\n * ```\n */\nexport function createHoneycombConfig(\n config: HoneycombPresetConfig,\n): AutotelConfig {\n const {\n apiKey,\n service,\n dataset,\n environment,\n version,\n endpoint = 'api.honeycomb.io:443',\n sampleRate,\n } = config;\n\n // Validation: API key is required\n if (!apiKey) {\n throw new Error(\n 'Honeycomb API key is required. Get your API key from: https://ui.honeycomb.io/account',\n );\n }\n\n // Build headers\n const headers: Record<string, string> = {\n 'x-honeycomb-team': apiKey,\n };\n\n // Add dataset header if specified (for classic Honeycomb accounts)\n if (dataset) {\n headers['x-honeycomb-dataset'] = dataset;\n }\n\n // Add sample rate header if specified\n if (sampleRate !== undefined) {\n headers['x-honeycomb-samplerate'] = String(sampleRate);\n }\n\n return {\n service,\n environment,\n version,\n protocol: 'grpc', // Honeycomb uses gRPC for better performance\n endpoint,\n headers,\n };\n}\n","/**\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/**\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(import.meta.url);\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","/**\n * Google Cloud preset for autotel\n *\n * Sends traces (and optionally metrics) to Google Cloud Observability via the\n * Telemetry (OTLP) API. Uses Application Default Credentials (ADC) for auth.\n *\n * @example Direct export to GCP (with google-auth-library)\n * ```typescript\n * import { init } from 'autotel';\n * import { createGoogleCloudConfig } from 'autotel-backends/google-cloud';\n *\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example Via OpenTelemetry Collector (no auth in app)\n * ```typescript\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * useCollector: true,\n * collectorEndpoint: 'http://localhost:4318',\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\n\n/** Minimal SpanExporter-compatible interface (avoids @opentelemetry/sdk-trace-base peer at build time). */\ninterface SpanExporterLike {\n export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): void | Promise<void>;\n forceFlush?(): Promise<void>;\n shutdown?(): Promise<void>;\n}\n\n/** Default Telemetry API base URL (OTLP). */\nconst DEFAULT_ENDPOINT = 'https://telemetry.googleapis.com';\n\n/**\n * Configuration options for Google Cloud preset\n */\nexport interface GoogleCloudPresetConfig {\n /**\n * Google Cloud project ID (required for direct export).\n * Used for quota and resource attribution. Set GOOGLE_CLOUD_PROJECT or\n * GOOGLE_APPLICATION_CREDENTIALS for ADC.\n *\n * @default process.env.GOOGLE_CLOUD_PROJECT\n */\n projectId: string;\n\n /**\n * Service name (required).\n * Appears as service.name in Cloud Trace and Monitoring.\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.GCP_VERSION || process.env.VERSION\n */\n version?: string;\n\n /**\n * Use an OpenTelemetry Collector instead of exporting directly to GCP.\n * When true, the app sends OTLP to collectorEndpoint; the Collector\n * handles authentication to the Telemetry API. No google-auth-library needed.\n *\n * @default false\n */\n useCollector?: boolean;\n\n /**\n * Collector OTLP endpoint (when useCollector is true).\n *\n * @default 'http://localhost:4318'\n */\n collectorEndpoint?: string;\n\n /**\n * Telemetry API base URL (when useCollector is false).\n * Only override for testing or special endpoints.\n *\n * @default 'https://telemetry.googleapis.com'\n */\n endpoint?: string;\n}\n\n/**\n * Create an autotel configuration for Google Cloud Observability (Telemetry API).\n *\n * - With useCollector: false (default), exports directly to the Telemetry API\n * using Application Default Credentials. Requires optional peer dependency\n * google-auth-library for auth. Install: pnpm add google-auth-library\n *\n * - With useCollector: true, sends OTLP to a local Collector; the Collector\n * forwards to GCP with ADC. No google-auth-library needed in the app.\n *\n * @param config - Google Cloud preset options\n * @returns AutotelConfig ready to pass to init()\n */\nexport function createGoogleCloudConfig(\n config: GoogleCloudPresetConfig,\n): AutotelConfig {\n const {\n projectId,\n service,\n environment,\n version,\n useCollector = false,\n collectorEndpoint = 'http://localhost:4318',\n endpoint = DEFAULT_ENDPOINT,\n } = config;\n\n if (!projectId) {\n throw new Error(\n 'Google Cloud projectId is required. Set it or use process.env.GOOGLE_CLOUD_PROJECT.',\n );\n }\n\n const baseConfig: AutotelConfig = {\n service,\n environment,\n version,\n };\n\n if (useCollector) {\n return {\n ...baseConfig,\n endpoint: collectorEndpoint,\n // x-goog-user-project for quota when Collector forwards to GCP\n headers: { 'x-goog-user-project': projectId },\n };\n }\n\n // Direct export: need ADC via google-auth-library\n try {\n const userRequire = createRequire(process.cwd() + '/package.json');\n const { GoogleAuth } = userRequire('google-auth-library');\n const { OTLPTraceExporter } = userRequire(\n '@opentelemetry/exporter-trace-otlp-http',\n );\n\n const tracesUrl = `${endpoint}/v1/traces`;\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n });\n\n const gcpTraceExporter = createGcpAuthTraceExporter(\n tracesUrl,\n projectId,\n auth,\n OTLPTraceExporter,\n );\n\n return {\n ...baseConfig,\n // Structurally compatible with SpanExporter from @opentelemetry/sdk-trace-base\n spanExporters: [\n gcpTraceExporter as NonNullable<AutotelConfig['spanExporters']>[number],\n ],\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (\n message.includes('google-auth-library') ||\n message.includes('Cannot find module')\n ) {\n throw new Error(\n 'Direct export to Google Cloud requires google-auth-library. ' +\n 'Install it: pnpm add google-auth-library. ' +\n 'Or use useCollector: true and run an OpenTelemetry Collector with GCP auth.',\n { cause: error },\n );\n }\n throw error;\n }\n}\n\n/** Minimal auth client: getClient() returns a client with getAccessToken(). */\ninterface GoogleAuthLike {\n getClient(): Promise<{ getAccessToken(): Promise<{ token: string | null }> }>;\n}\n\ntype OTLPTraceExporterCtor = new (config: {\n url: string;\n headers?: Record<string, string>;\n}) => SpanExporterLike;\n\nfunction createGcpAuthTraceExporter(\n url: string,\n projectId: string,\n auth: GoogleAuthLike,\n OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n): SpanExporterLike {\n return new GcpAuthSpanExporter(url, projectId, auth, OTLPTraceExporterCtor);\n}\n\nclass GcpAuthSpanExporter implements SpanExporterLike {\n constructor(\n private readonly url: string,\n private readonly projectId: string,\n private readonly auth: GoogleAuthLike,\n private readonly OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n ) {}\n\n async export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): Promise<void> {\n try {\n const client = await this.auth.getClient();\n const tokenResponse = await client.getAccessToken();\n const token = tokenResponse.token;\n if (!token) {\n resultCallback({\n code: 1,\n error: new Error('No access token from ADC'),\n });\n return;\n }\n const exporter = new this.OTLPTraceExporterCtor({\n url: this.url,\n headers: {\n Authorization: `Bearer ${token}`,\n 'x-goog-user-project': this.projectId,\n },\n });\n exporter.export(spans, resultCallback);\n } catch (error) {\n resultCallback({\n code: 1,\n error: error instanceof Error ? error : new Error(String(error)),\n });\n }\n }\n\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n}\n","/**\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/**\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(import.meta.url);\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"]}
package/dist/index.js CHANGED
@@ -212,6 +212,10 @@ var GcpAuthSpanExporter = class {
212
212
  this.auth = auth;
213
213
  this.OTLPTraceExporterCtor = OTLPTraceExporterCtor;
214
214
  }
215
+ url;
216
+ projectId;
217
+ auth;
218
+ OTLPTraceExporterCtor;
215
219
  async export(spans, resultCallback) {
216
220
  try {
217
221
  const client = await this.auth.getClient();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/honeycomb.ts","../src/datadog.ts","../src/google-cloud.ts","../src/grafana.ts"],"names":["createRequire"],"mappings":";;;AA4IO,SAAS,sBACd,MAAA,EACe;AACf,EAAA,MAAM;AAAA,IACJ,MAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,GAAW,sBAAA;AAAA,IACX;AAAA,GACF,GAAI,MAAA;AAGJ,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAGA,EAAA,MAAM,OAAA,GAAkC;AAAA,IACtC,kBAAA,EAAoB;AAAA,GACtB;AAGA,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,OAAA,CAAQ,qBAAqB,CAAA,GAAI,OAAA;AAAA,EACnC;AAGA,EAAA,IAAI,eAAe,MAAA,EAAW;AAC5B,IAAA,OAAA,CAAQ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CAAO,mBAAA,GAAsB;AAAA,UAC3B,IAAI,uBAAA;AAAA,YACF,IAAI,eAAA,CAAgB;AAAA,cAClB,GAAA,EAAK,OAAA;AAAA,cACL;AAAA,aACD;AAAA;AACH,SACF;AAAA,MACF,CAAA,CAAA,MAAQ;AACN,QAAA,MAAM,IAAI,KAAA;AAAA,UACR;AAAA,SAEF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["/**\n * Honeycomb preset for autotel\n *\n * Provides a simplified configuration helper for Honeycomb integration\n * with best practices built-in.\n *\n * @example Using Honeycomb with API key\n * ```typescript\n * import { init } from 'autotel';\n * import { createHoneycombConfig } from 'autotel-backends/honeycomb';\n *\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With custom dataset\n * ```typescript\n * import { init } from 'autotel';\n * import { createHoneycombConfig } from 'autotel-backends/honeycomb';\n *\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * dataset: 'production',\n * }));\n * ```\n */\n\nimport type { AutotelConfig } from 'autotel';\n\n/**\n * Configuration options for Honeycomb preset\n */\nexport interface HoneycombPresetConfig {\n /**\n * Honeycomb API key (required).\n *\n * Get your API key from:\n * https://ui.honeycomb.io/account\n *\n * For classic environments, use an environment-specific key.\n * For newer environments, use a team-level API key.\n */\n apiKey: string;\n\n /**\n * Service name (required).\n * Appears as service.name in Honeycomb traces and determines dataset routing.\n */\n service: string;\n\n /**\n * Dataset name (optional).\n * For classic Honeycomb accounts that use datasets.\n * Modern environments route based on service.name instead.\n *\n * @default service name\n */\n dataset?: string;\n\n /**\n * Deployment environment (e.g., 'production', 'staging', 'development').\n * Used for environment filtering in Honeycomb.\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.VERSION || auto-detected from package.json\n */\n version?: string;\n\n /**\n * Honeycomb API endpoint.\n * Use this to configure for different regions or on-premises installations.\n *\n * @default 'api.honeycomb.io:443'\n */\n endpoint?: string;\n\n /**\n * Sample rate for traces (1 = 100%, 10 = 10%, 100 = 1%).\n * Honeycomb's head-based sampling rate.\n *\n * Note: Autotel uses tail-based sampling by default.\n * This setting applies additional head-based sampling if specified.\n *\n * @default undefined (no head-based sampling, relies on tail sampling)\n */\n sampleRate?: number;\n}\n\n/**\n * Create an autotel configuration optimized for Honeycomb.\n *\n * This preset handles:\n * - gRPC protocol configuration (Honeycomb's preferred protocol)\n * - Proper endpoint and authentication headers\n * - Dataset routing (for classic accounts)\n * - Unified service tagging (service, env, version)\n *\n * Honeycomb uses gRPC by default for better performance and lower overhead.\n * This preset automatically configures the gRPC protocol.\n *\n * @param config - Honeycomb-specific configuration options\n * @returns AutotelConfig ready to pass to init()\n *\n * @example Simple configuration\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With custom dataset and environment\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * dataset: 'production',\n * environment: 'production',\n * version: '2.1.0',\n * }));\n * ```\n *\n * @example With sample rate\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * sampleRate: 10, // Sample 10% of traces (head-based sampling)\n * }));\n * ```\n */\nexport function createHoneycombConfig(\n config: HoneycombPresetConfig,\n): AutotelConfig {\n const {\n apiKey,\n service,\n dataset,\n environment,\n version,\n endpoint = 'api.honeycomb.io:443',\n sampleRate,\n } = config;\n\n // Validation: API key is required\n if (!apiKey) {\n throw new Error(\n 'Honeycomb API key is required. Get your API key from: https://ui.honeycomb.io/account',\n );\n }\n\n // Build headers\n const headers: Record<string, string> = {\n 'x-honeycomb-team': apiKey,\n };\n\n // Add dataset header if specified (for classic Honeycomb accounts)\n if (dataset) {\n headers['x-honeycomb-dataset'] = dataset;\n }\n\n // Add sample rate header if specified\n if (sampleRate !== undefined) {\n headers['x-honeycomb-samplerate'] = String(sampleRate);\n }\n\n return {\n service,\n environment,\n version,\n protocol: 'grpc', // Honeycomb uses gRPC for better performance\n endpoint,\n headers,\n };\n}\n","/**\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/**\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(import.meta.url);\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","/**\n * Google Cloud preset for autotel\n *\n * Sends traces (and optionally metrics) to Google Cloud Observability via the\n * Telemetry (OTLP) API. Uses Application Default Credentials (ADC) for auth.\n *\n * @example Direct export to GCP (with google-auth-library)\n * ```typescript\n * import { init } from 'autotel';\n * import { createGoogleCloudConfig } from 'autotel-backends/google-cloud';\n *\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example Via OpenTelemetry Collector (no auth in app)\n * ```typescript\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * useCollector: true,\n * collectorEndpoint: 'http://localhost:4318',\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\n\n/** Minimal SpanExporter-compatible interface (avoids @opentelemetry/sdk-trace-base peer at build time). */\ninterface SpanExporterLike {\n export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): void | Promise<void>;\n forceFlush?(): Promise<void>;\n shutdown?(): Promise<void>;\n}\n\n/** Default Telemetry API base URL (OTLP). */\nconst DEFAULT_ENDPOINT = 'https://telemetry.googleapis.com';\n\n/**\n * Configuration options for Google Cloud preset\n */\nexport interface GoogleCloudPresetConfig {\n /**\n * Google Cloud project ID (required for direct export).\n * Used for quota and resource attribution. Set GOOGLE_CLOUD_PROJECT or\n * GOOGLE_APPLICATION_CREDENTIALS for ADC.\n *\n * @default process.env.GOOGLE_CLOUD_PROJECT\n */\n projectId: string;\n\n /**\n * Service name (required).\n * Appears as service.name in Cloud Trace and Monitoring.\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.GCP_VERSION || process.env.VERSION\n */\n version?: string;\n\n /**\n * Use an OpenTelemetry Collector instead of exporting directly to GCP.\n * When true, the app sends OTLP to collectorEndpoint; the Collector\n * handles authentication to the Telemetry API. No google-auth-library needed.\n *\n * @default false\n */\n useCollector?: boolean;\n\n /**\n * Collector OTLP endpoint (when useCollector is true).\n *\n * @default 'http://localhost:4318'\n */\n collectorEndpoint?: string;\n\n /**\n * Telemetry API base URL (when useCollector is false).\n * Only override for testing or special endpoints.\n *\n * @default 'https://telemetry.googleapis.com'\n */\n endpoint?: string;\n}\n\n/**\n * Create an autotel configuration for Google Cloud Observability (Telemetry API).\n *\n * - With useCollector: false (default), exports directly to the Telemetry API\n * using Application Default Credentials. Requires optional peer dependency\n * google-auth-library for auth. Install: pnpm add google-auth-library\n *\n * - With useCollector: true, sends OTLP to a local Collector; the Collector\n * forwards to GCP with ADC. No google-auth-library needed in the app.\n *\n * @param config - Google Cloud preset options\n * @returns AutotelConfig ready to pass to init()\n */\nexport function createGoogleCloudConfig(\n config: GoogleCloudPresetConfig,\n): AutotelConfig {\n const {\n projectId,\n service,\n environment,\n version,\n useCollector = false,\n collectorEndpoint = 'http://localhost:4318',\n endpoint = DEFAULT_ENDPOINT,\n } = config;\n\n if (!projectId) {\n throw new Error(\n 'Google Cloud projectId is required. Set it or use process.env.GOOGLE_CLOUD_PROJECT.',\n );\n }\n\n const baseConfig: AutotelConfig = {\n service,\n environment,\n version,\n };\n\n if (useCollector) {\n return {\n ...baseConfig,\n endpoint: collectorEndpoint,\n // x-goog-user-project for quota when Collector forwards to GCP\n headers: { 'x-goog-user-project': projectId },\n };\n }\n\n // Direct export: need ADC via google-auth-library\n try {\n const userRequire = createRequire(process.cwd() + '/package.json');\n const { GoogleAuth } = userRequire('google-auth-library');\n const { OTLPTraceExporter } = userRequire(\n '@opentelemetry/exporter-trace-otlp-http',\n );\n\n const tracesUrl = `${endpoint}/v1/traces`;\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n });\n\n const gcpTraceExporter = createGcpAuthTraceExporter(\n tracesUrl,\n projectId,\n auth,\n OTLPTraceExporter,\n );\n\n return {\n ...baseConfig,\n // Structurally compatible with SpanExporter from @opentelemetry/sdk-trace-base\n spanExporters: [\n gcpTraceExporter as NonNullable<AutotelConfig['spanExporters']>[number],\n ],\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (\n message.includes('google-auth-library') ||\n message.includes('Cannot find module')\n ) {\n throw new Error(\n 'Direct export to Google Cloud requires google-auth-library. ' +\n 'Install it: pnpm add google-auth-library. ' +\n 'Or use useCollector: true and run an OpenTelemetry Collector with GCP auth.',\n { cause: error },\n );\n }\n throw error;\n }\n}\n\n/** Minimal auth client: getClient() returns a client with getAccessToken(). */\ninterface GoogleAuthLike {\n getClient(): Promise<{ getAccessToken(): Promise<{ token: string | null }> }>;\n}\n\ntype OTLPTraceExporterCtor = new (config: {\n url: string;\n headers?: Record<string, string>;\n}) => SpanExporterLike;\n\nfunction createGcpAuthTraceExporter(\n url: string,\n projectId: string,\n auth: GoogleAuthLike,\n OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n): SpanExporterLike {\n return new GcpAuthSpanExporter(url, projectId, auth, OTLPTraceExporterCtor);\n}\n\nclass GcpAuthSpanExporter implements SpanExporterLike {\n constructor(\n private readonly url: string,\n private readonly projectId: string,\n private readonly auth: GoogleAuthLike,\n private readonly OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n ) {}\n\n async export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): Promise<void> {\n try {\n const client = await this.auth.getClient();\n const tokenResponse = await client.getAccessToken();\n const token = tokenResponse.token;\n if (!token) {\n resultCallback({\n code: 1,\n error: new Error('No access token from ADC'),\n });\n return;\n }\n const exporter = new this.OTLPTraceExporterCtor({\n url: this.url,\n headers: {\n Authorization: `Bearer ${token}`,\n 'x-goog-user-project': this.projectId,\n },\n });\n exporter.export(spans, resultCallback);\n } catch (error) {\n resultCallback({\n code: 1,\n error: error instanceof Error ? error : new Error(String(error)),\n });\n }\n }\n\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n}\n","/**\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/**\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(import.meta.url);\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"]}
1
+ {"version":3,"sources":["../src/honeycomb.ts","../src/datadog.ts","../src/google-cloud.ts","../src/grafana.ts"],"names":["createRequire"],"mappings":";;;AA4IO,SAAS,sBACd,MAAA,EACe;AACf,EAAA,MAAM;AAAA,IACJ,MAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,GAAW,sBAAA;AAAA,IACX;AAAA,GACF,GAAI,MAAA;AAGJ,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAGA,EAAA,MAAM,OAAA,GAAkC;AAAA,IACtC,kBAAA,EAAoB;AAAA,GACtB;AAGA,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,OAAA,CAAQ,qBAAqB,CAAA,GAAI,OAAA;AAAA,EACnC;AAGA,EAAA,IAAI,eAAe,MAAA,EAAW;AAC5B,IAAA,OAAA,CAAQ,wBAAwB,CAAA,GAAI,MAAA,CAAO,UAAU,CAAA;AAA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,SACF;AACA,QAAA,MAAA,CAAO,mBAAA,GAAsB;AAAA,UAC3B,IAAI,uBAAA;AAAA,YACF,IAAI,eAAA,CAAgB;AAAA,cAClB,GAAA,EAAK,OAAA;AAAA,cACL;AAAA,aACD;AAAA;AACH,SACF;AAAA,MACF,CAAA,CAAA,MAAQ;AACN,QAAA,MAAM,IAAI,KAAA;AAAA,UACR;AAAA,SAEF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["/**\n * Honeycomb preset for autotel\n *\n * Provides a simplified configuration helper for Honeycomb integration\n * with best practices built-in.\n *\n * @example Using Honeycomb with API key\n * ```typescript\n * import { init } from 'autotel';\n * import { createHoneycombConfig } from 'autotel-backends/honeycomb';\n *\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With custom dataset\n * ```typescript\n * import { init } from 'autotel';\n * import { createHoneycombConfig } from 'autotel-backends/honeycomb';\n *\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * dataset: 'production',\n * }));\n * ```\n */\n\nimport type { AutotelConfig } from 'autotel';\n\n/**\n * Configuration options for Honeycomb preset\n */\nexport interface HoneycombPresetConfig {\n /**\n * Honeycomb API key (required).\n *\n * Get your API key from:\n * https://ui.honeycomb.io/account\n *\n * For classic environments, use an environment-specific key.\n * For newer environments, use a team-level API key.\n */\n apiKey: string;\n\n /**\n * Service name (required).\n * Appears as service.name in Honeycomb traces and determines dataset routing.\n */\n service: string;\n\n /**\n * Dataset name (optional).\n * For classic Honeycomb accounts that use datasets.\n * Modern environments route based on service.name instead.\n *\n * @default service name\n */\n dataset?: string;\n\n /**\n * Deployment environment (e.g., 'production', 'staging', 'development').\n * Used for environment filtering in Honeycomb.\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.VERSION || auto-detected from package.json\n */\n version?: string;\n\n /**\n * Honeycomb API endpoint.\n * Use this to configure for different regions or on-premises installations.\n *\n * @default 'api.honeycomb.io:443'\n */\n endpoint?: string;\n\n /**\n * Sample rate for traces (1 = 100%, 10 = 10%, 100 = 1%).\n * Honeycomb's head-based sampling rate.\n *\n * Note: Autotel uses tail-based sampling by default.\n * This setting applies additional head-based sampling if specified.\n *\n * @default undefined (no head-based sampling, relies on tail sampling)\n */\n sampleRate?: number;\n}\n\n/**\n * Create an autotel configuration optimized for Honeycomb.\n *\n * This preset handles:\n * - gRPC protocol configuration (Honeycomb's preferred protocol)\n * - Proper endpoint and authentication headers\n * - Dataset routing (for classic accounts)\n * - Unified service tagging (service, env, version)\n *\n * Honeycomb uses gRPC by default for better performance and lower overhead.\n * This preset automatically configures the gRPC protocol.\n *\n * @param config - Honeycomb-specific configuration options\n * @returns AutotelConfig ready to pass to init()\n *\n * @example Simple configuration\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With custom dataset and environment\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * dataset: 'production',\n * environment: 'production',\n * version: '2.1.0',\n * }));\n * ```\n *\n * @example With sample rate\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * sampleRate: 10, // Sample 10% of traces (head-based sampling)\n * }));\n * ```\n */\nexport function createHoneycombConfig(\n config: HoneycombPresetConfig,\n): AutotelConfig {\n const {\n apiKey,\n service,\n dataset,\n environment,\n version,\n endpoint = 'api.honeycomb.io:443',\n sampleRate,\n } = config;\n\n // Validation: API key is required\n if (!apiKey) {\n throw new Error(\n 'Honeycomb API key is required. Get your API key from: https://ui.honeycomb.io/account',\n );\n }\n\n // Build headers\n const headers: Record<string, string> = {\n 'x-honeycomb-team': apiKey,\n };\n\n // Add dataset header if specified (for classic Honeycomb accounts)\n if (dataset) {\n headers['x-honeycomb-dataset'] = dataset;\n }\n\n // Add sample rate header if specified\n if (sampleRate !== undefined) {\n headers['x-honeycomb-samplerate'] = String(sampleRate);\n }\n\n return {\n service,\n environment,\n version,\n protocol: 'grpc', // Honeycomb uses gRPC for better performance\n endpoint,\n headers,\n };\n}\n","/**\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/**\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(import.meta.url);\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","/**\n * Google Cloud preset for autotel\n *\n * Sends traces (and optionally metrics) to Google Cloud Observability via the\n * Telemetry (OTLP) API. Uses Application Default Credentials (ADC) for auth.\n *\n * @example Direct export to GCP (with google-auth-library)\n * ```typescript\n * import { init } from 'autotel';\n * import { createGoogleCloudConfig } from 'autotel-backends/google-cloud';\n *\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example Via OpenTelemetry Collector (no auth in app)\n * ```typescript\n * init(createGoogleCloudConfig({\n * projectId: process.env.GOOGLE_CLOUD_PROJECT!,\n * service: 'my-app',\n * useCollector: true,\n * collectorEndpoint: 'http://localhost:4318',\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\n\n/** Minimal SpanExporter-compatible interface (avoids @opentelemetry/sdk-trace-base peer at build time). */\ninterface SpanExporterLike {\n export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): void | Promise<void>;\n forceFlush?(): Promise<void>;\n shutdown?(): Promise<void>;\n}\n\n/** Default Telemetry API base URL (OTLP). */\nconst DEFAULT_ENDPOINT = 'https://telemetry.googleapis.com';\n\n/**\n * Configuration options for Google Cloud preset\n */\nexport interface GoogleCloudPresetConfig {\n /**\n * Google Cloud project ID (required for direct export).\n * Used for quota and resource attribution. Set GOOGLE_CLOUD_PROJECT or\n * GOOGLE_APPLICATION_CREDENTIALS for ADC.\n *\n * @default process.env.GOOGLE_CLOUD_PROJECT\n */\n projectId: string;\n\n /**\n * Service name (required).\n * Appears as service.name in Cloud Trace and Monitoring.\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.GCP_VERSION || process.env.VERSION\n */\n version?: string;\n\n /**\n * Use an OpenTelemetry Collector instead of exporting directly to GCP.\n * When true, the app sends OTLP to collectorEndpoint; the Collector\n * handles authentication to the Telemetry API. No google-auth-library needed.\n *\n * @default false\n */\n useCollector?: boolean;\n\n /**\n * Collector OTLP endpoint (when useCollector is true).\n *\n * @default 'http://localhost:4318'\n */\n collectorEndpoint?: string;\n\n /**\n * Telemetry API base URL (when useCollector is false).\n * Only override for testing or special endpoints.\n *\n * @default 'https://telemetry.googleapis.com'\n */\n endpoint?: string;\n}\n\n/**\n * Create an autotel configuration for Google Cloud Observability (Telemetry API).\n *\n * - With useCollector: false (default), exports directly to the Telemetry API\n * using Application Default Credentials. Requires optional peer dependency\n * google-auth-library for auth. Install: pnpm add google-auth-library\n *\n * - With useCollector: true, sends OTLP to a local Collector; the Collector\n * forwards to GCP with ADC. No google-auth-library needed in the app.\n *\n * @param config - Google Cloud preset options\n * @returns AutotelConfig ready to pass to init()\n */\nexport function createGoogleCloudConfig(\n config: GoogleCloudPresetConfig,\n): AutotelConfig {\n const {\n projectId,\n service,\n environment,\n version,\n useCollector = false,\n collectorEndpoint = 'http://localhost:4318',\n endpoint = DEFAULT_ENDPOINT,\n } = config;\n\n if (!projectId) {\n throw new Error(\n 'Google Cloud projectId is required. Set it or use process.env.GOOGLE_CLOUD_PROJECT.',\n );\n }\n\n const baseConfig: AutotelConfig = {\n service,\n environment,\n version,\n };\n\n if (useCollector) {\n return {\n ...baseConfig,\n endpoint: collectorEndpoint,\n // x-goog-user-project for quota when Collector forwards to GCP\n headers: { 'x-goog-user-project': projectId },\n };\n }\n\n // Direct export: need ADC via google-auth-library\n try {\n const userRequire = createRequire(process.cwd() + '/package.json');\n const { GoogleAuth } = userRequire('google-auth-library');\n const { OTLPTraceExporter } = userRequire(\n '@opentelemetry/exporter-trace-otlp-http',\n );\n\n const tracesUrl = `${endpoint}/v1/traces`;\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n });\n\n const gcpTraceExporter = createGcpAuthTraceExporter(\n tracesUrl,\n projectId,\n auth,\n OTLPTraceExporter,\n );\n\n return {\n ...baseConfig,\n // Structurally compatible with SpanExporter from @opentelemetry/sdk-trace-base\n spanExporters: [\n gcpTraceExporter as NonNullable<AutotelConfig['spanExporters']>[number],\n ],\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (\n message.includes('google-auth-library') ||\n message.includes('Cannot find module')\n ) {\n throw new Error(\n 'Direct export to Google Cloud requires google-auth-library. ' +\n 'Install it: pnpm add google-auth-library. ' +\n 'Or use useCollector: true and run an OpenTelemetry Collector with GCP auth.',\n { cause: error },\n );\n }\n throw error;\n }\n}\n\n/** Minimal auth client: getClient() returns a client with getAccessToken(). */\ninterface GoogleAuthLike {\n getClient(): Promise<{ getAccessToken(): Promise<{ token: string | null }> }>;\n}\n\ntype OTLPTraceExporterCtor = new (config: {\n url: string;\n headers?: Record<string, string>;\n}) => SpanExporterLike;\n\nfunction createGcpAuthTraceExporter(\n url: string,\n projectId: string,\n auth: GoogleAuthLike,\n OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n): SpanExporterLike {\n return new GcpAuthSpanExporter(url, projectId, auth, OTLPTraceExporterCtor);\n}\n\nclass GcpAuthSpanExporter implements SpanExporterLike {\n constructor(\n private readonly url: string,\n private readonly projectId: string,\n private readonly auth: GoogleAuthLike,\n private readonly OTLPTraceExporterCtor: OTLPTraceExporterCtor,\n ) {}\n\n async export(\n spans: unknown[],\n resultCallback: (result: { code: number; error?: Error }) => void,\n ): Promise<void> {\n try {\n const client = await this.auth.getClient();\n const tokenResponse = await client.getAccessToken();\n const token = tokenResponse.token;\n if (!token) {\n resultCallback({\n code: 1,\n error: new Error('No access token from ADC'),\n });\n return;\n }\n const exporter = new this.OTLPTraceExporterCtor({\n url: this.url,\n headers: {\n Authorization: `Bearer ${token}`,\n 'x-goog-user-project': this.projectId,\n },\n });\n exporter.export(spans, resultCallback);\n } catch (error) {\n resultCallback({\n code: 1,\n error: error instanceof Error ? error : new Error(String(error)),\n });\n }\n }\n\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n}\n","/**\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/**\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(import.meta.url);\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autotel-backends",
3
- "version": "2.12.6",
3
+ "version": "2.12.8",
4
4
  "description": "Vendor backend configurations for Autotel (Honeycomb, Datadog, etc.)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -58,7 +58,7 @@
58
58
  "dependencies": {
59
59
  "@opentelemetry/exporter-logs-otlp-http": ">=0.214.0",
60
60
  "@opentelemetry/sdk-logs": ">=0.214.0",
61
- "autotel": "2.26.0"
61
+ "autotel": "2.26.2"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "@opentelemetry/exporter-metrics-otlp-http": ">=0.214.0",