@superblocksteam/telemetry 2.0.105-next.0 → 2.0.105-next.1
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/browser/console-logging.d.ts +18 -0
- package/dist/browser/console-logging.d.ts.map +1 -0
- package/dist/browser/console-logging.js +32 -0
- package/dist/browser/console-logging.js.map +1 -0
- package/dist/browser/early-console-buffer.d.ts +39 -0
- package/dist/browser/early-console-buffer.d.ts.map +1 -0
- package/dist/browser/early-console-buffer.js +157 -0
- package/dist/browser/early-console-buffer.js.map +1 -0
- package/dist/browser/index.d.ts +7 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +22 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/init.d.ts +27 -3
- package/dist/browser/init.d.ts.map +1 -1
- package/dist/browser/init.js +159 -14
- package/dist/browser/init.js.map +1 -1
- package/dist/browser/instrumentations.d.ts +61 -0
- package/dist/browser/instrumentations.d.ts.map +1 -0
- package/dist/browser/instrumentations.js +74 -0
- package/dist/browser/instrumentations.js.map +1 -0
- package/dist/browser/logs.d.ts +52 -0
- package/dist/browser/logs.d.ts.map +1 -0
- package/dist/browser/logs.js +85 -0
- package/dist/browser/logs.js.map +1 -0
- package/dist/browser/metrics.d.ts +25 -0
- package/dist/browser/metrics.d.ts.map +1 -0
- package/dist/browser/metrics.js +37 -0
- package/dist/browser/metrics.js.map +1 -0
- package/dist/browser/sanitizer.d.ts +35 -0
- package/dist/browser/sanitizer.d.ts.map +1 -0
- package/dist/browser/sanitizer.js +211 -0
- package/dist/browser/sanitizer.js.map +1 -0
- package/dist/browser/traced-socket.d.ts +102 -0
- package/dist/browser/traced-socket.d.ts.map +1 -0
- package/dist/browser/traced-socket.js +186 -0
- package/dist/browser/traced-socket.js.map +1 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +1 -0
- package/dist/common/index.js.map +1 -1
- package/dist/common/traced-socket-types.d.ts +43 -0
- package/dist/common/traced-socket-types.d.ts.map +1 -0
- package/dist/common/traced-socket-types.js +17 -0
- package/dist/common/traced-socket-types.js.map +1 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist-esm/browser/console-logging.d.ts +18 -0
- package/dist-esm/browser/console-logging.d.ts.map +1 -0
- package/dist-esm/browser/console-logging.js +27 -0
- package/dist-esm/browser/console-logging.js.map +1 -0
- package/dist-esm/browser/early-console-buffer.d.ts +39 -0
- package/dist-esm/browser/early-console-buffer.d.ts.map +1 -0
- package/dist-esm/browser/early-console-buffer.js +155 -0
- package/dist-esm/browser/early-console-buffer.js.map +1 -0
- package/dist-esm/browser/index.d.ts +7 -0
- package/dist-esm/browser/index.d.ts.map +1 -1
- package/dist-esm/browser/index.js +7 -0
- package/dist-esm/browser/index.js.map +1 -1
- package/dist-esm/browser/init.d.ts +27 -3
- package/dist-esm/browser/init.d.ts.map +1 -1
- package/dist-esm/browser/init.js +161 -16
- package/dist-esm/browser/init.js.map +1 -1
- package/dist-esm/browser/instrumentations.d.ts +61 -0
- package/dist-esm/browser/instrumentations.d.ts.map +1 -0
- package/dist-esm/browser/instrumentations.js +70 -0
- package/dist-esm/browser/instrumentations.js.map +1 -0
- package/dist-esm/browser/logs.d.ts +52 -0
- package/dist-esm/browser/logs.d.ts.map +1 -0
- package/dist-esm/browser/logs.js +78 -0
- package/dist-esm/browser/logs.js.map +1 -0
- package/dist-esm/browser/metrics.d.ts +25 -0
- package/dist-esm/browser/metrics.d.ts.map +1 -0
- package/dist-esm/browser/metrics.js +34 -0
- package/dist-esm/browser/metrics.js.map +1 -0
- package/dist-esm/browser/sanitizer.d.ts +35 -0
- package/dist-esm/browser/sanitizer.d.ts.map +1 -0
- package/dist-esm/browser/sanitizer.js +207 -0
- package/dist-esm/browser/sanitizer.js.map +1 -0
- package/dist-esm/browser/traced-socket.d.ts +102 -0
- package/dist-esm/browser/traced-socket.d.ts.map +1 -0
- package/dist-esm/browser/traced-socket.js +182 -0
- package/dist-esm/browser/traced-socket.js.map +1 -0
- package/dist-esm/common/index.d.ts +1 -0
- package/dist-esm/common/index.d.ts.map +1 -1
- package/dist-esm/common/index.js +1 -0
- package/dist-esm/common/index.js.map +1 -1
- package/dist-esm/common/traced-socket-types.d.ts +43 -0
- package/dist-esm/common/traced-socket-types.d.ts.map +1 -0
- package/dist-esm/common/traced-socket-types.js +16 -0
- package/dist-esm/common/traced-socket-types.js.map +1 -0
- package/dist-esm/types/index.d.ts +5 -1
- package/dist-esm/types/index.d.ts.map +1 -1
- package/package.json +6 -3
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side TracedSocket for WebSocket tracing.
|
|
3
|
+
*
|
|
4
|
+
* Wraps a WebSocket client (or any WebSocket-like object) and adds
|
|
5
|
+
* OpenTelemetry tracing. Designed to speak the same envelope protocol as the
|
|
6
|
+
* server-side TracedSocket so that distributed traces link correctly across
|
|
7
|
+
* the browser–server boundary.
|
|
8
|
+
*
|
|
9
|
+
* Envelope format (matches @superblocksteam/shared SocketRequest):
|
|
10
|
+
* outbound: { request: { method, id, traceparent?, tracestate?, ... } }
|
|
11
|
+
* inbound: { request: { method, id, traceparent?, tracestate?, ... } }
|
|
12
|
+
* { response: { id, ... } }
|
|
13
|
+
*
|
|
14
|
+
* Propagation uses the W3C Trace Context propagator registered globally by
|
|
15
|
+
* initBrowserTelemetry() (see browser/init.ts). The carrier is the
|
|
16
|
+
* `request` object itself — the same convention as the server side.
|
|
17
|
+
*/
|
|
18
|
+
import { type Tracer } from "@opentelemetry/api";
|
|
19
|
+
import type { SocketMessageEnvelope } from "../common/traced-socket-types.js";
|
|
20
|
+
/** Minimal browser WebSocket surface needed by BrowserTracedSocket. */
|
|
21
|
+
export interface WebSocketLike {
|
|
22
|
+
readonly readyState: number;
|
|
23
|
+
close(code?: number, reason?: string): void;
|
|
24
|
+
send(data: string | ArrayBuffer): void;
|
|
25
|
+
addEventListener(type: string, listener: (event: unknown) => void): void;
|
|
26
|
+
removeEventListener(type: string, listener: (event: unknown) => void): void;
|
|
27
|
+
}
|
|
28
|
+
/** Configuration for BrowserTracedSocket. */
|
|
29
|
+
export interface BrowserTracedSocketConfig {
|
|
30
|
+
/**
|
|
31
|
+
* Tracer instance. When omitted the global tracer named
|
|
32
|
+
* "superblocks-ws" is used (requires initBrowserTelemetry() first).
|
|
33
|
+
*/
|
|
34
|
+
tracer?: Tracer;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* BrowserTracedSocket wraps a WebSocket and provides:
|
|
38
|
+
*
|
|
39
|
+
* 1. `decorateOutbound(msg)` — call this before sending any message.
|
|
40
|
+
* Injects traceparent/tracestate into msg.request so the server can
|
|
41
|
+
* extract the browser's active context.
|
|
42
|
+
*
|
|
43
|
+
* 2. `traceOutboundCall(method)` — wraps a client-initiated RPC call in a
|
|
44
|
+
* CLIENT span. Returns the span's end function.
|
|
45
|
+
*
|
|
46
|
+
* 3. `handleInbound(msg)` — call this when a message arrives from the server.
|
|
47
|
+
* Extracts the server's trace context and creates a SERVER span so that
|
|
48
|
+
* server-initiated pushes appear in the browser's trace.
|
|
49
|
+
*
|
|
50
|
+
* 4. `recordReconnect({ attempt })` — call this from the reconnect loop to
|
|
51
|
+
* create a ws.reconnect span.
|
|
52
|
+
*
|
|
53
|
+
* Lifecycle spans (ws.connect, ws.disconnect) are attached automatically via
|
|
54
|
+
* WebSocket open/close event listeners.
|
|
55
|
+
*/
|
|
56
|
+
export declare class BrowserTracedSocket {
|
|
57
|
+
private readonly ws;
|
|
58
|
+
private readonly tracer;
|
|
59
|
+
private connectStartTime;
|
|
60
|
+
constructor(ws: WebSocketLike, config: BrowserTracedSocketConfig);
|
|
61
|
+
private readonly onOpen;
|
|
62
|
+
private readonly onClose;
|
|
63
|
+
/**
|
|
64
|
+
* Records a ws.reconnect span. Call this from the reconnect loop just
|
|
65
|
+
* before opening a new WebSocket, passing the attempt counter so it shows
|
|
66
|
+
* up as a span attribute.
|
|
67
|
+
*/
|
|
68
|
+
recordReconnect({ attempt }: {
|
|
69
|
+
attempt: number;
|
|
70
|
+
}): void;
|
|
71
|
+
/**
|
|
72
|
+
* Injects W3C trace context into the message's request envelope.
|
|
73
|
+
* Call this on every outbound message before handing it to the transport.
|
|
74
|
+
*
|
|
75
|
+
* Mirrors the server-side TracedSocket.decorateToSend() behaviour so that
|
|
76
|
+
* the server can extract the browser's active context via propagation.extract.
|
|
77
|
+
*/
|
|
78
|
+
decorateOutbound(message: SocketMessageEnvelope): SocketMessageEnvelope;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a CLIENT span for a browser-initiated RPC call.
|
|
81
|
+
* Returns the span so the caller can end it after the response resolves.
|
|
82
|
+
*
|
|
83
|
+
* Usage:
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const span = socket.traceOutboundCall("editor.runApi");
|
|
86
|
+
* const result = await socket.request("editor.runApi", params);
|
|
87
|
+
* span.end();
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
traceOutboundCall(method: string): import("@opentelemetry/api").Span;
|
|
91
|
+
/**
|
|
92
|
+
* Handles an inbound message from the server.
|
|
93
|
+
* - Extracts the server's trace context from the request envelope.
|
|
94
|
+
* - Creates a SERVER span as a child of the server's trace so that
|
|
95
|
+
* server-initiated pushes appear in the browser's distributed trace.
|
|
96
|
+
* - Response-only messages (no request field) are ignored.
|
|
97
|
+
*/
|
|
98
|
+
handleInbound(message: SocketMessageEnvelope): void;
|
|
99
|
+
/** Remove lifecycle listeners. Call when tearing down the socket. */
|
|
100
|
+
dispose(): void;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=traced-socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced-socket.d.ts","sourceRoot":"","sources":["../../src/browser/traced-socket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAML,KAAK,MA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;OAMG;IACI,aAAa,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI;IAgC1D,qEAAqE;IAC9D,OAAO,IAAI,IAAI;CAIvB"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Browser-side TracedSocket for WebSocket tracing.
|
|
4
|
+
*
|
|
5
|
+
* Wraps a WebSocket client (or any WebSocket-like object) and adds
|
|
6
|
+
* OpenTelemetry tracing. Designed to speak the same envelope protocol as the
|
|
7
|
+
* server-side TracedSocket so that distributed traces link correctly across
|
|
8
|
+
* the browser–server boundary.
|
|
9
|
+
*
|
|
10
|
+
* Envelope format (matches @superblocksteam/shared SocketRequest):
|
|
11
|
+
* outbound: { request: { method, id, traceparent?, tracestate?, ... } }
|
|
12
|
+
* inbound: { request: { method, id, traceparent?, tracestate?, ... } }
|
|
13
|
+
* { response: { id, ... } }
|
|
14
|
+
*
|
|
15
|
+
* Propagation uses the W3C Trace Context propagator registered globally by
|
|
16
|
+
* initBrowserTelemetry() (see browser/init.ts). The carrier is the
|
|
17
|
+
* `request` object itself — the same convention as the server side.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.BrowserTracedSocket = void 0;
|
|
21
|
+
const api_1 = require("@opentelemetry/api");
|
|
22
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
23
|
+
const MESSAGING_ATTRS = {
|
|
24
|
+
[semantic_conventions_1.SEMATTRS_MESSAGING_SYSTEM]: "ws",
|
|
25
|
+
[semantic_conventions_1.SEMATTRS_MESSAGING_DESTINATION_KIND]: "websocket",
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* BrowserTracedSocket wraps a WebSocket and provides:
|
|
29
|
+
*
|
|
30
|
+
* 1. `decorateOutbound(msg)` — call this before sending any message.
|
|
31
|
+
* Injects traceparent/tracestate into msg.request so the server can
|
|
32
|
+
* extract the browser's active context.
|
|
33
|
+
*
|
|
34
|
+
* 2. `traceOutboundCall(method)` — wraps a client-initiated RPC call in a
|
|
35
|
+
* CLIENT span. Returns the span's end function.
|
|
36
|
+
*
|
|
37
|
+
* 3. `handleInbound(msg)` — call this when a message arrives from the server.
|
|
38
|
+
* Extracts the server's trace context and creates a SERVER span so that
|
|
39
|
+
* server-initiated pushes appear in the browser's trace.
|
|
40
|
+
*
|
|
41
|
+
* 4. `recordReconnect({ attempt })` — call this from the reconnect loop to
|
|
42
|
+
* create a ws.reconnect span.
|
|
43
|
+
*
|
|
44
|
+
* Lifecycle spans (ws.connect, ws.disconnect) are attached automatically via
|
|
45
|
+
* WebSocket open/close event listeners.
|
|
46
|
+
*/
|
|
47
|
+
class BrowserTracedSocket {
|
|
48
|
+
ws;
|
|
49
|
+
tracer;
|
|
50
|
+
connectStartTime;
|
|
51
|
+
constructor(ws, config) {
|
|
52
|
+
this.ws = ws;
|
|
53
|
+
this.tracer = config.tracer ?? api_1.trace.getTracer("superblocks-ws", "0.0.0");
|
|
54
|
+
this.ws.addEventListener("open", this.onOpen);
|
|
55
|
+
this.ws.addEventListener("close", this.onClose);
|
|
56
|
+
}
|
|
57
|
+
// ------------------------------------------------------------------
|
|
58
|
+
// Lifecycle handlers
|
|
59
|
+
// ------------------------------------------------------------------
|
|
60
|
+
onOpen = (_event) => {
|
|
61
|
+
const durationMs = this.connectStartTime
|
|
62
|
+
? Date.now() - this.connectStartTime
|
|
63
|
+
: undefined;
|
|
64
|
+
this.tracer.startActiveSpan("ws.connect", {
|
|
65
|
+
kind: api_1.SpanKind.CLIENT,
|
|
66
|
+
attributes: {
|
|
67
|
+
...MESSAGING_ATTRS,
|
|
68
|
+
...(durationMs !== undefined
|
|
69
|
+
? { "ws.connect_duration_ms": durationMs }
|
|
70
|
+
: {}),
|
|
71
|
+
},
|
|
72
|
+
}, (span) => {
|
|
73
|
+
span.end();
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
onClose = (event) => {
|
|
77
|
+
const ev = event;
|
|
78
|
+
const code = ev.code ?? 1000;
|
|
79
|
+
const reason = ev.reason ?? "";
|
|
80
|
+
this.tracer.startActiveSpan("ws.disconnect", {
|
|
81
|
+
kind: api_1.SpanKind.CLIENT,
|
|
82
|
+
attributes: {
|
|
83
|
+
...MESSAGING_ATTRS,
|
|
84
|
+
"ws.close_code": code,
|
|
85
|
+
"ws.close_reason": reason,
|
|
86
|
+
},
|
|
87
|
+
}, (span) => {
|
|
88
|
+
span.end();
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Records a ws.reconnect span. Call this from the reconnect loop just
|
|
93
|
+
* before opening a new WebSocket, passing the attempt counter so it shows
|
|
94
|
+
* up as a span attribute.
|
|
95
|
+
*/
|
|
96
|
+
recordReconnect({ attempt }) {
|
|
97
|
+
this.tracer.startActiveSpan("ws.reconnect", {
|
|
98
|
+
kind: api_1.SpanKind.CLIENT,
|
|
99
|
+
attributes: {
|
|
100
|
+
...MESSAGING_ATTRS,
|
|
101
|
+
"ws.reconnect_attempt": attempt,
|
|
102
|
+
},
|
|
103
|
+
}, (span) => {
|
|
104
|
+
span.end();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
// ------------------------------------------------------------------
|
|
108
|
+
// Outbound
|
|
109
|
+
// ------------------------------------------------------------------
|
|
110
|
+
/**
|
|
111
|
+
* Injects W3C trace context into the message's request envelope.
|
|
112
|
+
* Call this on every outbound message before handing it to the transport.
|
|
113
|
+
*
|
|
114
|
+
* Mirrors the server-side TracedSocket.decorateToSend() behaviour so that
|
|
115
|
+
* the server can extract the browser's active context via propagation.extract.
|
|
116
|
+
*/
|
|
117
|
+
decorateOutbound(message) {
|
|
118
|
+
if (!message.request) {
|
|
119
|
+
return message;
|
|
120
|
+
}
|
|
121
|
+
// Skip if already injected (e.g. manual traceparent for testing)
|
|
122
|
+
if (message.request.traceparent || message.request.tracestate) {
|
|
123
|
+
return message;
|
|
124
|
+
}
|
|
125
|
+
api_1.propagation.inject(api_1.context.active(), message.request);
|
|
126
|
+
return message;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Creates a CLIENT span for a browser-initiated RPC call.
|
|
130
|
+
* Returns the span so the caller can end it after the response resolves.
|
|
131
|
+
*
|
|
132
|
+
* Usage:
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const span = socket.traceOutboundCall("editor.runApi");
|
|
135
|
+
* const result = await socket.request("editor.runApi", params);
|
|
136
|
+
* span.end();
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
traceOutboundCall(method) {
|
|
140
|
+
return this.tracer.startActiveSpan(`WS CLIENT ${method}`, {
|
|
141
|
+
kind: api_1.SpanKind.CLIENT,
|
|
142
|
+
attributes: {
|
|
143
|
+
...MESSAGING_ATTRS,
|
|
144
|
+
"ws.method": method,
|
|
145
|
+
},
|
|
146
|
+
}, (span) => span);
|
|
147
|
+
}
|
|
148
|
+
// ------------------------------------------------------------------
|
|
149
|
+
// Inbound
|
|
150
|
+
// ------------------------------------------------------------------
|
|
151
|
+
/**
|
|
152
|
+
* Handles an inbound message from the server.
|
|
153
|
+
* - Extracts the server's trace context from the request envelope.
|
|
154
|
+
* - Creates a SERVER span as a child of the server's trace so that
|
|
155
|
+
* server-initiated pushes appear in the browser's distributed trace.
|
|
156
|
+
* - Response-only messages (no request field) are ignored.
|
|
157
|
+
*/
|
|
158
|
+
handleInbound(message) {
|
|
159
|
+
if (!message.request) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const method = message.request.method ?? "unknown";
|
|
163
|
+
const parentCtx = api_1.propagation.extract(api_1.ROOT_CONTEXT, message.request);
|
|
164
|
+
api_1.context.with(parentCtx, () => {
|
|
165
|
+
this.tracer.startActiveSpan(`WS SERVER ${method}`, {
|
|
166
|
+
kind: api_1.SpanKind.CLIENT,
|
|
167
|
+
attributes: {
|
|
168
|
+
...MESSAGING_ATTRS,
|
|
169
|
+
"ws.method": method,
|
|
170
|
+
},
|
|
171
|
+
}, (span) => {
|
|
172
|
+
span.end();
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
// ------------------------------------------------------------------
|
|
177
|
+
// Cleanup
|
|
178
|
+
// ------------------------------------------------------------------
|
|
179
|
+
/** Remove lifecycle listeners. Call when tearing down the socket. */
|
|
180
|
+
dispose() {
|
|
181
|
+
this.ws.removeEventListener("open", this.onOpen);
|
|
182
|
+
this.ws.removeEventListener("close", this.onClose);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.BrowserTracedSocket = BrowserTracedSocket;
|
|
186
|
+
//# sourceMappingURL=traced-socket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced-socket.js","sourceRoot":"","sources":["../../src/browser/traced-socket.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAEH,4CAO4B;AAC5B,8EAG6C;AAsB7C,MAAM,eAAe,GAAG;IACtB,CAAC,gDAAyB,CAAC,EAAE,IAAI;IACjC,CAAC,0DAAmC,CAAC,EAAE,WAAW;CAC1C,CAAC;AAEX;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,mBAAmB;IAKX;IAJF,MAAM,CAAS;IACxB,gBAAgB,CAAqB;IAE7C,YACmB,EAAiB,EAClC,MAAiC;QADhB,OAAE,GAAF,EAAE,CAAe;QAGlC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,WAAK,CAAC,SAAS,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAE1E,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;IAED,qEAAqE;IACrE,qBAAqB;IACrB,qEAAqE;IAEpD,MAAM,GAAG,CAAC,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AAe,CACzB,aAAa,MAAM,EAAE,EACrB;gBACE,IAAI,EAAE,cAAQ,CAAC,MAAM;gBACrB,UAAU,EAAE;oBACV,GAAG,eAAe;oBAClB,WAAW,EAAE,MAAM;iBACpB;aACF,EACD,CAAC,IAAI,EAAE,EAAE;gBACP,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,qEAAqE;IACrE,UAAU;IACV,qEAAqE;IAErE,qEAAqE;IAC9D,OAAO;QACZ,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACjD,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACrD,CAAC;CACF;AAvLD,kDAuLC"}
|
package/dist/common/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* in the tiered telemetry architecture. See obs/otel-collector/config-tiered.yaml.
|
|
8
8
|
*/
|
|
9
9
|
export * from "./deployment-type.js";
|
|
10
|
+
export * from "./traced-socket-types.js";
|
|
10
11
|
export * from "./resource.js";
|
|
11
12
|
export * from "./policy-evaluator.js";
|
|
12
13
|
export * from "./guardrails.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
|
package/dist/common/index.js
CHANGED
|
@@ -23,6 +23,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
__exportStar(require("./deployment-type.js"), exports);
|
|
26
|
+
__exportStar(require("./traced-socket-types.js"), exports);
|
|
26
27
|
__exportStar(require("./resource.js"), exports);
|
|
27
28
|
__exportStar(require("./policy-evaluator.js"), exports);
|
|
28
29
|
__exportStar(require("./guardrails.js"), exports);
|
package/dist/common/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;AAEH,uDAAqC;AACrC,gDAA8B;AAC9B,wDAAsC;AACtC,kDAAgC;AAChC,8DAA4C;AAC5C,qDAAmC;AACnC,kDAAgC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;AAEH,uDAAqC;AACrC,2DAAyC;AACzC,gDAA8B;AAC9B,wDAAsC;AACtC,kDAAgC;AAChC,8DAA4C;AAC5C,qDAAmC;AACnC,kDAAgC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared TracedSocket types for WebSocket message envelopes.
|
|
3
|
+
*
|
|
4
|
+
* Both the browser (TracedSocket in telemetry/browser) and the server
|
|
5
|
+
* (TracedSocket in telemetry/node) inject and extract trace context using
|
|
6
|
+
* these field names. Keeping them in one place ensures the two sides speak
|
|
7
|
+
* the same envelope protocol so traces link correctly end-to-end.
|
|
8
|
+
*
|
|
9
|
+
* Envelope structure mirrors @superblocksteam/shared SocketRequest:
|
|
10
|
+
* { request?: { method, payload, id, traceparent?, tracestate?, ... } }
|
|
11
|
+
*
|
|
12
|
+
* The W3C Trace Context propagator writes/reads exactly these two fields.
|
|
13
|
+
* See: https://www.w3.org/TR/trace-context/
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* W3C Trace Context fields that live inside a socket message's request object.
|
|
17
|
+
* The propagator uses these as the carrier for context injection/extraction.
|
|
18
|
+
*/
|
|
19
|
+
export interface SocketTraceContext {
|
|
20
|
+
traceparent?: string;
|
|
21
|
+
tracestate?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Minimal shape of the request portion of a socket message envelope.
|
|
25
|
+
* Both browser and server code passes this object as the propagation carrier.
|
|
26
|
+
*/
|
|
27
|
+
export interface SocketRequestEnvelope extends SocketTraceContext {
|
|
28
|
+
method?: string;
|
|
29
|
+
id?: number;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Minimal shape of the full socket message envelope.
|
|
34
|
+
* Request messages carry trace context; response messages do not.
|
|
35
|
+
*/
|
|
36
|
+
export interface SocketMessageEnvelope {
|
|
37
|
+
request?: SocketRequestEnvelope;
|
|
38
|
+
response?: {
|
|
39
|
+
id?: number;
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=traced-socket-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced-socket-types.d.ts","sourceRoot":"","sources":["../../src/common/traced-socket-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAChC,QAAQ,CAAC,EAAE;QACT,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared TracedSocket types for WebSocket message envelopes.
|
|
4
|
+
*
|
|
5
|
+
* Both the browser (TracedSocket in telemetry/browser) and the server
|
|
6
|
+
* (TracedSocket in telemetry/node) inject and extract trace context using
|
|
7
|
+
* these field names. Keeping them in one place ensures the two sides speak
|
|
8
|
+
* the same envelope protocol so traces link correctly end-to-end.
|
|
9
|
+
*
|
|
10
|
+
* Envelope structure mirrors @superblocksteam/shared SocketRequest:
|
|
11
|
+
* { request?: { method, payload, id, traceparent?, tracestate?, ... } }
|
|
12
|
+
*
|
|
13
|
+
* The W3C Trace Context propagator writes/reads exactly these two fields.
|
|
14
|
+
* See: https://www.w3.org/TR/trace-context/
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
//# sourceMappingURL=traced-socket-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced-socket-types.js","sourceRoot":"","sources":["../../src/common/traced-socket-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -61,7 +61,11 @@ export interface NodeTelemetryConfig extends BaseTelemetryConfig {
|
|
|
61
61
|
* Browser specific telemetry configuration.
|
|
62
62
|
*/
|
|
63
63
|
export interface BrowserTelemetryConfig extends BaseTelemetryConfig {
|
|
64
|
-
/** OTLP traces
|
|
64
|
+
/** OTLP base URL (e.g. "http://localhost:4318"). Signal-specific paths (/v1/traces, /v1/metrics, /v1/logs) are appended automatically. */
|
|
65
65
|
otlpUrl: string;
|
|
66
|
+
/** URL patterns to inject traceparent header into (for cross-origin propagation) */
|
|
67
|
+
propagateTraceUrls?: RegExp[];
|
|
68
|
+
/** URL patterns to skip instrumenting entirely */
|
|
69
|
+
ignoreUrls?: RegExp[];
|
|
66
70
|
}
|
|
67
71
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,aAAa,CAAC;AAE5B;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;IAEpB,sCAAsC;IACtC,cAAc,EAAE,MAAM,CAAC;IAEvB,4EAA4E;IAC5E,WAAW,EAAE,MAAM,CAAC;IAEpB,qCAAqC;IACrC,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7C;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1C,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB;IAC9D,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,+CAA+C;IAC/C,gBAAgB,CAAC,EAAE,OAAO,EAAE,CAAC;IAE7B,2CAA2C;IAC3C,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB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,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB;IAC9D,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,+CAA+C;IAC/C,gBAAgB,CAAC,EAAE,OAAO,EAAE,CAAC;IAE7B,2CAA2C;IAC3C,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB,uCAAuC;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,wBAAwB,CAAC,EAAE,wBAAwB,GAAG,IAAI,CAAC;IAE3D;;;OAGG;IACH,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACxC,KAAK,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACvC,IAAI,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACtC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;KACzB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,mBAAmB;IACjE,0IAA0I;IAC1I,OAAO,EAAE,MAAM,CAAC;IAEhB,oFAAoF;IACpF,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE9B,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Console Log Attributes
|
|
3
|
+
*
|
|
4
|
+
* Used to attach structured key-value metadata to console.* calls so the
|
|
5
|
+
* EarlyConsoleBuffer (and the live OTel patch) can forward them as OTEL log
|
|
6
|
+
* record attributes.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { consoleLogAttributes } from '@superblocksteam/telemetry/browser';
|
|
10
|
+
* console.info("user loaded", consoleLogAttributes({ userId: "abc123" }));
|
|
11
|
+
*/
|
|
12
|
+
export declare class ConsoleLogAttributes {
|
|
13
|
+
readonly attributes: Record<string, unknown>;
|
|
14
|
+
constructor(attributes: Record<string, unknown>);
|
|
15
|
+
static create(attrs: Record<string, unknown>): ConsoleLogAttributes;
|
|
16
|
+
}
|
|
17
|
+
export declare const consoleLogAttributes: (attrs: Record<string, unknown>) => ConsoleLogAttributes;
|
|
18
|
+
//# sourceMappingURL=console-logging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-logging.d.ts","sourceRoot":"","sources":["../../src/browser/console-logging.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,qBAAa,oBAAoB;aACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAAnC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAE/D,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,oBAAoB;CAGpE;AAGD,eAAO,MAAM,oBAAoB,GAC/B,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,oBAEF,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Console Log Attributes
|
|
3
|
+
*
|
|
4
|
+
* Used to attach structured key-value metadata to console.* calls so the
|
|
5
|
+
* EarlyConsoleBuffer (and the live OTel patch) can forward them as OTEL log
|
|
6
|
+
* record attributes.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { consoleLogAttributes } from '@superblocksteam/telemetry/browser';
|
|
10
|
+
* console.info("user loaded", consoleLogAttributes({ userId: "abc123" }));
|
|
11
|
+
*/
|
|
12
|
+
// The attributes that should be passed to OTEL logs as part of the message context.
|
|
13
|
+
// To use, create an instance of this class and pass it as an argument to console.* methods.
|
|
14
|
+
export class ConsoleLogAttributes {
|
|
15
|
+
attributes;
|
|
16
|
+
constructor(attributes) {
|
|
17
|
+
this.attributes = attributes;
|
|
18
|
+
}
|
|
19
|
+
static create(attrs) {
|
|
20
|
+
return new ConsoleLogAttributes(attrs);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Convenience factory
|
|
24
|
+
export const consoleLogAttributes = (attrs) => {
|
|
25
|
+
return new ConsoleLogAttributes(attrs);
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=console-logging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-logging.js","sourceRoot":"","sources":["../../src/browser/console-logging.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,oFAAoF;AACpF,4FAA4F;AAC5F,MAAM,OAAO,oBAAoB;IACH;IAA5B,YAA4B,UAAmC;QAAnC,eAAU,GAAV,UAAU,CAAyB;IAAG,CAAC;IAEnE,MAAM,CAAC,MAAM,CAAC,KAA8B;QAC1C,OAAO,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CACF;AAED,sBAAsB;AACtB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,KAA8B,EACR,EAAE;IACxB,OAAO,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Early Console Buffer
|
|
3
|
+
*
|
|
4
|
+
* Patches console.log/info/debug/warn/error as early as possible (before OTel
|
|
5
|
+
* initialises) to capture logs in a ring buffer. On OTel init, the buffer is
|
|
6
|
+
* flushed to the OTel Logger and all subsequent console calls are forwarded
|
|
7
|
+
* directly.
|
|
8
|
+
*
|
|
9
|
+
* IMPORTANT: Each patched method ALWAYS calls through to the original console
|
|
10
|
+
* method first, so downstream patchers (Datadog RUM, PostHog, etc.) that wrap
|
|
11
|
+
* console after us continue to receive every call.
|
|
12
|
+
*/
|
|
13
|
+
import { type Logger } from "@opentelemetry/api-logs";
|
|
14
|
+
declare class EarlyConsoleBuffer {
|
|
15
|
+
private static instance;
|
|
16
|
+
private buffer;
|
|
17
|
+
private maxBufferSize;
|
|
18
|
+
private originalMethods;
|
|
19
|
+
private otelLogger;
|
|
20
|
+
private isPatched;
|
|
21
|
+
static getInstance(): EarlyConsoleBuffer;
|
|
22
|
+
/**
|
|
23
|
+
* Patch console methods immediately with buffering.
|
|
24
|
+
* Safe to call multiple times — subsequent calls are no-ops.
|
|
25
|
+
*/
|
|
26
|
+
patchEarly(): void;
|
|
27
|
+
private patchMethod;
|
|
28
|
+
private bufferLog;
|
|
29
|
+
/**
|
|
30
|
+
* Called once OTel is ready. Flushes buffered entries then routes all future
|
|
31
|
+
* console calls directly to the OTel logger.
|
|
32
|
+
*/
|
|
33
|
+
enableOpenTelemetry(otelLogger: Logger): void;
|
|
34
|
+
private flushBuffer;
|
|
35
|
+
private sendToOpenTelemetry;
|
|
36
|
+
private formatConsoleArgs;
|
|
37
|
+
}
|
|
38
|
+
export default EarlyConsoleBuffer;
|
|
39
|
+
//# sourceMappingURL=early-console-buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"early-console-buffer.d.ts","sourceRoot":"","sources":["../../src/browser/early-console-buffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,MAAM,EAAkB,MAAM,yBAAyB,CAAC;AAuBtE,cAAM,kBAAkB;IACtB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAqB;IAE5C,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,aAAa,CAAQ;IAE7B,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,UAAU,CAAiC;IACnD,OAAO,CAAC,SAAS,CAAS;IAE1B,MAAM,CAAC,WAAW,IAAI,kBAAkB;IAOxC;;;OAGG;IACH,UAAU,IAAI,IAAI;IA4BlB,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,SAAS;IAOjB;;;OAGG;IACH,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAM7C,OAAO,CAAC,WAAW;IAwBnB,OAAO,CAAC,mBAAmB;IA8B3B,OAAO,CAAC,iBAAiB;CAkB1B;AAED,eAAe,kBAAkB,CAAC"}
|