import type { HrTime } from '@opentelemetry/api'; import { LiveSpan, Span } from '../entities/span'; import { TokenUsage } from '../entities/trace_info'; /** * OpenTelemetry Typescript SDK uses a unique timestamp format `HrTime` to represent * timestamps. This function converts a timestamp in nanoseconds to an `HrTime` * Supports both number and BigInt for large timestamps * Ref: https://github.com/open-telemetry/opentelemetry-js/blob/a9fc600f2bd7dbf9345ec14e4421f1cc034f1f9c/api/src/common/Time.ts#L17-L30C13 * @param nanoseconds The timestamp in nanoseconds (number or BigInt) * @returns The timestamp in `HrTime` format */ export declare function convertNanoSecondsToHrTime(nanoseconds: number | bigint): HrTime; /** * Convert HrTime to nanoseconds as BigInt * @param hrTime HrTime tuple [seconds, nanoseconds] * @returns BigInt nanoseconds */ export declare function convertHrTimeToNanoSeconds(hrTime: HrTime): bigint; /** * Convert HrTime to milliseconds * @param hrTime HrTime tuple [seconds, nanoseconds] * @returns Milliseconds */ export declare function convertHrTimeToMs(hrTime: HrTime): number; /** * Convert a hex span ID to base64 format for JSON serialization * Following Python implementation: _encode_span_id_to_byte * @param spanId Hex string span ID (16 chars) * @returns Base64 encoded span ID */ export declare function encodeSpanIdToBase64(spanId: string): string; /** * Convert a hex span ID to base64 format for JSON serialization * Following Python implementation: _encode_trace_id_to_byte * @param spanId Hex string span ID (32 chars) * @returns Base64 encoded span ID */ export declare function encodeTraceIdToBase64(traceId: string): string; /** * Convert a base64 span ID back to hex format * Following Python implementation: _decode_id_from_byte * @param base64SpanId Base64 encoded span ID * @returns Hex string span ID */ export declare function decodeIdFromBase64(base64SpanId: string): string; /** * Deduplicate span names in the trace data by appending an index number to the span name. * * This is only applied when there are multiple spans with the same name. The span names * are modified in place to avoid unnecessary copying. * * Examples: * ["red", "red"] -> ["red_1", "red_2"] * ["red", "red", "blue"] -> ["red_1", "red_2", "blue"] * * @param spans A list of spans to deduplicate */ export declare function deduplicateSpanNamesInPlace(spans: LiveSpan[]): void; /** * Map function arguments to an object with parameter names as keys * @param func The function to extract parameter names from * @param args The arguments passed to the function * @returns Object mapping parameter names to argument values */ export declare function mapArgsToObject(func: Function, args: any[]): Record; /** * Aggregate token usage information from all spans in a trace. * * This function iterates through all spans and extracts token usage from the * SpanAttributeKey.TOKEN_USAGE attribute. It avoids double-counting token usage * when both parent and child spans have usage data (e.g., LangChain ChatOpenAI + OpenAI tracing). * * @param spans - Array of spans to aggregate usage from * @returns Aggregated token usage or null if no usage data exists */ export declare function aggregateUsageFromSpans(spans: Span[]): TokenUsage | null;