export interface TracingInitOptions { serviceName?: string; serviceVersion?: string; } export interface ResourcesProvider { /** 提供服务初始化时注册的信息,如用户信息等 */ provide(): Promise; } export interface Trace { get traceId(): string; /** 开始一个全新的链路追踪,返回整个链路的根结点 */ startSpan(name: string, options?: SpanOptions): RootSpan; } export type RootSpan = Span; export type Attributes = Record; export interface Span { /** 获取 traceId */ get traceId(): string; /** 获取 span 相关的信息用于 http 请求头 */ get requestHeaders(): Record; /** 开始一个子链路 */ startSpan(name: string, options?: SpanOptions): Span; /** 设置当前 span 状态为 UNSET 并且结束追踪 */ markAsUnset(time?: TimeInput): void; /** 设置当前 span 状态为 FAILED 并且结束追踪 */ markAsFailed(exception?: Exception, time?: TimeInput): void; /** 设置当前 span 状态为 SUCCESSFUL 并且结束追踪 */ markAsSuccessful(time?: TimeInput): void; /** 设置当前 span 的 traceId */ setTraceId(traceId: string): void; /** 在当前 span 的关键链路上添加一个事件标记 */ addEvent(name: string, attributes?: Attributes): void; /** 为当前链路添加属性 */ setAttributes(attributes: Attributes): void; /** 记录异常 */ recordException(exception: Exception, time?: TimeInput): void; } interface ExceptionWithCode { code: string | number; name?: string; message?: string; stack?: string; } interface ExceptionWithMessage { code?: string | number; message: string; name?: string; stack?: string; } interface ExceptionWithName { code?: string | number; message?: string; name: string; stack?: string; } /** * Defines Exception. * * string or an object with one of (message or name or code) and optional stack */ export declare type Exception = ExceptionWithCode | ExceptionWithMessage | ExceptionWithName | string; export declare type HrTime = [number, number]; /** * Defines TimeInput. * * hrtime, epoch milliseconds, performance.now() or Date */ export declare type TimeInput = HrTime | number | Date; export interface SpanOptions { attributes?: Attributes; startTime?: TimeInput; } export {}; //# sourceMappingURL=tracing.d.ts.map