fix(routing): Round latency to integer for telemetry (#9242)

This commit is contained in:
Abhi
2025-09-23 17:29:12 -04:00
committed by GitHub
parent f795255e58
commit c12b87ed03

View File

@@ -92,17 +92,18 @@ export class CompositeStrategy implements TerminalStrategy {
startTime: number,
): RoutingDecision {
const endTime = performance.now();
const totalLatency = endTime - startTime;
// Combine the source paths: composite_name/child_source (e.g. 'router/default')
const compositeSource = `${this.name}/${decision.metadata.source}`;
// Use the child's latency if it's a meaningful (non-zero) value,
// otherwise use the total time spent in the composite strategy.
const latency = decision.metadata.latencyMs || endTime - startTime;
return {
...decision,
metadata: {
...decision.metadata,
source: compositeSource,
latencyMs: decision.metadata.latencyMs || totalLatency,
latencyMs: Math.round(latency), // Round to ensure int for telemetry.
},
};
}