grpc-dc 0.39.0 → 0.41.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/README.md +1 -0
- package/index.d.ts +74 -0
- package/index.js +31 -0
- package/package.json +5 -1
- package/plugin/gen/generators.js +12 -1
- package/src/channel.js +19 -2
- package/src/chunking.js +143 -0
- package/src/codec.js +26 -7
- package/src/kafka_grpc_dc.js +69 -1
- package/src/kafka_native.js +177 -0
- package/src/kafka_native_addon.c +389 -0
- package/src/kafka_pb.js +1417 -1
- package/src/rendezvous.js +127 -0
- package/src/rendezvous_server.js +44 -0
- package/src/server.js +1 -0
- package/src/signaling.js +224 -0
- package/src/signaling_server.js +212 -0
package/README.md
CHANGED
|
@@ -30,5 +30,6 @@ https://browser-grpc.github.io/grpc-over-datachannels/app/
|
|
|
30
30
|
- Runtime: this directory (see its generated sources).
|
|
31
31
|
- Worked example: `examples/` (Echo in every method shape).
|
|
32
32
|
- Tests: `tests/` — the same BDD scenarios every language runs.
|
|
33
|
+
- Test and example index: [`TESTS.md`](TESTS.md) — every suite and example here, plus shared matrix coverage.
|
|
33
34
|
|
|
34
35
|
Full project quickstart: [`../QUICKSTART.md`](../QUICKSTART.md).
|
package/index.d.ts
CHANGED
|
@@ -115,6 +115,80 @@ export declare function createPeer(
|
|
|
115
115
|
options?: { parity?: "odd" | "even" },
|
|
116
116
|
): { endpoint: Endpoint; server: Server; channel: Channel };
|
|
117
117
|
|
|
118
|
+
// HTTP/POST signaling (browser client; server half is the
|
|
119
|
+
// Node-only grpc-dc/signaling_server module, untyped here).
|
|
120
|
+
export declare const SIGNAL_PATH: string;
|
|
121
|
+
export declare function signalViaHttp(
|
|
122
|
+
url: string,
|
|
123
|
+
offerSdp: string,
|
|
124
|
+
fetchImpl?: typeof fetch,
|
|
125
|
+
): Promise<string>;
|
|
126
|
+
export declare function signalSessionViaHttp(
|
|
127
|
+
url: string,
|
|
128
|
+
offerSdp: string,
|
|
129
|
+
fetchImpl?: typeof fetch,
|
|
130
|
+
): Promise<{ sdp: string; session: string | null }>;
|
|
131
|
+
export declare function signalCandidateViaHttp(
|
|
132
|
+
url: string,
|
|
133
|
+
session: string,
|
|
134
|
+
candidate: string,
|
|
135
|
+
fetchImpl?: typeof fetch,
|
|
136
|
+
): Promise<void>;
|
|
137
|
+
export declare function signalRestartViaHttp(
|
|
138
|
+
url: string,
|
|
139
|
+
session: string,
|
|
140
|
+
offerSdp: string,
|
|
141
|
+
fetchImpl?: typeof fetch,
|
|
142
|
+
): Promise<string>;
|
|
143
|
+
export interface HttpSignalingOptions {
|
|
144
|
+
iceServers?: RTCIceServer[];
|
|
145
|
+
iceGatherTimeoutMs?: number;
|
|
146
|
+
connectTimeoutMs?: number;
|
|
147
|
+
label?: string;
|
|
148
|
+
trickle?: boolean;
|
|
149
|
+
fetchImpl?: typeof fetch;
|
|
150
|
+
RTCPeerConnectionImpl?: typeof RTCPeerConnection;
|
|
151
|
+
}
|
|
152
|
+
export declare function httpSignalingChannel(
|
|
153
|
+
url: string,
|
|
154
|
+
options?: HttpSignalingOptions,
|
|
155
|
+
): Promise<Channel & {
|
|
156
|
+
peerConnection: RTCPeerConnection;
|
|
157
|
+
dataChannel: RTCDataChannel;
|
|
158
|
+
signalingSession: string | null;
|
|
159
|
+
closeSignaling(): void;
|
|
160
|
+
restartSignaling(): Promise<void>;
|
|
161
|
+
}>;
|
|
162
|
+
export interface RendezvousDescriptor {
|
|
163
|
+
host: string;
|
|
164
|
+
port: number;
|
|
165
|
+
iceUfrag: string;
|
|
166
|
+
icePwd: string;
|
|
167
|
+
fingerprint: string;
|
|
168
|
+
setup?: string;
|
|
169
|
+
}
|
|
170
|
+
export interface RendezvousOptions {
|
|
171
|
+
iceServers?: RTCIceServer[];
|
|
172
|
+
iceTransportPolicy?: RTCIceTransportPolicy;
|
|
173
|
+
timeoutMs?: number;
|
|
174
|
+
label?: string;
|
|
175
|
+
}
|
|
176
|
+
export declare function synthesizeRendezvousOffer(
|
|
177
|
+
descriptor: RendezvousDescriptor,
|
|
178
|
+
): string;
|
|
179
|
+
export declare function fetchRendezvousDescriptor(
|
|
180
|
+
url: string,
|
|
181
|
+
options?: { fetchImpl?: typeof fetch },
|
|
182
|
+
): Promise<RendezvousDescriptor>;
|
|
183
|
+
export declare function rendezvousChannel(
|
|
184
|
+
descriptor: RendezvousDescriptor,
|
|
185
|
+
options?: RendezvousOptions,
|
|
186
|
+
): Promise<Channel & {
|
|
187
|
+
peerConnection: RTCPeerConnection;
|
|
188
|
+
dataChannel: RTCDataChannel;
|
|
189
|
+
closeRendezvous(): void;
|
|
190
|
+
}>;
|
|
191
|
+
|
|
118
192
|
// Event bus (grpcdc.events.v1): message/stub types live in
|
|
119
193
|
// grpc-dc's generated events_pb/events_grpc_dc modules; these
|
|
120
194
|
// are the broker and helpers over them. TagValue/Event are
|
package/index.js
CHANGED
|
@@ -11,8 +11,11 @@ export {
|
|
|
11
11
|
decodeFrame,
|
|
12
12
|
encodeTimeout,
|
|
13
13
|
parseTimeout,
|
|
14
|
+
asTraceParent,
|
|
15
|
+
newTraceContext,
|
|
14
16
|
setTracer,
|
|
15
17
|
setTraceFilter,
|
|
18
|
+
traceEnd,
|
|
16
19
|
toHex,
|
|
17
20
|
fromHex,
|
|
18
21
|
} from "./src/codec.js";
|
|
@@ -31,7 +34,35 @@ export {
|
|
|
31
34
|
export { Channel } from "./src/channel.js";
|
|
32
35
|
export { Server } from "./src/server.js";
|
|
33
36
|
export { memoryDataChannelPair } from "./src/loopback.js";
|
|
37
|
+
export {
|
|
38
|
+
DC_CHUNK_MAGIC,
|
|
39
|
+
MAX_DC_CHUNK_PAYLOAD,
|
|
40
|
+
DcChunkReassembler,
|
|
41
|
+
chunkedDataChannel,
|
|
42
|
+
splitDcMessage,
|
|
43
|
+
} from "./src/chunking.js";
|
|
34
44
|
export { createGrpcDcBridge, createGrpcDcServerBridge } from "./src/wasm_bridge.js";
|
|
45
|
+
export {
|
|
46
|
+
SIGNAL_PATH,
|
|
47
|
+
httpSignalingChannel,
|
|
48
|
+
signalCandidateViaHttp,
|
|
49
|
+
signalRestartViaHttp,
|
|
50
|
+
signalSessionViaHttp,
|
|
51
|
+
signalViaHttp,
|
|
52
|
+
} from "./src/signaling.js";
|
|
53
|
+
export {
|
|
54
|
+
fetchRendezvousDescriptor,
|
|
55
|
+
rendezvousChannel,
|
|
56
|
+
synthesizeRendezvousOffer,
|
|
57
|
+
} from "./src/rendezvous.js";
|
|
58
|
+
// The rendezvous server (src/rendezvous_server.js) is Node-only
|
|
59
|
+
// (node:dgram via webrtc/js/rendezvous.js) and is not re-exported
|
|
60
|
+
// here. Import it directly:
|
|
61
|
+
// import { serveRendezvous } from "grpc-dc/rendezvous_server";
|
|
62
|
+
// The Node HTTP/POST signaling server (src/signaling_server.js)
|
|
63
|
+
// is likewise Node-only (node:http + the Node WebRTC stack) and
|
|
64
|
+
// is not re-exported here. Import it directly:
|
|
65
|
+
// import { serveHttpSignaling } from "grpc-dc/signaling_server";
|
|
35
66
|
// Note: the Node WebRTC-Direct adapter (src/webrtc_direct.js)
|
|
36
67
|
// is deliberately NOT re-exported here -- it imports Node-only
|
|
37
68
|
// modules (node:dgram via webrtc/js/direct.js) and this index
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grpc-dc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "gRPC in the browser over WebRTC DataChannels: dependency-free generated gRPC clients & servers for JavaScript \u2014 no grpc-web proxy, no external runtime",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"grpc",
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
},
|
|
30
30
|
"./wire_gen.js": "./wire_gen.js",
|
|
31
31
|
"./webrtc_direct": "./src/webrtc_direct.js",
|
|
32
|
+
"./signaling": "./src/signaling.js",
|
|
33
|
+
"./signaling_server": "./src/signaling_server.js",
|
|
34
|
+
"./rendezvous": "./src/rendezvous.js",
|
|
35
|
+
"./rendezvous_server": "./src/rendezvous_server.js",
|
|
32
36
|
"./http2": "./src/http2.js",
|
|
33
37
|
"./eventbus_gitlog": "./src/eventbus_gitlog.js"
|
|
34
38
|
},
|
package/plugin/gen/generators.js
CHANGED
|
@@ -3398,8 +3398,19 @@ function swpCamel(s) {
|
|
|
3398
3398
|
return parts[0] + parts.slice(1).map((p) => (p ? p[0].toUpperCase() + p.slice(1) : '')).join('');
|
|
3399
3399
|
}
|
|
3400
3400
|
|
|
3401
|
+
const SWP_KEYWORDS = new Set([
|
|
3402
|
+
'associatedtype', 'class', 'deinit', 'enum', 'extension', 'fileprivate',
|
|
3403
|
+
'func', 'import', 'init', 'inout', 'internal', 'let', 'open', 'operator',
|
|
3404
|
+
'private', 'precedencegroup', 'protocol', 'public', 'rethrows', 'static',
|
|
3405
|
+
'struct', 'subscript', 'typealias', 'var', 'actor', 'async', 'await',
|
|
3406
|
+
'break', 'case', 'catch', 'continue', 'default', 'defer', 'do', 'else',
|
|
3407
|
+
'fallthrough', 'for', 'guard', 'if', 'in', 'return', 'throw', 'switch',
|
|
3408
|
+
'where', 'while', 'false', 'nil', 'true', 'self', 'Self', 'super',
|
|
3409
|
+
]);
|
|
3410
|
+
|
|
3401
3411
|
function swpFieldName(f) {
|
|
3402
|
-
|
|
3412
|
+
const n = f.jsonName ? f.jsonName : swpCamel(f.name);
|
|
3413
|
+
return SWP_KEYWORDS.has(n) ? '`' + n + '`' : n;
|
|
3403
3414
|
}
|
|
3404
3415
|
|
|
3405
3416
|
function swpResolve(model, typeName) {
|
package/src/channel.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
formatTraceparent,
|
|
13
13
|
getTracer,
|
|
14
14
|
headersFrame,
|
|
15
|
+
asTraceParent,
|
|
15
16
|
parseTraceparent,
|
|
16
17
|
statusFrame,
|
|
17
18
|
traceEnd,
|
|
@@ -88,6 +89,18 @@ function responsesIterable(inner, cancel) {
|
|
|
88
89
|
export class Channel {
|
|
89
90
|
#endpoint;
|
|
90
91
|
#traces = new Map();
|
|
92
|
+
#traceContext = null;
|
|
93
|
+
|
|
94
|
+
// A Channel view sharing this endpoint whose outbound spans are
|
|
95
|
+
// parented to traceContext (a server span context from
|
|
96
|
+
// ctx.traceContext, or a root from newTraceContext). Explicit
|
|
97
|
+
// call metadata still wins. This is the browser-safe propagation
|
|
98
|
+
// path: no ambient async context is assumed.
|
|
99
|
+
withTraceContext(traceContext) {
|
|
100
|
+
const ch = new Channel(this.#endpoint);
|
|
101
|
+
ch.#traceContext = traceContext ?? null;
|
|
102
|
+
return ch;
|
|
103
|
+
}
|
|
91
104
|
|
|
92
105
|
/** Accepts an Endpoint or a raw RTCDataChannel-like object. */
|
|
93
106
|
constructor(dcOrEndpoint, options) {
|
|
@@ -107,11 +120,15 @@ export class Channel {
|
|
|
107
120
|
}
|
|
108
121
|
let traceCtx = null;
|
|
109
122
|
if (getTracer() !== null) {
|
|
110
|
-
traceCtx = traceStart(
|
|
123
|
+
traceCtx = traceStart(
|
|
124
|
+
"client",
|
|
125
|
+
path,
|
|
126
|
+
parseTraceparent(metadata?.traceparent) ?? asTraceParent(this.#traceContext),
|
|
127
|
+
);
|
|
111
128
|
if (traceCtx !== null) {
|
|
112
129
|
metadata = {
|
|
113
130
|
...metadata,
|
|
114
|
-
traceparent: formatTraceparent(traceCtx.traceId, traceCtx.spanId),
|
|
131
|
+
traceparent: formatTraceparent(traceCtx.traceId, traceCtx.spanId, traceCtx.sampled),
|
|
115
132
|
};
|
|
116
133
|
}
|
|
117
134
|
}
|
package/src/chunking.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// @generated by grpc-dc codegen. DO NOT EDIT.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// DataChannel message chunking: browsers reject (and peers
|
|
4
|
+
// drop) single RTCDataChannel messages above the negotiated
|
|
5
|
+
// max-message-size (262144 in Chromium), so a grpc-dc frame
|
|
6
|
+
// larger than that could never cross a browser. This shim
|
|
7
|
+
// sits below the Endpoint, on the DC message layer: outgoing
|
|
8
|
+
// messages over MAX_DC_CHUNK_PAYLOAD are split into chunk
|
|
9
|
+
// messages with a 2-byte header [magic, flags]; incoming
|
|
10
|
+
// chunk messages are reassembled before the Endpoint sees
|
|
11
|
+
// them. Messages at or under the limit pass through byte-
|
|
12
|
+
// identical, and the magic byte (0xF0) is an unknown grpc-dc
|
|
13
|
+
// frame type, so a peer without the shim ignores chunks
|
|
14
|
+
// instead of misdecoding them (the documented forward-compat
|
|
15
|
+
// rule) — chunking is safe to enable on one side of a link
|
|
16
|
+
// whose other side only ever receives small messages, and
|
|
17
|
+
// required on both sides for large ones.
|
|
18
|
+
//
|
|
19
|
+
// The native WebRTC stacks (webrtc/rust, webrtc/go,
|
|
20
|
+
// webrtc/js) implement the same format behind an opt-in flag.
|
|
21
|
+
|
|
22
|
+
export const DC_CHUNK_MAGIC = 0xf0;
|
|
23
|
+
export const DC_CHUNK_FINAL = 0x01;
|
|
24
|
+
export const MAX_DC_CHUNK_PAYLOAD = 65536;
|
|
25
|
+
|
|
26
|
+
/** Split one DC message into wire messages (raw if small). */
|
|
27
|
+
export function splitDcMessage(bytes, maxPayload = MAX_DC_CHUNK_PAYLOAD) {
|
|
28
|
+
const data = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
29
|
+
if (data.length <= maxPayload) return [data];
|
|
30
|
+
const out = [];
|
|
31
|
+
for (let off = 0; off < data.length; off += maxPayload) {
|
|
32
|
+
const last = off + maxPayload >= data.length;
|
|
33
|
+
const chunk = new Uint8Array(2 + Math.min(maxPayload, data.length - off));
|
|
34
|
+
chunk[0] = DC_CHUNK_MAGIC;
|
|
35
|
+
chunk[1] = last ? DC_CHUNK_FINAL : 0;
|
|
36
|
+
chunk.set(data.subarray(off, off + Math.min(maxPayload, data.length - off)), 2);
|
|
37
|
+
out.push(chunk);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Stateful reassembler: push one wire message, get the
|
|
43
|
+
* complete logical message or null while chunks accumulate.
|
|
44
|
+
* Non-chunk messages pass through untouched. */
|
|
45
|
+
export class DcChunkReassembler {
|
|
46
|
+
#parts = null;
|
|
47
|
+
|
|
48
|
+
push(bytes) {
|
|
49
|
+
const data = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
50
|
+
if (this.#parts === null && (data.length < 2 || data[0] !== DC_CHUNK_MAGIC)) {
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
if (data.length < 2 || data[0] !== DC_CHUNK_MAGIC) {
|
|
54
|
+
// Raw message interleaved mid-reassembly (should not
|
|
55
|
+
// happen on an ordered channel): drop the partial.
|
|
56
|
+
this.#parts = null;
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
if (this.#parts === null) this.#parts = [];
|
|
60
|
+
this.#parts.push(data.subarray(2));
|
|
61
|
+
if ((data[1] & DC_CHUNK_FINAL) === 0) return null;
|
|
62
|
+
const total = this.#parts.reduce((n, p) => n + p.length, 0);
|
|
63
|
+
const out = new Uint8Array(total);
|
|
64
|
+
let off = 0;
|
|
65
|
+
for (const part of this.#parts) {
|
|
66
|
+
out.set(part, off);
|
|
67
|
+
off += part.length;
|
|
68
|
+
}
|
|
69
|
+
this.#parts = null;
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Wrap a DataChannel-shaped object (send + message events)
|
|
75
|
+
* with chunk-split sends and reassembling receives. The
|
|
76
|
+
* Endpoint-facing interface is preserved. */
|
|
77
|
+
export function chunkedDataChannel(dc, { maxPayload = MAX_DC_CHUNK_PAYLOAD } = {}) {
|
|
78
|
+
const reassembler = new DcChunkReassembler();
|
|
79
|
+
const listeners = new Map();
|
|
80
|
+
const emit = (name, event) => {
|
|
81
|
+
for (const fn of listeners.get(name) ?? []) fn(event);
|
|
82
|
+
};
|
|
83
|
+
const onRawMessage = (event) => {
|
|
84
|
+
let data = event?.data ?? event;
|
|
85
|
+
const done = (bytes) => {
|
|
86
|
+
const whole = reassembler.push(bytes);
|
|
87
|
+
if (whole !== null) emit("message", { data: whole });
|
|
88
|
+
};
|
|
89
|
+
if (typeof Blob !== "undefined" && data instanceof Blob) {
|
|
90
|
+
data.arrayBuffer().then((b) => done(new Uint8Array(b)));
|
|
91
|
+
} else if (data instanceof ArrayBuffer) {
|
|
92
|
+
done(new Uint8Array(data));
|
|
93
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
94
|
+
done(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
|
|
95
|
+
} else {
|
|
96
|
+
emit("message", event);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
if (typeof dc.addEventListener === "function") dc.addEventListener("message", onRawMessage);
|
|
100
|
+
else dc.onmessage = onRawMessage;
|
|
101
|
+
for (const name of ["open", "close", "error", "bufferedamountlow"]) {
|
|
102
|
+
if (typeof dc.addEventListener === "function") {
|
|
103
|
+
dc.addEventListener(name, (e) => emit(name, e));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
get readyState() {
|
|
108
|
+
return dc.readyState;
|
|
109
|
+
},
|
|
110
|
+
get bufferedAmount() {
|
|
111
|
+
return dc.bufferedAmount ?? 0;
|
|
112
|
+
},
|
|
113
|
+
set bufferedAmountLowThreshold(v) {
|
|
114
|
+
try {
|
|
115
|
+
dc.bufferedAmountLowThreshold = v;
|
|
116
|
+
} catch {
|
|
117
|
+
/* structural channels may not expose it */
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
set binaryType(v) {
|
|
121
|
+
try {
|
|
122
|
+
dc.binaryType = v;
|
|
123
|
+
} catch {
|
|
124
|
+
/* ignore */
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
send(bytes) {
|
|
128
|
+
for (const chunk of splitDcMessage(bytes, maxPayload)) dc.send(chunk);
|
|
129
|
+
},
|
|
130
|
+
addEventListener(name, fn) {
|
|
131
|
+
if (!listeners.has(name)) listeners.set(name, []);
|
|
132
|
+
listeners.get(name).push(fn);
|
|
133
|
+
},
|
|
134
|
+
removeEventListener(name, fn) {
|
|
135
|
+
const list = listeners.get(name) ?? [];
|
|
136
|
+
const i = list.indexOf(fn);
|
|
137
|
+
if (i >= 0) list.splice(i, 1);
|
|
138
|
+
},
|
|
139
|
+
close() {
|
|
140
|
+
dc.close?.();
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
package/src/codec.js
CHANGED
|
@@ -153,7 +153,7 @@ export function fromHex(hex) {
|
|
|
153
153
|
return out;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
// --- Homegrown tracing (W3C traceparent propagation) -------------
|
|
156
|
+
// --- Homegrown tracing (beta) (W3C traceparent propagation) -------------
|
|
157
157
|
// Dormant until setTracer() registers an observer with
|
|
158
158
|
// onStart(kind, method, traceId, spanId, parentSpanId) and
|
|
159
159
|
// onEnd(kind, method, traceId, spanId, statusName). Generated code
|
|
@@ -194,17 +194,18 @@ function randomHex(bytes) {
|
|
|
194
194
|
return toHex(buf);
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
export function formatTraceparent(traceId, spanId) {
|
|
198
|
-
return `00-${traceId}-${spanId}
|
|
197
|
+
export function formatTraceparent(traceId, spanId, sampled = true) {
|
|
198
|
+
return `00-${traceId}-${spanId}-${sampled ? "01" : "00"}`;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
export function parseTraceparent(value) {
|
|
202
202
|
if (typeof value !== "string") return null;
|
|
203
203
|
const parts = value.split("-");
|
|
204
204
|
if (parts.length !== 4) return null;
|
|
205
|
-
const [, traceId, spanId] = parts;
|
|
205
|
+
const [, traceId, spanId, flags] = parts;
|
|
206
206
|
if (!/^[0-9a-f]{32}$/.test(traceId) || !/^[0-9a-f]{16}$/.test(spanId)) return null;
|
|
207
|
-
|
|
207
|
+
if (!/^[0-9a-f]{2}$/.test(flags)) return null;
|
|
208
|
+
return { traceId, spanId, sampled: (parseInt(flags, 16) & 1) === 1 };
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
export function traceStart(kind, method, parent) {
|
|
@@ -213,7 +214,12 @@ export function traceStart(kind, method, parent) {
|
|
|
213
214
|
traceId: parent ? parent.traceId : randomHex(16),
|
|
214
215
|
spanId: randomHex(8),
|
|
215
216
|
parentSpanId: parent ? parent.spanId : "",
|
|
217
|
+
sampled: parent ? parent.sampled : true,
|
|
218
|
+
startMs: Date.now(),
|
|
216
219
|
};
|
|
220
|
+
// An upstream not-sampled decision is honored: the context
|
|
221
|
+
// still propagates (with flags 00) but no span is recorded.
|
|
222
|
+
if (!ctx.sampled) return ctx;
|
|
217
223
|
try {
|
|
218
224
|
tracer.onStart?.(kind, method, ctx.traceId, ctx.spanId, ctx.parentSpanId);
|
|
219
225
|
} catch {
|
|
@@ -223,10 +229,23 @@ export function traceStart(kind, method, parent) {
|
|
|
223
229
|
}
|
|
224
230
|
|
|
225
231
|
export function traceEnd(kind, method, ctx, status) {
|
|
226
|
-
if (ctx === null || tracer === null) return;
|
|
232
|
+
if (ctx === null || tracer === null || ctx.sampled === false) return;
|
|
227
233
|
try {
|
|
228
|
-
tracer.onEnd?.(kind, method, ctx.traceId, ctx.spanId, status);
|
|
234
|
+
tracer.onEnd?.(kind, method, ctx.traceId, ctx.spanId, status, Date.now() - ctx.startMs);
|
|
229
235
|
} catch {
|
|
230
236
|
// observers must never break the call
|
|
231
237
|
}
|
|
232
238
|
}
|
|
239
|
+
|
|
240
|
+
// Start a root span context (e.g. for a client workflow grouping
|
|
241
|
+
// several outbound calls under one trace). Pair with traceEnd.
|
|
242
|
+
// Returns null when tracing is dormant.
|
|
243
|
+
export function newTraceContext(kind = "internal", method = "") {
|
|
244
|
+
return traceStart(kind, method, null);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// View a span context as a traceparent parent for an outbound call.
|
|
248
|
+
export function asTraceParent(ctx) {
|
|
249
|
+
if (!ctx) return null;
|
|
250
|
+
return { traceId: ctx.traceId, spanId: ctx.spanId, sampled: ctx.sampled !== false };
|
|
251
|
+
}
|
package/src/kafka_grpc_dc.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Generated code: use without restriction (see GENERATED-CODE-LICENSE.md).
|
|
2
2
|
// @generated by protoc-gen-grpc-dc-js. DO NOT EDIT.
|
|
3
3
|
// source: kafka.proto
|
|
4
|
-
import { MetadataRequest, MetadataResponse, OpenProducerRequest, OpenProducerResponse, CloseProducerRequest, CloseProducerResponse, EndTransactionRequest, EndTransactionResponse, ProduceRequest, ProduceResponse, ConsumeRequest, ConsumeResponse, GroupSubscribeRequest, GroupSubscribeResponse, ListOffsetsRequest, ListOffsetsResponse, CommitOffsetRequest, CommitOffsetResponse, FetchOffsetRequest, FetchOffsetResponse, CreateTopicsRequest, CreateTopicsResponse, DeleteTopicsRequest, DeleteTopicsResponse } from "./kafka_pb.js";
|
|
4
|
+
import { MetadataRequest, MetadataResponse, OpenProducerRequest, OpenProducerResponse, CloseProducerRequest, CloseProducerResponse, EndTransactionRequest, EndTransactionResponse, ProduceRequest, ProduceResponse, ConsumeRequest, ConsumeResponse, GroupSubscribeRequest, GroupSubscribeResponse, ListOffsetsRequest, ListOffsetsResponse, CommitOffsetRequest, CommitOffsetResponse, FetchOffsetRequest, FetchOffsetResponse, CreateTopicsRequest, CreateTopicsResponse, DeleteTopicsRequest, DeleteTopicsResponse, DescribeConfigsRequest, DescribeConfigsResponse, AlterConfigsRequest, AlterConfigsResponse, CreatePartitionsRequest, CreatePartitionsResponse, DeleteRecordsRequest, DeleteRecordsResponse, ListGroupsRequest, ListGroupsResponse, DescribeGroupsRequest, DescribeGroupsResponse, DeleteGroupsRequest, DeleteGroupsResponse, DeleteGroupOffsetsRequest, DeleteGroupOffsetsResponse, DescribeAclsRequest, DescribeAclsResponse, CreateAclsRequest, CreateAclsResponse, DeleteAclsRequest, DeleteAclsResponse, ListTransactionsRequest, ListTransactionsResponse, DescribeTransactionsRequest, DescribeTransactionsResponse, OpenShareGroupRequest, OpenShareGroupResponse, SharePollRequest, SharePollResponse, ShareAckRequest, ShareAckResponse, CloseShareGroupRequest, CloseShareGroupResponse } from "./kafka_pb.js";
|
|
5
5
|
|
|
6
6
|
export class KafkaClient {
|
|
7
7
|
#channel;
|
|
@@ -42,6 +42,57 @@ export class KafkaClient {
|
|
|
42
42
|
async deleteTopics(request, options) {
|
|
43
43
|
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/DeleteTopics", request, DeleteTopicsRequest, DeleteTopicsResponse, options);
|
|
44
44
|
}
|
|
45
|
+
async describeConfigs(request, options) {
|
|
46
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/DescribeConfigs", request, DescribeConfigsRequest, DescribeConfigsResponse, options);
|
|
47
|
+
}
|
|
48
|
+
async alterConfigs(request, options) {
|
|
49
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/AlterConfigs", request, AlterConfigsRequest, AlterConfigsResponse, options);
|
|
50
|
+
}
|
|
51
|
+
async createPartitions(request, options) {
|
|
52
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/CreatePartitions", request, CreatePartitionsRequest, CreatePartitionsResponse, options);
|
|
53
|
+
}
|
|
54
|
+
async deleteRecords(request, options) {
|
|
55
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/DeleteRecords", request, DeleteRecordsRequest, DeleteRecordsResponse, options);
|
|
56
|
+
}
|
|
57
|
+
async listGroups(request, options) {
|
|
58
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/ListGroups", request, ListGroupsRequest, ListGroupsResponse, options);
|
|
59
|
+
}
|
|
60
|
+
async describeGroups(request, options) {
|
|
61
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/DescribeGroups", request, DescribeGroupsRequest, DescribeGroupsResponse, options);
|
|
62
|
+
}
|
|
63
|
+
async deleteGroups(request, options) {
|
|
64
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/DeleteGroups", request, DeleteGroupsRequest, DeleteGroupsResponse, options);
|
|
65
|
+
}
|
|
66
|
+
async deleteGroupOffsets(request, options) {
|
|
67
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/DeleteGroupOffsets", request, DeleteGroupOffsetsRequest, DeleteGroupOffsetsResponse, options);
|
|
68
|
+
}
|
|
69
|
+
async describeAcls(request, options) {
|
|
70
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/DescribeAcls", request, DescribeAclsRequest, DescribeAclsResponse, options);
|
|
71
|
+
}
|
|
72
|
+
async createAcls(request, options) {
|
|
73
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/CreateAcls", request, CreateAclsRequest, CreateAclsResponse, options);
|
|
74
|
+
}
|
|
75
|
+
async deleteAcls(request, options) {
|
|
76
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/DeleteAcls", request, DeleteAclsRequest, DeleteAclsResponse, options);
|
|
77
|
+
}
|
|
78
|
+
async listTransactions(request, options) {
|
|
79
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/ListTransactions", request, ListTransactionsRequest, ListTransactionsResponse, options);
|
|
80
|
+
}
|
|
81
|
+
async describeTransactions(request, options) {
|
|
82
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/DescribeTransactions", request, DescribeTransactionsRequest, DescribeTransactionsResponse, options);
|
|
83
|
+
}
|
|
84
|
+
async openShareGroup(request, options) {
|
|
85
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/OpenShareGroup", request, OpenShareGroupRequest, OpenShareGroupResponse, options);
|
|
86
|
+
}
|
|
87
|
+
async sharePoll(request, options) {
|
|
88
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/SharePoll", request, SharePollRequest, SharePollResponse, options);
|
|
89
|
+
}
|
|
90
|
+
async shareAck(request, options) {
|
|
91
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/ShareAck", request, ShareAckRequest, ShareAckResponse, options);
|
|
92
|
+
}
|
|
93
|
+
async closeShareGroup(request, options) {
|
|
94
|
+
return this.#channel.unary("/grpcdc.kafka.v1.Kafka/CloseShareGroup", request, CloseShareGroupRequest, CloseShareGroupResponse, options);
|
|
95
|
+
}
|
|
45
96
|
}
|
|
46
97
|
|
|
47
98
|
export function createKafkaService(handlers) {
|
|
@@ -60,6 +111,23 @@ export function createKafkaService(handlers) {
|
|
|
60
111
|
FetchOffset: { path: "/grpcdc.kafka.v1.Kafka/FetchOffset", kind: "unary", requestType: FetchOffsetRequest, responseType: FetchOffsetResponse, handler: handlers.fetchOffset },
|
|
61
112
|
CreateTopics: { path: "/grpcdc.kafka.v1.Kafka/CreateTopics", kind: "unary", requestType: CreateTopicsRequest, responseType: CreateTopicsResponse, handler: handlers.createTopics },
|
|
62
113
|
DeleteTopics: { path: "/grpcdc.kafka.v1.Kafka/DeleteTopics", kind: "unary", requestType: DeleteTopicsRequest, responseType: DeleteTopicsResponse, handler: handlers.deleteTopics },
|
|
114
|
+
DescribeConfigs: { path: "/grpcdc.kafka.v1.Kafka/DescribeConfigs", kind: "unary", requestType: DescribeConfigsRequest, responseType: DescribeConfigsResponse, handler: handlers.describeConfigs },
|
|
115
|
+
AlterConfigs: { path: "/grpcdc.kafka.v1.Kafka/AlterConfigs", kind: "unary", requestType: AlterConfigsRequest, responseType: AlterConfigsResponse, handler: handlers.alterConfigs },
|
|
116
|
+
CreatePartitions: { path: "/grpcdc.kafka.v1.Kafka/CreatePartitions", kind: "unary", requestType: CreatePartitionsRequest, responseType: CreatePartitionsResponse, handler: handlers.createPartitions },
|
|
117
|
+
DeleteRecords: { path: "/grpcdc.kafka.v1.Kafka/DeleteRecords", kind: "unary", requestType: DeleteRecordsRequest, responseType: DeleteRecordsResponse, handler: handlers.deleteRecords },
|
|
118
|
+
ListGroups: { path: "/grpcdc.kafka.v1.Kafka/ListGroups", kind: "unary", requestType: ListGroupsRequest, responseType: ListGroupsResponse, handler: handlers.listGroups },
|
|
119
|
+
DescribeGroups: { path: "/grpcdc.kafka.v1.Kafka/DescribeGroups", kind: "unary", requestType: DescribeGroupsRequest, responseType: DescribeGroupsResponse, handler: handlers.describeGroups },
|
|
120
|
+
DeleteGroups: { path: "/grpcdc.kafka.v1.Kafka/DeleteGroups", kind: "unary", requestType: DeleteGroupsRequest, responseType: DeleteGroupsResponse, handler: handlers.deleteGroups },
|
|
121
|
+
DeleteGroupOffsets: { path: "/grpcdc.kafka.v1.Kafka/DeleteGroupOffsets", kind: "unary", requestType: DeleteGroupOffsetsRequest, responseType: DeleteGroupOffsetsResponse, handler: handlers.deleteGroupOffsets },
|
|
122
|
+
DescribeAcls: { path: "/grpcdc.kafka.v1.Kafka/DescribeAcls", kind: "unary", requestType: DescribeAclsRequest, responseType: DescribeAclsResponse, handler: handlers.describeAcls },
|
|
123
|
+
CreateAcls: { path: "/grpcdc.kafka.v1.Kafka/CreateAcls", kind: "unary", requestType: CreateAclsRequest, responseType: CreateAclsResponse, handler: handlers.createAcls },
|
|
124
|
+
DeleteAcls: { path: "/grpcdc.kafka.v1.Kafka/DeleteAcls", kind: "unary", requestType: DeleteAclsRequest, responseType: DeleteAclsResponse, handler: handlers.deleteAcls },
|
|
125
|
+
ListTransactions: { path: "/grpcdc.kafka.v1.Kafka/ListTransactions", kind: "unary", requestType: ListTransactionsRequest, responseType: ListTransactionsResponse, handler: handlers.listTransactions },
|
|
126
|
+
DescribeTransactions: { path: "/grpcdc.kafka.v1.Kafka/DescribeTransactions", kind: "unary", requestType: DescribeTransactionsRequest, responseType: DescribeTransactionsResponse, handler: handlers.describeTransactions },
|
|
127
|
+
OpenShareGroup: { path: "/grpcdc.kafka.v1.Kafka/OpenShareGroup", kind: "unary", requestType: OpenShareGroupRequest, responseType: OpenShareGroupResponse, handler: handlers.openShareGroup },
|
|
128
|
+
SharePoll: { path: "/grpcdc.kafka.v1.Kafka/SharePoll", kind: "unary", requestType: SharePollRequest, responseType: SharePollResponse, handler: handlers.sharePoll },
|
|
129
|
+
ShareAck: { path: "/grpcdc.kafka.v1.Kafka/ShareAck", kind: "unary", requestType: ShareAckRequest, responseType: ShareAckResponse, handler: handlers.shareAck },
|
|
130
|
+
CloseShareGroup: { path: "/grpcdc.kafka.v1.Kafka/CloseShareGroup", kind: "unary", requestType: CloseShareGroupRequest, responseType: CloseShareGroupResponse, handler: handlers.closeShareGroup },
|
|
63
131
|
},
|
|
64
132
|
};
|
|
65
133
|
}
|