import { InMemoryMetricExporter, MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'; import { InMemorySpanExporter, BasicTracerProvider } from '@opentelemetry/sdk-trace-base'; /** * In-memory OpenTelemetry collectors for cross-transport parity testing. * * Provides {@link InMemorySpanCollector} and {@link InMemoryMetricCollector} — * lightweight wrappers around the official SDK in-memory exporters with * `flush()` helpers that return a normalized, transport-agnostic shape. * * "Normalized" here means: * - the `connectum.transport` span attribute is stripped (it intentionally * differs between HTTP and in-process paths and would defeat parity diff); * - the `transport` metric attribute is stripped for the same reason; * - identifiers that legitimately differ between independent runs * (`traceId`, `spanId`, `parentSpanId`, wall-clock timestamps) are * preserved in the raw output so callers performing structural diff * can mask them as needed (the default driver compare strips them). * * Each scenario must use a *fresh* collector pair, otherwise the second * transport will observe spans/metrics emitted by the first. * * @module otel-collectors */ /** Span attribute key produced by `@connectum/otel` to distinguish transports. */ declare const TRANSPORT_SPAN_ATTRIBUTE = "connectum.transport"; /** Metric attribute key produced by `@connectum/otel` to distinguish transports. */ declare const TRANSPORT_METRIC_ATTRIBUTE = "transport"; /** * Structural, transport-agnostic representation of a span suitable for `deepEqual`. */ interface NormalizedSpan { name: string; kind: number; attributes: Record; events: Array<{ name: string; attributes: Record; }>; status: { code: number; message: string | undefined; }; traceId: string; spanId: string; parentSpanId: string | undefined; } /** * Structural representation of a single metric data point. */ interface NormalizedMetric { name: string; description: string; unit: string; type: string; points: Array<{ attributes: Record; value: unknown; }>; } /** * In-memory span collector. Owns its own `BasicTracerProvider` so that * different scenarios cannot cross-contaminate. * * Callers wishing to register the provider globally (so that * `trace.getTracer(...)` resolves here) should call {@link registerGlobal} * — and pair it with {@link InMemorySpanCollector.dispose} when done. */ declare class InMemorySpanCollector { readonly exporter: InMemorySpanExporter; readonly provider: BasicTracerProvider; constructor(); /** * Returns normalized finished spans collected so far. * * Spans are sorted by `(name, kind, sorted-attributes)` so that scenarios * which emit multiple spans concurrently produce a deterministic order * for the parity structural diff. */ flush(): NormalizedSpan[]; /** Clear the internal buffer. */ reset(): void; dispose(): Promise; } /** * In-memory metric collector. Owns its own `MeterProvider` and periodic * reader. `flush()` performs a forced collect+export cycle synchronously * (via `forceFlush`) and returns the normalized data. */ declare class InMemoryMetricCollector { readonly exporter: InMemoryMetricExporter; readonly provider: MeterProvider; readonly reader: PeriodicExportingMetricReader; constructor(); flush(): Promise; reset(): void; dispose(): Promise; } export { InMemoryMetricCollector as I, type NormalizedMetric as N, TRANSPORT_METRIC_ATTRIBUTE as T, InMemorySpanCollector as a, type NormalizedSpan as b, TRANSPORT_SPAN_ATTRIBUTE as c };