openlit
Version:
OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects
68 lines (67 loc) • 1.97 kB
TypeScript
/**
* Cross-Language Trace Comparison Utilities
*
* This module provides utilities to compare traces generated by Python and TypeScript
* OpenLIT SDKs to ensure consistency across implementations.
* Uses SemanticConvention keys so comparisons stay in sync with the SDK.
*/
import { Span } from '@opentelemetry/api';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
export interface NormalizedTrace {
spanName: string;
spanKind: string;
attributes: Record<string, any>;
events: Array<{
name: string;
attributes?: Record<string, any>;
}>;
status: {
code: string;
message?: string;
};
duration?: number;
}
export interface TraceComparisonResult {
match: boolean;
differences: string[];
pythonTrace?: NormalizedTrace;
typescriptTrace?: NormalizedTrace;
}
/**
* Normalize a TypeScript span to a comparable format
*/
export declare function normalizeTypeScriptSpan(span: ReadableSpan | Span): NormalizedTrace;
/**
* Compare two normalized traces
*/
export declare function compareTraces(pythonTrace: NormalizedTrace, typescriptTrace: NormalizedTrace): TraceComparisonResult;
/**
* Extract key metrics from a trace for comparison
*/
export declare function extractKeyMetrics(trace: NormalizedTrace): {
tokens: {
input: number;
output: number;
total: number;
};
cost: number;
model: string;
operation: string;
system: string;
};
/**
* Compare key metrics between Python and TypeScript traces
*/
export declare function compareMetrics(pythonTrace: NormalizedTrace, typescriptTrace: NormalizedTrace): {
match: boolean;
differences: string[];
};
/**
* Create a test helper that validates trace consistency
*/
export declare function createTraceValidator(providerName: string, expectedAttributes?: string[]): {
validateTrace: (trace: NormalizedTrace) => {
valid: boolean;
errors: string[];
};
};