@beignet/devtools 0.0.3 → 0.0.5
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/CHANGELOG.md +81 -0
- package/README.md +116 -71
- package/dist/events.d.ts +15 -3
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +1 -0
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +13 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -13
- package/dist/index.js.map +1 -1
- package/dist/persistence.d.ts +1 -1
- package/dist/persistence.d.ts.map +1 -1
- package/dist/provider-instrumentation.d.ts +1 -1
- package/dist/provider-instrumentation.d.ts.map +1 -1
- package/dist/provider.d.ts +5 -5
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +10 -5
- package/dist/provider.js.map +1 -1
- package/dist/redaction.d.ts +1 -1
- package/dist/redaction.d.ts.map +1 -1
- package/dist/redaction.js +1 -0
- package/dist/redaction.js.map +1 -1
- package/dist/routes.d.ts +2 -2
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +3 -3
- package/dist/routes.js.map +1 -1
- package/dist/ui-model.d.ts +38 -0
- package/dist/ui-model.d.ts.map +1 -0
- package/dist/ui-model.js +1039 -0
- package/dist/ui-model.js.map +1 -0
- package/dist/ui.d.ts +1 -1
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +310 -164
- package/dist/ui.js.map +1 -1
- package/dist/watchers.d.ts +2 -2
- package/dist/watchers.d.ts.map +1 -1
- package/dist/watchers.js +10 -2
- package/dist/watchers.js.map +1 -1
- package/package.json +22 -2
- package/src/events.ts +25 -1
- package/src/index.ts +13 -15
- package/src/persistence.ts +1 -1
- package/src/provider-instrumentation.ts +1 -1
- package/src/provider.ts +12 -7
- package/src/redaction.ts +2 -1
- package/src/routes.ts +4 -4
- package/src/ui-model.ts +1233 -0
- package/src/ui.ts +310 -164
- package/src/watchers.ts +12 -3
- package/dist/audit.d.ts +0 -31
- package/dist/audit.d.ts.map +0 -1
- package/dist/audit.js +0 -55
- package/dist/audit.js.map +0 -1
- package/dist/instrumentation.d.ts +0 -114
- package/dist/instrumentation.d.ts.map +0 -1
- package/dist/instrumentation.js +0 -303
- package/dist/instrumentation.js.map +0 -1
- package/dist/trace-context.d.ts +0 -80
- package/dist/trace-context.d.ts.map +0 -1
- package/dist/trace-context.js +0 -92
- package/dist/trace-context.js.map +0 -1
- package/src/audit.ts +0 -92
- package/src/instrumentation.ts +0 -491
- package/src/trace-context.ts +0 -166
package/src/trace-context.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
const TRACEPARENT_PATTERN = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Devtools trace context used to correlate related events.
|
|
5
|
-
*/
|
|
6
|
-
export interface DevtoolsTraceContext {
|
|
7
|
-
/**
|
|
8
|
-
* W3C trace ID.
|
|
9
|
-
*/
|
|
10
|
-
traceId: string;
|
|
11
|
-
/**
|
|
12
|
-
* Current span ID.
|
|
13
|
-
*/
|
|
14
|
-
spanId: string;
|
|
15
|
-
/**
|
|
16
|
-
* Parent span ID when available.
|
|
17
|
-
*/
|
|
18
|
-
parentSpanId?: string;
|
|
19
|
-
/**
|
|
20
|
-
* W3C traceparent header value.
|
|
21
|
-
*/
|
|
22
|
-
traceparent: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Parsed W3C traceparent header.
|
|
27
|
-
*/
|
|
28
|
-
export interface ParsedTraceparent {
|
|
29
|
-
/**
|
|
30
|
-
* W3C trace ID.
|
|
31
|
-
*/
|
|
32
|
-
traceId: string;
|
|
33
|
-
/**
|
|
34
|
-
* Span ID from the traceparent header.
|
|
35
|
-
*/
|
|
36
|
-
spanId: string;
|
|
37
|
-
/**
|
|
38
|
-
* Trace flags from the traceparent header.
|
|
39
|
-
*/
|
|
40
|
-
traceFlags: string;
|
|
41
|
-
/**
|
|
42
|
-
* Normalized traceparent header value.
|
|
43
|
-
*/
|
|
44
|
-
traceparent: string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Input accepted when creating devtools trace context.
|
|
49
|
-
*/
|
|
50
|
-
export interface DevtoolsTraceContextInput {
|
|
51
|
-
traceId?: string;
|
|
52
|
-
spanId?: string;
|
|
53
|
-
parentSpanId?: string;
|
|
54
|
-
traceparent?: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function createHexId(length: number): string {
|
|
58
|
-
const bytes = new Uint8Array(length / 2);
|
|
59
|
-
if (typeof crypto !== "undefined" && "getRandomValues" in crypto) {
|
|
60
|
-
crypto.getRandomValues(bytes);
|
|
61
|
-
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join(
|
|
62
|
-
"",
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
let value = "";
|
|
67
|
-
while (value.length < length) {
|
|
68
|
-
value += Math.floor(Math.random() * 16).toString(16);
|
|
69
|
-
}
|
|
70
|
-
return value.slice(0, length);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function isNonZeroHex(value: string): boolean {
|
|
74
|
-
return !/^0+$/.test(value);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Create a non-zero W3C trace ID.
|
|
79
|
-
*/
|
|
80
|
-
export function createTraceId(): string {
|
|
81
|
-
let traceId = createHexId(32);
|
|
82
|
-
while (!isNonZeroHex(traceId)) {
|
|
83
|
-
traceId = createHexId(32);
|
|
84
|
-
}
|
|
85
|
-
return traceId;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Create a non-zero W3C span ID.
|
|
90
|
-
*/
|
|
91
|
-
export function createSpanId(): string {
|
|
92
|
-
let spanId = createHexId(16);
|
|
93
|
-
while (!isNonZeroHex(spanId)) {
|
|
94
|
-
spanId = createHexId(16);
|
|
95
|
-
}
|
|
96
|
-
return spanId;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Create a W3C traceparent header value.
|
|
101
|
-
*/
|
|
102
|
-
export function createTraceparent(args: {
|
|
103
|
-
traceId: string;
|
|
104
|
-
spanId: string;
|
|
105
|
-
traceFlags?: string;
|
|
106
|
-
}): string {
|
|
107
|
-
return `00-${args.traceId}-${args.spanId}-${args.traceFlags ?? "01"}`;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Parse and validate a W3C traceparent header value.
|
|
112
|
-
*/
|
|
113
|
-
export function parseTraceparent(
|
|
114
|
-
value: string | null | undefined,
|
|
115
|
-
): ParsedTraceparent | undefined {
|
|
116
|
-
if (!value) return undefined;
|
|
117
|
-
const normalized = value.trim().toLowerCase();
|
|
118
|
-
const match = TRACEPARENT_PATTERN.exec(normalized);
|
|
119
|
-
if (!match) return undefined;
|
|
120
|
-
|
|
121
|
-
const [, traceId, spanId, traceFlags] = match;
|
|
122
|
-
if (!isNonZeroHex(traceId) || !isNonZeroHex(spanId)) return undefined;
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
traceId,
|
|
126
|
-
spanId,
|
|
127
|
-
traceFlags,
|
|
128
|
-
traceparent: normalized,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Create devtools trace context from explicit IDs or an existing traceparent.
|
|
134
|
-
*/
|
|
135
|
-
export function createDevtoolsTraceContext(
|
|
136
|
-
input: DevtoolsTraceContextInput = {},
|
|
137
|
-
): DevtoolsTraceContext {
|
|
138
|
-
const parsed = parseTraceparent(input.traceparent);
|
|
139
|
-
const traceId = input.traceId ?? parsed?.traceId ?? createTraceId();
|
|
140
|
-
const parentSpanId = input.parentSpanId ?? parsed?.spanId;
|
|
141
|
-
const spanId = input.spanId ?? createSpanId();
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
traceId,
|
|
145
|
-
spanId,
|
|
146
|
-
...(parentSpanId ? { parentSpanId } : {}),
|
|
147
|
-
traceparent: createTraceparent({
|
|
148
|
-
traceId,
|
|
149
|
-
spanId,
|
|
150
|
-
traceFlags: parsed?.traceFlags,
|
|
151
|
-
}),
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Create child trace context from a parent context.
|
|
157
|
-
*/
|
|
158
|
-
export function createChildDevtoolsTraceContext(
|
|
159
|
-
parent: DevtoolsTraceContextInput,
|
|
160
|
-
): DevtoolsTraceContext {
|
|
161
|
-
return createDevtoolsTraceContext({
|
|
162
|
-
traceId: parent.traceId,
|
|
163
|
-
parentSpanId: parent.spanId,
|
|
164
|
-
traceparent: parent.traceparent,
|
|
165
|
-
});
|
|
166
|
-
}
|