{"version":3,"sources":["../src/tail-sampling-processor.ts"],"names":["AUTOTEL_SAMPLING_TAIL_EVALUATED","AUTOTEL_SAMPLING_TAIL_KEEP"],"mappings":";;;;;AAyBO,IAAM,4BAAN,MAAyD;AAAA,EACtD,gBAAA;AAAA,EAER,YAAY,gBAAA,EAAiC;AAC3C,IAAA,IAAA,CAAK,gBAAA,GAAmB,gBAAA;AAAA,EAC1B;AAAA,EAEA,OAAA,CAAQ,MAAY,aAAA,EAA8B;AAChD,IAAA,IAAA,CAAK,gBAAA,CAAiB,OAAA,CAAQ,IAAA,EAAM,aAAa,CAAA;AAAA,EACnD;AAAA,EAEA,MAAM,IAAA,EAA0B;AAC9B,IAAA,MAAM,aAAA,GAAgB,IAAA,CAAK,UAAA,CAAWA,iDAA+B,CAAA;AACrE,IAAA,MAAM,UAAA,GAAa,IAAA,CAAK,UAAA,CAAWC,4CAA0B,CAAA;AAE7D,IAAA,IAAI,aAAA,KAAkB,IAAA,IAAQ,UAAA,KAAe,KAAA,EAAO;AAClD,MAAA;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,gBAAA,CAAiB,MAAM,IAAI,CAAA;AAAA,EAClC;AAAA,EAEA,UAAA,GAA4B;AAC1B,IAAA,OAAO,IAAA,CAAK,iBAAiB,UAAA,EAAW;AAAA,EAC1C;AAAA,EAEA,QAAA,GAA0B;AACxB,IAAA,OAAO,IAAA,CAAK,iBAAiB,QAAA,EAAS;AAAA,EACxC;AACF","file":"chunk-CEAQK2QY.cjs","sourcesContent":["/**\n * Tail Sampling Span Processor\n *\n * Filters spans based on the `autotel.sampling.tail.keep` attribute set during execution.\n * This enables adaptive sampling where we decide whether to keep a span AFTER\n * the operation completes, based on criteria like errors, duration, etc.\n *\n * How it works:\n * 1. Decorator creates span optimistically (head sampling returns true)\n * 2. Operation executes and completes\n * 3. Decorator calls shouldKeepTrace() and sets autotel.sampling.tail.keep attribute\n * 4. This processor checks the attribute and drops spans marked as false\n */\n\nimport type {\n  SpanProcessor,\n  ReadableSpan,\n} from '@opentelemetry/sdk-trace-base';\nimport type { Context } from '@opentelemetry/api';\nimport type { Span } from '@opentelemetry/sdk-trace-base';\nimport {\n  AUTOTEL_SAMPLING_TAIL_KEEP,\n  AUTOTEL_SAMPLING_TAIL_EVALUATED,\n} from './sampling';\n\nexport class TailSamplingSpanProcessor implements SpanProcessor {\n  private wrappedProcessor: SpanProcessor;\n\n  constructor(wrappedProcessor: SpanProcessor) {\n    this.wrappedProcessor = wrappedProcessor;\n  }\n\n  onStart(span: Span, parentContext: Context): void {\n    this.wrappedProcessor.onStart(span, parentContext);\n  }\n\n  onEnd(span: ReadableSpan): void {\n    const tailEvaluated = span.attributes[AUTOTEL_SAMPLING_TAIL_EVALUATED];\n    const shouldKeep = span.attributes[AUTOTEL_SAMPLING_TAIL_KEEP];\n\n    if (tailEvaluated === true && shouldKeep === false) {\n      return;\n    }\n\n    this.wrappedProcessor.onEnd(span);\n  }\n\n  forceFlush(): Promise<void> {\n    return this.wrappedProcessor.forceFlush();\n  }\n\n  shutdown(): Promise<void> {\n    return this.wrappedProcessor.shutdown();\n  }\n}\n"]}