/**
 * Sentry Streaming Context - Anonymous context for debugging streaming issues
 *
 * Extracts trace headers from mobile clients and adds them to Sentry scope
 * for cross-service error correlation without user identification.
 */ import * as Sentry from "@sentry/node";
/**
 * Express middleware to extract trace headers and set Sentry context
 * Use at the top of your middleware stack
 */ export function sentryTraceMiddleware(req, res, next) {
    const sessionId = req.headers['x-session-id'];
    const traceId = req.headers['x-trace-id'];
    if (sessionId || traceId) {
        // Set tags for easy filtering
        if (sessionId) {
            Sentry.setTag('client_session_id', sessionId);
        }
        if (traceId) {
            Sentry.setTag('trace_id', traceId);
        }
        // Set context with full details
        Sentry.setContext('client_trace', {
            session_id: sessionId,
            trace_id: traceId,
            user_agent: req.headers['user-agent'],
            endpoint: req.path,
            method: req.method
        });
        // Add breadcrumb for request
        Sentry.addBreadcrumb({
            category: 'http',
            message: `${req.method} ${req.path}`,
            data: {
                session_id: sessionId,
                trace_id: traceId
            },
            level: 'info'
        });
    }
    next();
}
/**
 * Add streaming-specific breadcrumb
 */ export function addStreamingBreadcrumb(message, data, level = 'info') {
    Sentry.addBreadcrumb({
        category: 'streaming',
        message,
        data,
        level
    });
}
/**
 * Capture streaming error with context
 */ export function captureStreamingError(error, extra) {
    const errorObj = typeof error === 'string' ? new Error(error) : error;
    Sentry.captureException(errorObj, {
        tags: {
            error_category: 'streaming'
        },
        extra
    });
}
/**
 * Update connection context for server-side tracking
 */ export function updateServerContext(context) {
    Sentry.setContext('server_state', {
        active_connections: context.activeConnections,
        active_streams: context.activeStreams,
        transcode_jobs: context.transcodeJobsActive,
        timestamp: Date.now()
    });
}

//# sourceMappingURL=sentryStreamingContext.js.map