import type { RumConfiguration } from '../configuration/configuration'; import type { RumFetchResolveContext, RumFetchStartContext, RumXhrCompleteContext, RumXhrStartContext } from '../requestCollection'; import type { RumSessionManager } from '../rumSessionManager'; import type { Propagator, TracingOption } from './tracer.type'; export interface Tracer { traceFetch: (context: RumFetchStartContext) => void; traceXhr: (context: RumXhrStartContext, xhr: XMLHttpRequest) => void; clearTracingIfNeeded: (context: RumFetchResolveContext | RumXhrCompleteContext) => void; } export declare function isTracingOption(item: unknown): item is TracingOption; /** * Clear tracing information to avoid incomplete traces. Ideally, we should do it when the * request did not reach the server, but the browser does not expose this. So, we clear tracing * information if the request ended with status 0 without being aborted by the application. * * Reasoning: * * * Applications are usually aborting requests after a bit of time, for example when the user is * typing (autocompletion) or navigating away (in a SPA). With a performant device and good * network conditions, the request is likely to reach the server before being canceled. * * * Requests aborted otherwise (ex: lack of internet, CORS issue, blocked by a privacy extension) * are likely to finish quickly and without reaching the server. * * Of course, it might not be the case every time, but it should limit having incomplete traces a * bit. * */ /** * 清除trace信息,以免不完整的trace。 * 理想情况下,我们应在请求未到达服务器时清除trace信息,但浏览器没有提供这个能力。 * 因此,我们在请求以状态0结束,且未被应用程序中止的情况下,清除trace信息。 * * 理由: * * * 应用程序经常会在短时间内中止请求,例如在用户输入(自动补全)或路由变化(在SPA中)时。 * 在性能良好的设备和良好的网络条件下,请求大概率会在被取消之前到达服务器。 * * * 其他情况下(例如:网络不好、CORS问题、被隐私扩展阻止),请求可能会快速结束且不会到达服务器。 * * 当然,这并不是每次都适用,但应该可以减少不完整trace的情况。 */ export declare function clearTracingIfNeeded(context: RumFetchResolveContext | RumXhrCompleteContext): void; export declare function startTracer(configuration: RumConfiguration, sessionManager: RumSessionManager): Tracer; export declare function isTracingSupported(): boolean; export declare function getCrypto(): Crypto; export interface TraceIdentifier { toPaddedBase36: () => string; toPaddedHexadecimalString: () => string; toDoublePaddedHexadecimalString: () => string; } export declare function createTraceIdentifier(): TraceIdentifier; export declare function getSpanName(method: string, url: string): string; export declare function getSkywalkingHeaderKey(propagator: Propagator): string; export declare function getSkywalkingHeaderValue(traceId: TraceIdentifier, segmentId: TraceIdentifier, service: string, spanName: string): string; export declare function getTraceparentHeaderValue(traceId: TraceIdentifier, spanId: TraceIdentifier): string;