{"version":3,"sources":["../src/observability-sdk/processors/filterable-batch-span-processor.ts","../src/observability-sdk/features/data-capture/presets.ts"],"sourcesContent":["/**\n * Filterable Batch Span Exporter for OpenTelemetry\n *\n * This module provides a BatchSpanProcessor subclass that allows filtering of spans before export\n * based on configurable rules. Spans matching any exclude rule are dropped and not exported.\n *\n * @module filterable-batch-span-exporter\n */\n\nimport {\n  BatchSpanProcessor,\n  type ReadableSpan,\n  type SpanExporter,\n} from '@opentelemetry/sdk-trace-base';\n\n/**\n * A rule for excluding spans from export based on their name or instrumentation scope name.\n *\n * @property fieldName - The span field to match against ('span_name' or 'instrumentation_scope_name').\n * @property matchValue - The value to match against the field.\n * @property matchOperation - The operation to use for matching ('includes', 'exact_match', 'starts_with', 'ends_with').\n *\n * @example\n * const rule: SpanProcessingExcludeRule = {\n *   fieldName: 'span_name',\n *   matchValue: 'heartbeat',\n *   matchOperation: 'exact_match',\n * };\n */\nexport interface SpanProcessingExcludeRule {\n  fieldName: \"span_name\" | \"instrumentation_scope_name\";\n  matchValue: string;\n  matchOperation: \"includes\" | \"exact_match\" | \"starts_with\" | \"ends_with\";\n}\n\n/**\n * A BatchSpanProcessor that filters out spans matching any of the provided exclude rules before export.\n *\n * This is useful for dropping noisy or irrelevant spans (e.g., health checks, heartbeats) from being exported to your tracing backend.\n *\n * @example\n * import { FilterableBatchSpanProcessor } from './filterable-batch-span-exporter';\n * import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';\n *\n * const exporter = new OTLPTraceExporter({ url: '...' });\n * const filters = [\n *   { fieldName: 'span_name', matchValue: 'heartbeat', matchOperation: 'exact_match' },\n *   { fieldName: 'instrumentation_scope_name', matchValue: 'internal', matchOperation: 'starts_with' },\n * ];\n * provider.addSpanProcessor(new FilterableBatchSpanProcessor(exporter, filters));\n */\nexport class FilterableBatchSpanProcessor extends BatchSpanProcessor {\n  private readonly _filters: SpanProcessingExcludeRule[];\n\n  /**\n   * Create a new FilterableBatchSpanProcessor.\n   *\n   * @param exporter - The underlying SpanExporter to use for exporting spans.\n   * @param filters - An array of rules for excluding spans from export.\n   */\n  constructor(exporter: SpanExporter, filters: SpanProcessingExcludeRule[]) {\n    super(exporter);\n    this._filters = filters;\n  }\n\n  /**\n   * Called when a span ends. If the span matches any exclude rule, it is dropped and not exported.\n   *\n   * @param span - The ReadableSpan that has ended.\n   */\n  override onEnd(span: ReadableSpan): void {\n    for (const filter of this._filters) {\n      let sourceValue: string;\n\n      if (filter.fieldName === \"span_name\") {\n        sourceValue = span.name;\n      } else if (filter.fieldName === \"instrumentation_scope_name\") {\n        sourceValue = span.instrumentationScope.name;\n      } else {\n        continue;\n      }\n\n      const matchValue = filter.matchValue;\n      const matchOperation = filter.matchOperation;\n\n      switch (true) {\n        case matchOperation === \"exact_match\" && sourceValue === matchValue:\n        case matchOperation === \"includes\" && sourceValue.includes(matchValue):\n        case matchOperation === \"starts_with\" && sourceValue.startsWith(matchValue):\n        case matchOperation === \"ends_with\" && sourceValue.endsWith(matchValue):\n          return;\n\n        default: break;\n      }\n    }\n\n    super.onEnd(span);\n  }\n}\n","import { type DataCaptureMode } from \"./types\";\n\n/**\n * Predefined data capture configurations for common use cases.\n */\nexport const DataCapturePresets = {\n  /**\n   * Capture both input and output - useful for development and debugging.\n   */\n  CAPTURE_ALL: \"all\" as DataCaptureMode,\n\n  /**\n   * Capture nothing - useful for high-security environments.\n   */\n  CAPTURE_NONE: \"none\" as DataCaptureMode,\n\n  /**\n   * Capture only inputs - useful when you want to see what's being sent.\n   */\n  INPUT_ONLY: \"input\" as DataCaptureMode,\n\n  /**\n   * Capture only outputs - useful when you want to see responses.\n   */\n  OUTPUT_ONLY: \"output\" as DataCaptureMode,\n} as const;\n"],"mappings":";;;;;AASA;AAAA,EACE;AAAA,OAGK;AAsCA,IAAM,+BAAN,cAA2C,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASnE,YAAY,UAAwB,SAAsC;AACxE,UAAM,QAAQ;AACd,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOS,MAAM,MAA0B;AACvC,eAAW,UAAU,KAAK,UAAU;AAClC,UAAI;AAEJ,UAAI,OAAO,cAAc,aAAa;AACpC,sBAAc,KAAK;AAAA,MACrB,WAAW,OAAO,cAAc,8BAA8B;AAC5D,sBAAc,KAAK,qBAAqB;AAAA,MAC1C,OAAO;AACL;AAAA,MACF;AAEA,YAAM,aAAa,OAAO;AAC1B,YAAM,iBAAiB,OAAO;AAE9B,cAAQ,MAAM;AAAA,QACZ,MAAK,mBAAmB,iBAAiB,gBAAgB;AAAA,QACzD,MAAK,mBAAmB,cAAc,YAAY,SAAS,UAAU;AAAA,QACrE,MAAK,mBAAmB,iBAAiB,YAAY,WAAW,UAAU;AAAA,QAC1E,MAAK,mBAAmB,eAAe,YAAY,SAAS,UAAU;AACpE;AAAA,QAEF;AAAS;AAAA,MACX;AAAA,IACF;AAEA,UAAM,MAAM,IAAI;AAAA,EAClB;AACF;;;AC7FO,IAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAIhC,aAAa;AAAA;AAAA;AAAA;AAAA,EAKb,cAAc;AAAA;AAAA;AAAA;AAAA,EAKd,YAAY;AAAA;AAAA;AAAA;AAAA,EAKZ,aAAa;AACf;","names":[]}