{"version":3,"file":"index.cjs","names":["trace"],"sources":["../src/config.ts","../src/link.ts"],"sourcesContent":["import type { SentryOtlpConfig } from './types';\n\n/**\n * Build OTLP export configuration from a Sentry DSN.\n *\n * Returns the normalized DSN (for Sentry.init), the OTLP base endpoint\n * (autotel appends /v1/traces), and the auth header.\n */\nexport function sentryOtlpConfig(rawDsn: string): SentryOtlpConfig {\n  const dsn = rawDsn.trim().replace(/^dsn=/i, '').trim();\n  if (!dsn) {\n    throw new Error('SENTRY_DSN is required');\n  }\n\n  const url = new URL(dsn);\n  const publicKey = url.username;\n  if (!publicKey) {\n    throw new Error('SENTRY_DSN must contain a public key');\n  }\n\n  const projectId = url.pathname.replace(/^\\/+/, '').split('/')[0];\n  if (!projectId) {\n    throw new Error('SENTRY_DSN is missing the project id');\n  }\n\n  return {\n    dsn,\n    endpoint: `${url.origin}/api/${projectId}/integration/otlp`,\n    headers: {\n      'x-sentry-auth': `sentry sentry_key=${publicKey}`,\n    },\n  };\n}\n","import { trace } from '@opentelemetry/api';\nimport type { SentryLinkable } from './types';\n\n/**\n * Install a global Sentry event processor that attaches the active\n * OpenTelemetry trace_id and span_id to every Sentry event.\n *\n * This is the \"external propagation context\" from the Sentry OTLP Integration\n * spec — it ensures errors, check-ins, and logs are linked to the correct\n * OTel trace without requiring a SpanProcessor bridge.\n *\n * Call once after Sentry.init() and autotel init().\n */\nexport function linkSentryErrors(sentry: SentryLinkable): void {\n  sentry.getGlobalScope().addEventProcessor((event) => {\n    const otelSpan = trace.getActiveSpan();\n    if (!otelSpan) return event;\n\n    const contexts = (event.contexts ?? {}) as Record<string, unknown>;\n\n    // Don't overwrite trace context that's already set\n    if (contexts.trace) return event;\n\n    const ctx = otelSpan.spanContext();\n    return {\n      ...event,\n      contexts: {\n        ...contexts,\n        trace: {\n          trace_id: ctx.traceId,\n          span_id: ctx.spanId,\n        },\n      },\n    };\n  });\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,iBAAiB,QAAkC;CACjE,MAAM,MAAM,OAAO,KAAK,CAAC,CAAC,QAAQ,UAAU,EAAE,CAAC,CAAC,KAAK;CACrD,IAAI,CAAC,KACH,MAAM,IAAI,MAAM,wBAAwB;CAG1C,MAAM,MAAM,IAAI,IAAI,GAAG;CACvB,MAAM,YAAY,IAAI;CACtB,IAAI,CAAC,WACH,MAAM,IAAI,MAAM,sCAAsC;CAGxD,MAAM,YAAY,IAAI,SAAS,QAAQ,QAAQ,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;CAC9D,IAAI,CAAC,WACH,MAAM,IAAI,MAAM,sCAAsC;CAGxD,OAAO;EACL;EACA,UAAU,GAAG,IAAI,OAAO,OAAO,UAAU;EACzC,SAAS,EACP,iBAAiB,qBAAqB,YACxC;CACF;AACF;;;;;;;;;;;;;ACnBA,SAAgB,iBAAiB,QAA8B;CAC7D,OAAO,eAAe,CAAC,CAAC,mBAAmB,UAAU;EACnD,MAAM,WAAWA,mBAAAA,MAAM,cAAc;EACrC,IAAI,CAAC,UAAU,OAAO;EAEtB,MAAM,WAAY,MAAM,YAAY,CAAC;EAGrC,IAAI,SAAS,OAAO,OAAO;EAE3B,MAAM,MAAM,SAAS,YAAY;EACjC,OAAO;GACL,GAAG;GACH,UAAU;IACR,GAAG;IACH,OAAO;KACL,UAAU,IAAI;KACd,SAAS,IAAI;IACf;GACF;EACF;CACF,CAAC;AACH"}