@dxos/tracing 0.6.7 → 0.6.8-main.3be982f
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/dist/lib/browser/index.mjs +68 -15
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +66 -15
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/api.d.ts +4 -2
- package/dist/types/src/api.d.ts.map +1 -1
- package/dist/types/src/diagnostics-channel.d.ts +3 -2
- package/dist/types/src/diagnostics-channel.d.ts.map +1 -1
- package/dist/types/src/trace-processor.d.ts.map +1 -1
- package/dist/types/src/weak-ref.d.ts +2 -0
- package/dist/types/src/weak-ref.d.ts.map +1 -0
- package/package.json +11 -11
- package/src/diagnostics-channel.ts +20 -10
- package/src/trace-processor.ts +13 -4
- package/src/weak-ref.ts +18 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace-processor.d.ts","sourceRoot":"","sources":["../../../src/trace-processor.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,4CAA4C,CAAC;AAC3E,OAAO,EAAE,KAAK,KAAK,IAAI,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,KAAK,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAG3F,OAAO,KAAK,EAAE,cAAc,EAAa,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM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,EAAE,cAAc,EACvC,MAAM,EAAE,eAAe;IAuBzB,IAAI,IAAI,WAGP;IAED,IAAI,GAAG,IAAI,OAAO,GAAG,IAAI,CAExB;IAED,WAAW;IASX,SAAS,CAAC,GAAG,EAAE,OAAO;IAUtB,SAAS,IAAI,IAAI;IAYjB,OAAO,CAAC,sBAAsB;CAK/B;AAiBD,eAAO,MAAM,eAAe,EAAE,cAA+E,CAAC;AAsE9G,eAAO,MAAM,iBAAiB,cAAe,MAAM,WAQlD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weak-ref.d.ts","sourceRoot":"","sources":["../../../src/weak-ref.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,OAAO,oBAAoC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/tracing",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8-main.3be982f",
|
|
4
4
|
"description": "Async utilities.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
"src"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@dxos/async": "0.6.
|
|
28
|
-
"@dxos/codec-protobuf": "0.6.
|
|
29
|
-
"@dxos/
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/log": "0.6.
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/util": "0.6.
|
|
27
|
+
"@dxos/async": "0.6.8-main.3be982f",
|
|
28
|
+
"@dxos/codec-protobuf": "0.6.8-main.3be982f",
|
|
29
|
+
"@dxos/debug": "0.6.8-main.3be982f",
|
|
30
|
+
"@dxos/context": "0.6.8-main.3be982f",
|
|
31
|
+
"@dxos/invariant": "0.6.8-main.3be982f",
|
|
32
|
+
"@dxos/log": "0.6.8-main.3be982f",
|
|
33
|
+
"@dxos/node-std": "0.6.8-main.3be982f",
|
|
34
|
+
"@dxos/protocols": "0.6.8-main.3be982f",
|
|
35
|
+
"@dxos/util": "0.6.8-main.3be982f"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@dxos/test": "0.6.
|
|
38
|
+
"@dxos/test": "0.6.8-main.3be982f"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { Trigger, sleep } from '@dxos/async';
|
|
6
6
|
import { Context } from '@dxos/context';
|
|
7
|
+
import { invariant } from '@dxos/invariant';
|
|
7
8
|
|
|
8
9
|
import {
|
|
9
10
|
DIAGNOSTICS_TIMEOUT,
|
|
@@ -38,21 +39,27 @@ export type DiagnosticChannelMessage =
|
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
export class DiagnosticsChannel {
|
|
42
|
+
static get supported() {
|
|
43
|
+
return globalThis.BroadcastChannel != null;
|
|
44
|
+
}
|
|
45
|
+
|
|
41
46
|
private _ctx = new Context();
|
|
42
47
|
|
|
43
48
|
// Separate channels becauase the client and server may be in the same process.
|
|
44
|
-
private readonly _serveChannel
|
|
45
|
-
private readonly _clientChannel
|
|
49
|
+
private readonly _serveChannel?: BroadcastChannel = undefined;
|
|
50
|
+
private readonly _clientChannel?: BroadcastChannel = undefined;
|
|
46
51
|
|
|
47
52
|
constructor(private readonly _channelName: string = DEFAULT_CHANNEL_NAME) {
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
if (DiagnosticsChannel.supported) {
|
|
54
|
+
this._serveChannel = new BroadcastChannel(_channelName);
|
|
55
|
+
this._clientChannel = new BroadcastChannel(_channelName);
|
|
56
|
+
}
|
|
50
57
|
}
|
|
51
58
|
|
|
52
59
|
destroy() {
|
|
53
60
|
void this._ctx.dispose();
|
|
54
|
-
this._serveChannel
|
|
55
|
-
this._clientChannel
|
|
61
|
+
this._serveChannel?.close();
|
|
62
|
+
this._clientChannel?.close();
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
/**
|
|
@@ -61,18 +68,19 @@ export class DiagnosticsChannel {
|
|
|
61
68
|
* Noop in the browser.
|
|
62
69
|
*/
|
|
63
70
|
unref() {
|
|
64
|
-
if (typeof (this._serveChannel as any).unref === 'function') {
|
|
71
|
+
if (this._serveChannel && typeof (this._serveChannel as any).unref === 'function') {
|
|
65
72
|
(this._serveChannel as any).unref();
|
|
66
73
|
(this._clientChannel as any).unref();
|
|
67
74
|
}
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
serve(manager: DiagnosticsManager) {
|
|
78
|
+
invariant(this._serveChannel);
|
|
71
79
|
const listener = async (event: MessageEvent) => {
|
|
72
80
|
switch (event.data.type) {
|
|
73
81
|
case 'DIAGNOSTICS_DISCOVER': {
|
|
74
82
|
const diagnostics = manager.list();
|
|
75
|
-
this._serveChannel
|
|
83
|
+
this._serveChannel!.postMessage({
|
|
76
84
|
type: 'DIAGNOSTICS_ANNOUNCE',
|
|
77
85
|
diagnostics,
|
|
78
86
|
} satisfies DiagnosticChannelMessage);
|
|
@@ -88,7 +96,7 @@ export class DiagnosticsChannel {
|
|
|
88
96
|
}
|
|
89
97
|
|
|
90
98
|
const data = await manager.fetch(request);
|
|
91
|
-
this._serveChannel
|
|
99
|
+
this._serveChannel!.postMessage({
|
|
92
100
|
type: 'DIAGNOSTICS_RESPONSE',
|
|
93
101
|
requestId,
|
|
94
102
|
data,
|
|
@@ -99,10 +107,11 @@ export class DiagnosticsChannel {
|
|
|
99
107
|
};
|
|
100
108
|
|
|
101
109
|
this._serveChannel.addEventListener('message', listener);
|
|
102
|
-
this._ctx.onDispose(() => this._serveChannel
|
|
110
|
+
this._ctx.onDispose(() => this._serveChannel!.removeEventListener('message', listener));
|
|
103
111
|
}
|
|
104
112
|
|
|
105
113
|
async discover(): Promise<DiagnosticMetadata[]> {
|
|
114
|
+
invariant(this._clientChannel);
|
|
106
115
|
const diagnostics: DiagnosticMetadata[] = [];
|
|
107
116
|
|
|
108
117
|
const collector = (event: MessageEvent) => {
|
|
@@ -135,6 +144,7 @@ export class DiagnosticsChannel {
|
|
|
135
144
|
}
|
|
136
145
|
|
|
137
146
|
async fetch(request: DiagnosticsRequest): Promise<DiagnosticsData> {
|
|
147
|
+
invariant(this._clientChannel);
|
|
138
148
|
const requestId = createId();
|
|
139
149
|
|
|
140
150
|
const trigger = new Trigger<DiagnosticsData>();
|
package/src/trace-processor.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { type BaseCounter } from './metrics';
|
|
|
17
17
|
import { RemoteMetrics, RemoteTracing } from './remote';
|
|
18
18
|
import { TRACE_SPAN_ATTRIBUTE, getTracingContext } from './symbols';
|
|
19
19
|
import { TraceSender } from './trace-sender';
|
|
20
|
+
import { WeakRef } from './weak-ref';
|
|
20
21
|
|
|
21
22
|
export type Diagnostics = {
|
|
22
23
|
resources: Record<string, Resource>;
|
|
@@ -77,6 +78,8 @@ const REFRESH_INTERVAL = 1_000;
|
|
|
77
78
|
|
|
78
79
|
const MAX_INFO_OBJECT_DEPTH = 8;
|
|
79
80
|
|
|
81
|
+
const IS_CLOUDFLARE_WORKERS = !!globalThis?.navigator?.userAgent?.includes('Cloudflare-Workers');
|
|
82
|
+
|
|
80
83
|
export class TraceProcessor {
|
|
81
84
|
public readonly diagnostics = new DiagnosticsManager();
|
|
82
85
|
public readonly diagnosticsChannel = new DiagnosticsChannel();
|
|
@@ -99,10 +102,14 @@ export class TraceProcessor {
|
|
|
99
102
|
constructor() {
|
|
100
103
|
log.addProcessor(this._logProcessor.bind(this));
|
|
101
104
|
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
if (!IS_CLOUDFLARE_WORKERS) {
|
|
106
|
+
const refreshInterval = setInterval(this.refresh.bind(this), REFRESH_INTERVAL);
|
|
107
|
+
unrefTimeout(refreshInterval);
|
|
108
|
+
}
|
|
104
109
|
|
|
105
|
-
|
|
110
|
+
if (DiagnosticsChannel.supported) {
|
|
111
|
+
this.diagnosticsChannel.serve(this.diagnostics);
|
|
112
|
+
}
|
|
106
113
|
this.diagnosticsChannel.unref();
|
|
107
114
|
}
|
|
108
115
|
|
|
@@ -438,7 +445,9 @@ export class TracingSpan {
|
|
|
438
445
|
}
|
|
439
446
|
|
|
440
447
|
private _markInBrowserTimeline() {
|
|
441
|
-
performance
|
|
448
|
+
if (typeof globalThis?.performance?.measure === 'function') {
|
|
449
|
+
performance.measure(this.name, { start: this.startTs, end: this.endTs! });
|
|
450
|
+
}
|
|
442
451
|
}
|
|
443
452
|
}
|
|
444
453
|
|
package/src/weak-ref.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Workerd does not support WeakRef
|
|
2
|
+
|
|
3
|
+
//
|
|
4
|
+
// Copyright 2024 DXOS.org
|
|
5
|
+
//
|
|
6
|
+
|
|
7
|
+
class WeakRefMock<T> {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
9
|
+
constructor(target: T) {
|
|
10
|
+
// do nothing
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
deref(): T | undefined {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const WeakRef = globalThis.WeakRef ?? WeakRefMock;
|