@ohos-ports/dxos-tracing 0.11.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +105 -0
- package/README.md +3 -0
- package/dist/lib/index.mjs +509 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/types/src/api.d.ts +47 -0
- package/dist/types/src/api.d.ts.map +1 -0
- package/dist/types/src/buffering-backend.d.ts +24 -0
- package/dist/types/src/buffering-backend.d.ts.map +1 -0
- package/dist/types/src/diagnostic.d.ts +38 -0
- package/dist/types/src/diagnostic.d.ts.map +1 -0
- package/dist/types/src/diagnostics-channel.d.ts +34 -0
- package/dist/types/src/diagnostics-channel.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +7 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/remote/index.d.ts +2 -0
- package/dist/types/src/remote/index.d.ts.map +1 -0
- package/dist/types/src/remote/metrics.d.ts +37 -0
- package/dist/types/src/remote/metrics.d.ts.map +1 -0
- package/dist/types/src/trace-processor.d.ts +29 -0
- package/dist/types/src/trace-processor.d.ts.map +1 -0
- package/dist/types/src/tracing-types.d.ts +67 -0
- package/dist/types/src/tracing-types.d.ts.map +1 -0
- package/dist/types/src/tracing.test.d.ts +2 -0
- package/dist/types/src/tracing.test.d.ts.map +1 -0
- package/dist/types/src/util.d.ts +2 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +42 -0
- package/src/api.ts +204 -0
- package/src/buffering-backend.ts +112 -0
- package/src/diagnostic.ts +103 -0
- package/src/diagnostics-channel.ts +174 -0
- package/src/index.ts +25 -0
- package/src/remote/index.ts +5 -0
- package/src/remote/metrics.ts +57 -0
- package/src/trace-processor.ts +82 -0
- package/src/tracing-types.ts +77 -0
- package/src/tracing.test.ts +296 -0
- package/src/util.ts +6 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Context } from '@dxos/context';
|
|
2
|
+
import { type MaybePromise } from '@dxos/util';
|
|
3
|
+
/** localStorage key that switches the browser OTEL sampler from 30% to 100%. */
|
|
4
|
+
export declare const TRACE_ALL_KEY = "dxos.debug.traceAll";
|
|
5
|
+
export type SpanOptions = {
|
|
6
|
+
showInBrowserTimeline?: boolean;
|
|
7
|
+
/** When false the span is not exported to remote OTLP collectors. Defaults to true. */
|
|
8
|
+
showInRemoteTracing?: boolean;
|
|
9
|
+
op?: string;
|
|
10
|
+
attributes?: Record<string, any>;
|
|
11
|
+
};
|
|
12
|
+
export type ManualSpanParams = {
|
|
13
|
+
id: string;
|
|
14
|
+
instance: any;
|
|
15
|
+
methodName: string;
|
|
16
|
+
parentCtx: Context | null;
|
|
17
|
+
showInBrowserTimeline?: boolean;
|
|
18
|
+
showInRemoteTracing?: boolean;
|
|
19
|
+
op?: string;
|
|
20
|
+
attributes?: Record<string, any>;
|
|
21
|
+
};
|
|
22
|
+
export type AddLinkOptions = {};
|
|
23
|
+
export type TraceDiagnosticProps<T> = {
|
|
24
|
+
/** Unique ID. */
|
|
25
|
+
id: string;
|
|
26
|
+
/**
|
|
27
|
+
* Human-readable name.
|
|
28
|
+
* @defaults Defaults to `id`
|
|
29
|
+
*/
|
|
30
|
+
name?: string;
|
|
31
|
+
/** Function that will be called to fetch the diagnostic data. */
|
|
32
|
+
fetch: () => MaybePromise<T>;
|
|
33
|
+
};
|
|
34
|
+
export interface TraceDiagnostic {
|
|
35
|
+
id: string;
|
|
36
|
+
unregister(): void;
|
|
37
|
+
}
|
|
38
|
+
export declare const trace: {
|
|
39
|
+
addLink: (parent: any, child: any, opts?: AddLinkOptions) => void;
|
|
40
|
+
diagnostic: <T>(params: TraceDiagnosticProps<T>) => TraceDiagnostic;
|
|
41
|
+
mark: (name: string) => void;
|
|
42
|
+
span: ({ showInBrowserTimeline, showInRemoteTracing, op, attributes }?: SpanOptions) => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any) => any>) => void;
|
|
43
|
+
spanStart: (params: ManualSpanParams) => Context | null;
|
|
44
|
+
spanEnd: (id: string) => void;
|
|
45
|
+
metrics: import(".").RemoteMetrics;
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAwB,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAK/C,gFAAgF;AAChF,eAAO,MAAM,aAAa,wBAAwB,CAAC;AAMnD,MAAM,MAAM,WAAW,GAAG;IACxB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,uFAAuF;IACvF,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC,CAAC;AA8DF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,GAAG,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC,CAAC;AAqEF,MAAM,MAAM,cAAc,GAAG,EAAE,CAAC;AAMhC,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI;IACpC,iBAAiB;IACjB,EAAE,EAAE,MAAM,CAAC;IAEX;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,iEAAiE;IACjE,KAAK,EAAE,MAAM,YAAY,CAAC,CAAC,CAAC,CAAC;CAC9B,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,IAAI,IAAI,CAAC;CACpB;AASD,eAAO,MAAM,KAAK;sBA9BO,GAAG,SAAS,GAAG,SAAQ,cAAc;iBA0B1C,CAAC,UAAU,oBAAoB,CAAC,CAAC,CAAC,KAAG,eAAe;iBAlLpD,MAAM;4EAiBwD,WAAW,cAClF,GAAG,eAAe,MAAM,cAAc,uBAAuB,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,CAAC;wBA4EpE,gBAAgB,KAAG,OAAO,GAAG,IAAI;kBA0CvC,MAAM;;CAsD1B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type TraceContextData } from '@dxos/context';
|
|
2
|
+
import type { RemoteSpan, StartSpanOptions, TracingBackend } from './tracing-types';
|
|
3
|
+
export declare const BUFFERED_PREFIX = "buffered-";
|
|
4
|
+
/**
|
|
5
|
+
* A {@link TracingBackend} that buffers span operations until a real backend
|
|
6
|
+
* registers. On {@link drain}, buffered spans are replayed in FIFO order with
|
|
7
|
+
* parent IDs translated from synthetic `buffered-*` traceparents to real OTEL
|
|
8
|
+
* IDs, preserving the trace hierarchy.
|
|
9
|
+
*/
|
|
10
|
+
export declare class BufferingTracingBackend implements TracingBackend {
|
|
11
|
+
#private;
|
|
12
|
+
startSpan(options: StartSpanOptions): RemoteSpan;
|
|
13
|
+
/** Discard all buffered spans without replaying them. */
|
|
14
|
+
clear(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Replay all buffered spans into {@link backend}.
|
|
17
|
+
*
|
|
18
|
+
* @returns Map from synthetic buffered traceparent to real {@link TraceContextData},
|
|
19
|
+
* used by the post-drain translating wrapper to resolve stale buffered IDs
|
|
20
|
+
* still present on in-flight {@link Context} objects.
|
|
21
|
+
*/
|
|
22
|
+
drain(backend: TracingBackend): Map<string, TraceContextData>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=buffering-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffering-backend.d.ts","sourceRoot":"","sources":["../../../src/buffering-backend.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEpF,eAAO,MAAM,eAAe,cAAc,CAAC;AAuD3C;;;;;GAKG;AACH,qBAAa,uBAAwB,YAAW,cAAc;;IAI5D,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,UAAU,CAI/C;IAED,yDAAyD;IACzD,KAAK,IAAI,IAAI,CAEZ;IAED;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,EAAE,cAAc,GAAG,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAmB5D;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type TraceDiagnostic, type TraceDiagnosticProps } from './api';
|
|
2
|
+
export declare const DIAGNOSTICS_TIMEOUT = 10000;
|
|
3
|
+
export type DiagnosticMetadata = {
|
|
4
|
+
id: string;
|
|
5
|
+
instanceId: string;
|
|
6
|
+
instanceTag: string | null;
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
export type DiagnosticsRequest = {
|
|
10
|
+
id: string;
|
|
11
|
+
instanceId?: string;
|
|
12
|
+
instanceTag?: string | null;
|
|
13
|
+
};
|
|
14
|
+
export type DiagnosticsData = {
|
|
15
|
+
id: string;
|
|
16
|
+
instanceId: string;
|
|
17
|
+
data: any;
|
|
18
|
+
error?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare class TraceDiagnosticImpl implements TraceDiagnostic {
|
|
21
|
+
id: string;
|
|
22
|
+
fetch: () => any;
|
|
23
|
+
name: string;
|
|
24
|
+
private readonly _onUnregister;
|
|
25
|
+
constructor(id: string, fetch: () => any, name: string, _onUnregister: () => void);
|
|
26
|
+
unregister(): void;
|
|
27
|
+
}
|
|
28
|
+
export declare class DiagnosticsManager {
|
|
29
|
+
readonly instanceId: string;
|
|
30
|
+
readonly registry: Map<string, TraceDiagnosticImpl>;
|
|
31
|
+
private _instanceTag;
|
|
32
|
+
get instanceTag(): string | null;
|
|
33
|
+
setInstanceTag(tag: string): void;
|
|
34
|
+
registerDiagnostic(params: TraceDiagnosticProps<any>): TraceDiagnostic;
|
|
35
|
+
list(): DiagnosticMetadata[];
|
|
36
|
+
fetch(request: DiagnosticsRequest): Promise<DiagnosticsData>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=diagnostic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../../../src/diagnostic.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAGxE,eAAO,MAAM,mBAAmB,QAAS,CAAC;AAE1C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,qBAAa,mBAAoB,YAAW,eAAe;IAEhD,EAAE,EAAE,MAAM;IACV,KAAK,EAAE,MAAM,GAAG;IAChB,IAAI,EAAE,MAAM;IACnB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAJhC,YACS,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,GAAG,EAChB,IAAI,EAAE,MAAM,EACF,aAAa,EAAE,MAAM,IAAI,EACxC;IAEJ,UAAU,IAAI,IAAI,CAEjB;CACF;AAED,qBAAa,kBAAkB;IAC7B,QAAQ,CAAC,UAAU,SAAc;IAEjC,QAAQ,CAAC,QAAQ,mCAA0C;IAE3D,OAAO,CAAC,YAAY,CAAuB;IAE3C,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAE/B;IAED,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEhC;IAED,kBAAkB,CAAC,MAAM,EAAE,oBAAoB,CAAC,GAAG,CAAC,GAAG,eAAe,CAQrE;IAED,IAAI,IAAI,kBAAkB,EAAE,CAO3B;IAEK,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,CAsBjE;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type DiagnosticMetadata, type DiagnosticsData, type DiagnosticsManager, type DiagnosticsRequest } from './diagnostic';
|
|
2
|
+
export type DiagnosticChannelMessage = {
|
|
3
|
+
type: 'DIAGNOSTICS_DISCOVER';
|
|
4
|
+
} | {
|
|
5
|
+
type: 'DIAGNOSTICS_ANNOUNCE';
|
|
6
|
+
diagnostics: DiagnosticMetadata[];
|
|
7
|
+
} | {
|
|
8
|
+
type: 'DIAGNOSTICS_FETCH';
|
|
9
|
+
requestId: string;
|
|
10
|
+
request: DiagnosticsRequest;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'DIAGNOSTICS_RESPONSE';
|
|
13
|
+
requestId: string;
|
|
14
|
+
data: DiagnosticsData;
|
|
15
|
+
};
|
|
16
|
+
export declare class DiagnosticsChannel {
|
|
17
|
+
private readonly _channelName;
|
|
18
|
+
static get supported(): boolean;
|
|
19
|
+
private _ctx;
|
|
20
|
+
private readonly _serveChannel?;
|
|
21
|
+
private readonly _clientChannel?;
|
|
22
|
+
constructor(_channelName?: string);
|
|
23
|
+
destroy(): void;
|
|
24
|
+
/**
|
|
25
|
+
* In node.js, the channel will keep the process alive.
|
|
26
|
+
* This method allows the process to exit.
|
|
27
|
+
* Noop in the browser.
|
|
28
|
+
*/
|
|
29
|
+
unref(): void;
|
|
30
|
+
serve(manager: DiagnosticsManager): void;
|
|
31
|
+
discover(): Promise<DiagnosticMetadata[]>;
|
|
32
|
+
fetch(request: DiagnosticsRequest): Promise<DiagnosticsData>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=diagnostics-channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics-channel.d.ts","sourceRoot":"","sources":["../../../src/diagnostics-channel.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,kBAAkB,EAEvB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;AAOtB,MAAM,MAAM,wBAAwB,GAChC;IACE,IAAI,EAAE,sBAAsB,CAAC;CAC9B,GACD;IACE,IAAI,EAAE,sBAAsB,CAAC;IAC7B,WAAW,EAAE,kBAAkB,EAAE,CAAC;CACnC,GACD;IACE,IAAI,EAAE,mBAAmB,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,kBAAkB,CAAC;CAC7B,GACD;IACE,IAAI,EAAE,sBAAsB,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,eAAe,CAAC;CACvB,CAAC;AAEN,qBAAa,kBAAkB;IAWjB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAVzC,MAAM,KAAK,SAAS,YAEnB;IAED,OAAO,CAAC,IAAI,CAAiB;IAG7B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAA+B;IAC9D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAA+B;IAE/D,YAA6B,YAAY,GAAE,MAA6B,EAKvE;IAED,OAAO,IAAI,IAAI,CAId;IAED;;;;OAIG;IACH,KAAK,IAAI,IAAI,CAKZ;IAED,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAkCvC;IAEK,QAAQ,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC,CA+B9C;IAEK,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,CA2BjE;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAMA,cAAc,OAAO,CAAC;AACtB,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/remote/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
type TagType = number | string | boolean | null | undefined;
|
|
2
|
+
export interface MetricData {
|
|
3
|
+
unit?: string;
|
|
4
|
+
tags?: Record<string, TagType>;
|
|
5
|
+
timestamp?: number;
|
|
6
|
+
}
|
|
7
|
+
interface MetricsMethods {
|
|
8
|
+
/**
|
|
9
|
+
* Adds a value to a counter metric
|
|
10
|
+
*/
|
|
11
|
+
increment(name: string, value?: number, data?: MetricData): void;
|
|
12
|
+
/**
|
|
13
|
+
* Adds a value to a distribution metric
|
|
14
|
+
*/
|
|
15
|
+
distribution(name: string, value: number, data?: MetricData): void;
|
|
16
|
+
/**
|
|
17
|
+
* Adds a value to a set metric. Value must be a string or integer.
|
|
18
|
+
*/
|
|
19
|
+
set(name: string, value: number | string, data?: MetricData): void;
|
|
20
|
+
/**
|
|
21
|
+
* Adds a value to a gauge metric
|
|
22
|
+
*/
|
|
23
|
+
gauge(name: string, value: number, data?: MetricData): void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Allows metrics to be recorded within SDK code without requiring specific consumers.
|
|
27
|
+
*/
|
|
28
|
+
export declare class RemoteMetrics implements MetricsMethods {
|
|
29
|
+
private _metrics;
|
|
30
|
+
registerProcessor(processor: MetricsMethods): void;
|
|
31
|
+
increment(name: string, value?: number, data?: MetricData): void[];
|
|
32
|
+
distribution(name: string, value: number, data?: MetricData): void[];
|
|
33
|
+
set(name: string, value: number | string, data?: MetricData): void[];
|
|
34
|
+
gauge(name: string, value: number, data?: MetricData): void[];
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../../src/remote/metrics.ts"],"names":[],"mappings":"AAIA,KAAK,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAE5D,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,cAAc;IACtB;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IACjE;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IACnE;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IACnE;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;CAC7D;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,cAAc;IAClD,OAAO,CAAC,QAAQ,CAA6B;IAE7C,iBAAiB,CAAC,SAAS,EAAE,cAAc,GAAG,IAAI,CAEjD;IAED,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,EAAE,CAEjE;IAED,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,EAAE,CAEnE;IAED,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,EAAE,CAEnE;IAED,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,EAAE,CAE5D;CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AddLinkOptions } from './api';
|
|
2
|
+
import { DiagnosticsManager } from './diagnostic';
|
|
3
|
+
import { DiagnosticsChannel } from './diagnostics-channel';
|
|
4
|
+
import { RemoteMetrics } from './remote/metrics';
|
|
5
|
+
import type { TracingBackend } from './tracing-types';
|
|
6
|
+
export declare class TraceProcessor {
|
|
7
|
+
#private;
|
|
8
|
+
readonly diagnostics: DiagnosticsManager;
|
|
9
|
+
readonly diagnosticsChannel: DiagnosticsChannel;
|
|
10
|
+
readonly remoteMetrics: RemoteMetrics;
|
|
11
|
+
/**
|
|
12
|
+
* Tracing backend. Initially a buffering backend that records spans;
|
|
13
|
+
* once the observability package sets a real backend, the buffer is drained
|
|
14
|
+
* and a thin translating wrapper is installed that resolves stale buffered
|
|
15
|
+
* parent IDs still held by in-flight {@link Context} objects.
|
|
16
|
+
*
|
|
17
|
+
* The wrapper only allocates when a `buffered-*` parent is actually encountered;
|
|
18
|
+
* the common path is a single `startsWith` check and direct passthrough.
|
|
19
|
+
*/
|
|
20
|
+
get tracingBackend(): TracingBackend;
|
|
21
|
+
set tracingBackend(backend: TracingBackend | undefined);
|
|
22
|
+
private _instanceTag;
|
|
23
|
+
constructor();
|
|
24
|
+
setInstanceTag(tag: string): void;
|
|
25
|
+
addLink(parent: any, child: any, opts: AddLinkOptions): void;
|
|
26
|
+
}
|
|
27
|
+
export declare const TRACE_PROCESSOR: TraceProcessor;
|
|
28
|
+
export declare const sanitizeClassName: (className: string) => string;
|
|
29
|
+
//# sourceMappingURL=trace-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-processor.d.ts","sourceRoot":"","sources":["../../../src/trace-processor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAgC,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEpF,qBAAa,cAAc;;IACzB,SAAgB,WAAW,qBAA4B;IACvD,SAAgB,kBAAkB,qBAA4B;IAC9D,SAAgB,aAAa,gBAAuB;IAKpD;;;;;;;;OAQG;IACH,IAAI,cAAc,IAAI,cAAc,CAEnC;IAED,IAAI,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,EAmBrD;IAED,OAAO,CAAC,YAAY,CAAuB;IAE3C,cAKC;IAED,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAGhC;IAGD,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAAG;CAChE;AAED,eAAO,MAAM,eAAe,EAAE,cAA+E,CAAC;AAE9G,eAAO,MAAM,iBAAiB,cAAe,MAAM,WAQlD,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type TraceContextData } from '@dxos/context';
|
|
2
|
+
/**
|
|
3
|
+
* Opaque span handle returned by {@link TracingBackend.startSpan}.
|
|
4
|
+
*
|
|
5
|
+
* The `spanContext` field carries W3C trace context strings that are stored
|
|
6
|
+
* on the DXOS {@link Context} via `TRACE_SPAN_ATTRIBUTE`. Because these are
|
|
7
|
+
* plain strings (not live runtime objects), they survive after the span ends
|
|
8
|
+
* and across serialization boundaries.
|
|
9
|
+
*/
|
|
10
|
+
export type RemoteSpan = {
|
|
11
|
+
/** Signal that the span has ended. Must be called exactly once. */
|
|
12
|
+
end: (endTime?: number) => void;
|
|
13
|
+
/** Record an error on the span (e.g., OTEL `span.recordException` + `setStatus`). */
|
|
14
|
+
setError?: (err: unknown) => void;
|
|
15
|
+
/**
|
|
16
|
+
* W3C trace context identifying this span.
|
|
17
|
+
*
|
|
18
|
+
* Stored on the DXOS `Context` attribute (`TRACE_SPAN_ATTRIBUTE`) so that
|
|
19
|
+
* child `@trace.span()` methods can read it and pass it as
|
|
20
|
+
* {@link StartSpanOptions.parentContext} to create properly-parented spans.
|
|
21
|
+
*/
|
|
22
|
+
spanContext?: TraceContextData;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Options passed to {@link TracingBackend.startSpan}.
|
|
26
|
+
*/
|
|
27
|
+
export type StartSpanOptions = {
|
|
28
|
+
/** Human-readable span name, typically `ClassName.methodName`. */
|
|
29
|
+
name: string;
|
|
30
|
+
/** Span category (e.g., `'function'`, `'rpc'`). */
|
|
31
|
+
op?: string;
|
|
32
|
+
/** Key-value attributes attached to the span. */
|
|
33
|
+
attributes?: Record<string, any>;
|
|
34
|
+
/**
|
|
35
|
+
* W3C trace context of the parent span.
|
|
36
|
+
*
|
|
37
|
+
* The backend extracts the trace/span IDs from these strings to establish
|
|
38
|
+
* parent-child relationships. When `undefined`, the backend creates a root span.
|
|
39
|
+
*/
|
|
40
|
+
parentContext?: TraceContextData;
|
|
41
|
+
/**
|
|
42
|
+
* Epoch-millisecond timestamp for the span start.
|
|
43
|
+
* Used by the buffering backend to preserve original timing when replaying spans.
|
|
44
|
+
* When `undefined`, the backend uses the current time.
|
|
45
|
+
*/
|
|
46
|
+
startTime?: number;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Backend-agnostic tracing interface implemented by the observability package
|
|
50
|
+
* and registered on `TRACE_PROCESSOR.tracingBackend`.
|
|
51
|
+
*
|
|
52
|
+
* The backend receives and returns {@link TraceContextData} (W3C strings) —
|
|
53
|
+
* no opaque runtime objects cross the interface boundary. The OTEL backend
|
|
54
|
+
* performs `propagation.extract/inject` internally in {@link startSpan}.
|
|
55
|
+
*/
|
|
56
|
+
export interface TracingBackend {
|
|
57
|
+
/**
|
|
58
|
+
* Create a new span.
|
|
59
|
+
*
|
|
60
|
+
* The backend should:
|
|
61
|
+
* 1. Extract the parent from `options.parentContext` (if present).
|
|
62
|
+
* 2. Create a span as a child of that parent.
|
|
63
|
+
* 3. Inject the new span's identity into the returned `spanContext`.
|
|
64
|
+
*/
|
|
65
|
+
startSpan: (options: StartSpanOptions) => RemoteSpan;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=tracing-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracing-types.d.ts","sourceRoot":"","sources":["../../../src/tracing-types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,mEAAmE;IACnE,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAEhC,qFAAqF;IACrF,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IAElC;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;CAChC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,iDAAiD;IACjD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEjC;;;;;OAKG;IACH,aAAa,CAAC,EAAE,gBAAgB,CAAC;IAEjC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;;OAOG;IACH,SAAS,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,UAAU,CAAC;CACtD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracing.test.d.ts","sourceRoot":"","sources":["../../../src/tracing.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ,cAA4C,CAAC"}
|