import { MULTIPLAYER_TRACE_SESSION_CACHE_PREFIX } from '@multiplayer-app/session-recorder-common';
/**
 * Implementation of the {@link SpanProcessor} that batches spans exported by
 * the SDK then pushes them to the exporter pipeline.
 */
export class CrashBufferSpanProcessor {
    constructor(_crashBuffer, _serializeSpan) {
        this._crashBuffer = _crashBuffer;
        this._serializeSpan = _serializeSpan;
    }
    forceFlush() {
        return Promise.resolve();
    }
    onStart(_span, _parentContext) {
        return;
    }
    onEnd(span) {
        const _spanContext = span.spanContext();
        const traceId = _spanContext.traceId;
        // // Never buffer/export unsampled spans.
        // if ((_spanContext.traceFlags & TraceFlags.SAMPLED) === 0) {
        //   return
        // }
        if (traceId.startsWith(MULTIPLAYER_TRACE_SESSION_CACHE_PREFIX)) {
            if (this._crashBuffer) {
                this._crashBuffer.appendSpans([
                    {
                        ts: span.startTime[0] * 1000 + span.startTime[1] / 1000000,
                        span: this._serializeSpan(span),
                    },
                ]);
            }
            return;
        }
    }
    shutdown() {
        return Promise.resolve();
    }
}
//# sourceMappingURL=CrashBufferSpanProcessor.js.map