Spaces:
Running
Running
File size: 1,555 Bytes
aa89cb5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import type { RuntimeDiagnosticEvent, RuntimeExecutionCorrelation } from './telemetry';
import type { SQLExecutionMetadata } from '../sql/core';
/** Does not spread metadata, parameters, rows, audit payloads or entity IDs. */
export function sqlDiagnosticEvent(metadata: SQLExecutionMetadata,
correlation?: RuntimeExecutionCorrelation): RuntimeDiagnosticEvent {
if (metadata.logMode !== 'masked') throw new Error('Telemetry requires safe SQL projection');
const nodes = (frames: readonly { kind: string; name: string; detail?: string }[] = []) =>
JSON.stringify(frames.map(frame => ({ kind: frame.kind, name: frame.name, detail: frame.detail ?? '' })));
return Object.freeze({ body: 'TeaQL SQL execution', correlation,
attributes: Object.freeze({
'teaql.trace_chain': nodes(metadata.traceChain),
'teaql.trace_path': nodes(metadata.tracePath),
'teaql.mutation_lineage': nodes(metadata.mutationLineage),
'teaql.intent.comment': metadata.comment ?? metadata.auditReason ?? '',
'teaql.intent.purpose': metadata.purpose ?? '',
'teaql.sql.debug': metadata.debugSQL,
'teaql.sql.log_mode': metadata.logMode,
'teaql.sql.operation': metadata.operation,
'teaql.sql.outcome': metadata.executionOutcome ?? 'unknown',
'teaql.sql.elapsed_us': metadata.elapsedMicros,
...(metadata.resultCount === undefined ? {} : { 'teaql.sql.result_count': metadata.resultCount }),
...(metadata.affectedRows === undefined ? {} : { 'teaql.sql.affected_rows': metadata.affectedRows }),
}) });
}
|