@numbunch/node 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Numbunch contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,122 @@
1
+ import { type OtelApi } from './context.js';
2
+ import { type FlagValue } from './evaluate.js';
3
+ import { type Properties } from './matching.js';
4
+ export interface NumbunchOptions {
5
+ /** Ingestion host (where `/batch/`, `/flags/` and `/v1/flags/definitions` live). */
6
+ host?: string;
7
+ /** The environment's `nb_sec_` secret. Enables local flag evaluation. Never ship it to a browser. */
8
+ secretKey?: string;
9
+ /** Send a batch once this many events are queued. */
10
+ flushAt?: number;
11
+ /** Send queued events at least this often. */
12
+ flushIntervalMs?: number;
13
+ /** Events beyond this are dropped (and reported to `onError`). */
14
+ maxQueueSize?: number;
15
+ /** How often flag definitions are re-fetched (with `If-None-Match`). */
16
+ pollIntervalMs?: number;
17
+ requestTimeoutMs?: number;
18
+ /** Retries of a failed batch (network errors, 5xx, 429), with exponential backoff and jitter. */
19
+ maxRetries?: number;
20
+ /** First retry delay; doubles per attempt. */
21
+ retryBaseDelayMs?: number;
22
+ /** Capture nothing and make no requests. */
23
+ disabled?: boolean;
24
+ fetch?: typeof fetch;
25
+ onError?: (error: unknown) => void;
26
+ /** `@opentelemetry/api`, if it should not be imported lazily. */
27
+ opentelemetry?: OtelApi;
28
+ }
29
+ export interface CaptureMessage {
30
+ /** Defaults to the distinct ID of the current `withRequestContext`. */
31
+ distinctId?: string;
32
+ event: string;
33
+ properties?: Properties;
34
+ /** Group type name → key. */
35
+ groups?: Record<string, string | number>;
36
+ /** Explicit event UUID, for idempotent server events (the server deduplicates on it). */
37
+ uuid?: string;
38
+ timestamp?: Date | string;
39
+ /** Add `$feature/{key}` for every locally evaluable flag. */
40
+ sendFeatureFlags?: boolean;
41
+ }
42
+ export interface FlagOptions {
43
+ personProperties?: Properties;
44
+ groups?: Record<string, string | number>;
45
+ groupProperties?: Record<string, Properties>;
46
+ /** Never ask the server; return undefined for flags that cannot be evaluated locally. */
47
+ onlyEvaluateLocally?: boolean;
48
+ /** Capture `$feature_flag_called` (once per distinct ID, flag and value). Default true. */
49
+ sendFeatureFlagEvents?: boolean;
50
+ }
51
+ /** What the browser SDK accepts as its `bootstrap` option, so server-rendered pages need no flag request. */
52
+ export interface Bootstrap {
53
+ distinctId?: string;
54
+ isIdentified?: boolean;
55
+ flags?: Record<string, FlagValue>;
56
+ }
57
+ export declare class Numbunch {
58
+ readonly apiKey: string;
59
+ readonly host: string;
60
+ private readonly options;
61
+ private readonly fetchImpl;
62
+ private queue;
63
+ private flushTimer;
64
+ private flushing;
65
+ private pollTimer;
66
+ private definitions;
67
+ private flagsByKey;
68
+ private etag;
69
+ private definitionsLoaded;
70
+ private readonly calledSent;
71
+ private closed;
72
+ constructor(apiKey: string, options?: NumbunchOptions);
73
+ capture(message: CaptureMessage): void;
74
+ /** `$identify` with `$set` (and `$set_once` from `propertiesOnce`). */
75
+ identify({ distinctId, properties, propertiesOnce }: {
76
+ distinctId: string;
77
+ properties?: Properties;
78
+ propertiesOnce?: Properties;
79
+ }): void;
80
+ /** `$groupidentify`: sets properties on a group. */
81
+ groupIdentify({ groupType, groupKey, properties, distinctId, }: {
82
+ groupType: string;
83
+ groupKey: string;
84
+ properties?: Properties;
85
+ distinctId?: string;
86
+ }): void;
87
+ /** `$exception` with `$exception_list` (the server fingerprints and symbolicates it). */
88
+ captureException(error: unknown, distinctId?: string, properties?: Properties, handled?: boolean): void;
89
+ /**
90
+ * Captures uncaught exceptions and unhandled rejections. When no other listener handles them, the process still
91
+ * exits with code 1 after the events are flushed, as it would without the SDK. Returns a function that removes
92
+ * the hooks.
93
+ */
94
+ enableExceptionAutocapture(): () => void;
95
+ private enqueue;
96
+ /** Sends every queued event. Resolves when they are sent (or given up on). */
97
+ flush(): Promise<void>;
98
+ private send;
99
+ /** Flushes, stops polling and refuses further events. */
100
+ shutdown(): Promise<void>;
101
+ /** Resolves once the first definitions request has finished (successfully or not). */
102
+ waitForDefinitions(): Promise<void>;
103
+ /** Re-fetches definitions now (with `If-None-Match`). */
104
+ loadDefinitions(): Promise<void>;
105
+ getFeatureFlag(key: string, distinctId: string, options?: FlagOptions): Promise<FlagValue | undefined>;
106
+ isFeatureEnabled(key: string, distinctId: string, options?: FlagOptions): Promise<boolean | undefined>;
107
+ getFeatureFlagPayload(key: string, distinctId: string, options?: FlagOptions): Promise<unknown>;
108
+ /** Every flag for `distinctId`: local where possible, one remote call for the rest (unless `onlyEvaluateLocally`). */
109
+ getAllFlags(distinctId: string, options?: FlagOptions): Promise<Record<string, FlagValue>>;
110
+ /** A bootstrap object for the browser SDK, so a server-rendered page has every flag before any request. */
111
+ getBootstrap(distinctId: string, options?: FlagOptions & {
112
+ isIdentified?: boolean;
113
+ }): Promise<Bootstrap>;
114
+ private flag;
115
+ /** The local value, or undefined when only the server can decide. */
116
+ private local;
117
+ private remote;
118
+ private featureProperties;
119
+ private flagCalled;
120
+ private request;
121
+ private report;
122
+ }
package/dist/client.js ADDED
@@ -0,0 +1,395 @@
1
+ // The Numbunch Node.js client: batched capture in PostHog's wire format, local flag evaluation from
2
+ // `GET /v1/flags/definitions` (both bucketing algorithms) with remote fallback, exceptions and trace context.
3
+ //
4
+ // The capture and flag request shapes follow posthog-node 4.11.2 (MIT, Copyright (c) PostHog Inc.), because the
5
+ // server is PostHog-compatible.
6
+ import { activeTrace, currentRequestContext, loadOtel, useOtel } from './context.js';
7
+ import { decodePayload, evaluateLocally, payloadFor, } from './evaluate.js';
8
+ import { exceptionList } from './exceptions.js';
9
+ import { InconclusiveMatchError } from './matching.js';
10
+ import { uuidv7 } from './uuid.js';
11
+ import { VERSION } from './version.js';
12
+ const DEDUP_LIMIT = 50_000;
13
+ export class Numbunch {
14
+ apiKey;
15
+ host;
16
+ options;
17
+ fetchImpl;
18
+ queue = [];
19
+ flushTimer;
20
+ flushing = Promise.resolve();
21
+ pollTimer;
22
+ definitions;
23
+ flagsByKey = new Map();
24
+ etag;
25
+ definitionsLoaded = Promise.resolve();
26
+ calledSent = new Set();
27
+ closed = false;
28
+ constructor(apiKey, options = {}) {
29
+ this.apiKey = apiKey;
30
+ this.host = (options.host ?? 'https://in.numbunch.com').replace(/\/+$/, '');
31
+ this.options = {
32
+ flushAt: 100,
33
+ flushIntervalMs: 10_000,
34
+ maxQueueSize: 10_000,
35
+ pollIntervalMs: 30_000,
36
+ requestTimeoutMs: 10_000,
37
+ maxRetries: 3,
38
+ retryBaseDelayMs: 500,
39
+ ...stripUndefined(options),
40
+ };
41
+ this.fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
42
+ if (options.opentelemetry)
43
+ useOtel(options.opentelemetry);
44
+ else
45
+ void loadOtel();
46
+ if (options.secretKey && !options.disabled) {
47
+ this.definitionsLoaded = this.loadDefinitions();
48
+ this.pollTimer = setInterval(() => void this.loadDefinitions(), this.options.pollIntervalMs);
49
+ this.pollTimer.unref?.();
50
+ }
51
+ }
52
+ // --- Capture ---------------------------------------------------------------------------------------------------
53
+ capture(message) {
54
+ const context = currentRequestContext();
55
+ const distinctId = message.distinctId ?? context?.distinctId;
56
+ if (!distinctId) {
57
+ this.report(new Error(`capture(${message.event}): no distinctId`));
58
+ return;
59
+ }
60
+ const properties = { ...(message.properties ?? {}) };
61
+ if (message.groups)
62
+ properties.$groups = message.groups;
63
+ if (context?.sessionId && properties.$session_id === undefined)
64
+ properties.$session_id = context.sessionId;
65
+ const trace = activeTrace();
66
+ if (trace && properties.$trace_id === undefined) {
67
+ properties.$trace_id = trace.traceId;
68
+ properties.$span_id = trace.spanId;
69
+ }
70
+ if (message.sendFeatureFlags)
71
+ Object.assign(properties, this.featureProperties(distinctId, message.groups));
72
+ this.enqueue({
73
+ event: message.event,
74
+ distinct_id: distinctId,
75
+ properties,
76
+ timestamp: toIso(message.timestamp),
77
+ uuid: message.uuid ?? uuidv7(),
78
+ });
79
+ }
80
+ /** `$identify` with `$set` (and `$set_once` from `propertiesOnce`). */
81
+ identify({ distinctId, properties, propertiesOnce }) {
82
+ const props = { $set: properties ?? {} };
83
+ if (propertiesOnce)
84
+ props.$set_once = propertiesOnce;
85
+ this.capture({ distinctId, event: '$identify', properties: props });
86
+ }
87
+ /** `$groupidentify`: sets properties on a group. */
88
+ groupIdentify({ groupType, groupKey, properties, distinctId, }) {
89
+ this.capture({
90
+ distinctId: distinctId ?? `$${groupType}_${groupKey}`,
91
+ event: '$groupidentify',
92
+ properties: { $group_type: groupType, $group_key: groupKey, $group_set: properties ?? {} },
93
+ });
94
+ }
95
+ /** `$exception` with `$exception_list` (the server fingerprints and symbolicates it). */
96
+ captureException(error, distinctId, properties = {}, handled = true) {
97
+ const list = exceptionList(error, handled);
98
+ const id = distinctId ?? currentRequestContext()?.distinctId;
99
+ this.capture({
100
+ distinctId: id ?? uuidv7(),
101
+ event: '$exception',
102
+ properties: {
103
+ ...(id ? {} : { $process_person_profile: false }),
104
+ $exception_list: list,
105
+ $exception_level: 'error',
106
+ ...properties,
107
+ },
108
+ });
109
+ }
110
+ /**
111
+ * Captures uncaught exceptions and unhandled rejections. When no other listener handles them, the process still
112
+ * exits with code 1 after the events are flushed, as it would without the SDK. Returns a function that removes
113
+ * the hooks.
114
+ */
115
+ enableExceptionAutocapture() {
116
+ const fatal = (error, kind) => {
117
+ this.captureException(error, undefined, { $exception_source: kind }, false);
118
+ if (process.listenerCount(kind) > 1)
119
+ return;
120
+ // Without other listeners Node would print the error and exit; do the same once the event is sent.
121
+ process.stderr.write(`${error instanceof Error ? (error.stack ?? String(error)) : String(error)}\n`);
122
+ const exit = () => process.exit(1);
123
+ void Promise.race([this.shutdown(), new Promise((r) => setTimeout(r, 3000).unref?.())]).then(exit, exit);
124
+ };
125
+ const onException = (error) => fatal(error, 'uncaughtException');
126
+ const onRejection = (reason) => fatal(reason, 'unhandledRejection');
127
+ process.on('uncaughtException', onException);
128
+ process.on('unhandledRejection', onRejection);
129
+ return () => {
130
+ process.off('uncaughtException', onException);
131
+ process.off('unhandledRejection', onRejection);
132
+ };
133
+ }
134
+ enqueue(event) {
135
+ if (this.options.disabled || this.closed)
136
+ return;
137
+ if (this.queue.length >= this.options.maxQueueSize) {
138
+ this.report(new Error(`queue full (${this.options.maxQueueSize}); dropped ${event.event}`));
139
+ return;
140
+ }
141
+ event.properties = { $lib: 'numbunch-node', $lib_version: VERSION, ...event.properties };
142
+ this.queue.push({ ...event, type: 'capture', library: 'numbunch-node', library_version: VERSION });
143
+ if (this.queue.length >= this.options.flushAt) {
144
+ void this.flush();
145
+ }
146
+ else if (!this.flushTimer) {
147
+ this.flushTimer = setTimeout(() => {
148
+ this.flushTimer = undefined;
149
+ void this.flush();
150
+ }, this.options.flushIntervalMs);
151
+ this.flushTimer.unref?.();
152
+ }
153
+ }
154
+ /** Sends every queued event. Resolves when they are sent (or given up on). */
155
+ flush() {
156
+ if (this.flushTimer) {
157
+ clearTimeout(this.flushTimer);
158
+ this.flushTimer = undefined;
159
+ }
160
+ this.flushing = this.flushing.then(async () => {
161
+ while (this.queue.length > 0) {
162
+ const batch = this.queue.splice(0, Math.max(1, Math.min(this.options.flushAt, 1000)));
163
+ try {
164
+ await this.send(batch);
165
+ }
166
+ catch (error) {
167
+ this.report(error);
168
+ }
169
+ }
170
+ });
171
+ return this.flushing;
172
+ }
173
+ async send(batch) {
174
+ const body = JSON.stringify({ api_key: this.apiKey, batch, sent_at: new Date().toISOString() });
175
+ for (let attempt = 0;; attempt++) {
176
+ let retryable;
177
+ let failure;
178
+ try {
179
+ const res = await this.request(`${this.host}/batch/`, {
180
+ method: 'POST',
181
+ headers: { 'content-type': 'application/json' },
182
+ body,
183
+ });
184
+ if (res.ok)
185
+ return;
186
+ retryable = res.status >= 500 || res.status === 429;
187
+ failure = new Error(`POST /batch/: ${res.status} ${await res.text().catch(() => '')}`);
188
+ }
189
+ catch (error) {
190
+ retryable = true;
191
+ failure = error;
192
+ }
193
+ if (!retryable || attempt >= this.options.maxRetries)
194
+ throw failure;
195
+ const delay = this.options.retryBaseDelayMs * 2 ** attempt;
196
+ await sleep(delay / 2 + Math.random() * (delay / 2));
197
+ }
198
+ }
199
+ /** Flushes, stops polling and refuses further events. */
200
+ async shutdown() {
201
+ if (this.pollTimer)
202
+ clearInterval(this.pollTimer);
203
+ this.pollTimer = undefined;
204
+ await this.flush();
205
+ this.closed = true;
206
+ }
207
+ // --- Flags -----------------------------------------------------------------------------------------------------
208
+ /** Resolves once the first definitions request has finished (successfully or not). */
209
+ waitForDefinitions() {
210
+ return this.definitionsLoaded;
211
+ }
212
+ /** Re-fetches definitions now (with `If-None-Match`). */
213
+ async loadDefinitions() {
214
+ if (!this.options.secretKey)
215
+ return;
216
+ try {
217
+ const headers = { authorization: `Bearer ${this.options.secretKey}` };
218
+ if (this.etag)
219
+ headers['if-none-match'] = this.etag;
220
+ const res = await this.request(`${this.host}/v1/flags/definitions`, { headers });
221
+ if (res.status === 304)
222
+ return;
223
+ if (!res.ok)
224
+ throw new Error(`GET /v1/flags/definitions: ${res.status} ${await res.text().catch(() => '')}`);
225
+ const definitions = (await res.json());
226
+ this.definitions = definitions;
227
+ this.flagsByKey = new Map(definitions.flags.map((f) => [f.key, f]));
228
+ this.etag = res.headers.get('etag') ?? undefined;
229
+ }
230
+ catch (error) {
231
+ this.report(error);
232
+ }
233
+ }
234
+ async getFeatureFlag(key, distinctId, options = {}) {
235
+ const result = await this.flag(key, distinctId, options);
236
+ if (result && options.sendFeatureFlagEvents !== false) {
237
+ this.flagCalled(distinctId, key, result.value, result.locally, result.version);
238
+ }
239
+ return result?.value;
240
+ }
241
+ async isFeatureEnabled(key, distinctId, options = {}) {
242
+ const value = await this.getFeatureFlag(key, distinctId, options);
243
+ return value === undefined ? undefined : value !== false;
244
+ }
245
+ async getFeatureFlagPayload(key, distinctId, options = {}) {
246
+ const result = await this.flag(key, distinctId, options);
247
+ return result?.payload;
248
+ }
249
+ /** Every flag for `distinctId`: local where possible, one remote call for the rest (unless `onlyEvaluateLocally`). */
250
+ async getAllFlags(distinctId, options = {}) {
251
+ await this.definitionsLoaded;
252
+ const out = {};
253
+ let needsRemote = !this.definitions;
254
+ for (const flag of this.definitions?.flags ?? []) {
255
+ const value = this.local(flag, distinctId, options);
256
+ if (value === undefined)
257
+ needsRemote = true;
258
+ else
259
+ out[flag.key] = value;
260
+ }
261
+ if (needsRemote && !options.onlyEvaluateLocally) {
262
+ const remote = await this.remote(distinctId, options);
263
+ for (const [key, flag] of Object.entries(remote ?? {})) {
264
+ if (!(key in out) && (!this.definitions || this.flagsByKey.has(key)))
265
+ out[key] = remoteValue(flag);
266
+ }
267
+ }
268
+ return out;
269
+ }
270
+ /** A bootstrap object for the browser SDK, so a server-rendered page has every flag before any request. */
271
+ async getBootstrap(distinctId, options = {}) {
272
+ const flags = await this.getAllFlags(distinctId, options);
273
+ const out = { distinctId, flags };
274
+ if (options.isIdentified !== undefined)
275
+ out.isIdentified = options.isIdentified;
276
+ return out;
277
+ }
278
+ async flag(key, distinctId, options) {
279
+ await this.definitionsLoaded;
280
+ const flag = this.flagsByKey.get(key);
281
+ if (flag) {
282
+ const value = this.local(flag, distinctId, options);
283
+ if (value !== undefined) {
284
+ const out = { value, payload: payloadFor(flag, value), locally: true };
285
+ return flag.version === undefined ? out : { ...out, version: flag.version };
286
+ }
287
+ }
288
+ if (options.onlyEvaluateLocally)
289
+ return undefined;
290
+ const remote = await this.remote(distinctId, options);
291
+ const found = remote?.[key];
292
+ if (!found)
293
+ return undefined;
294
+ const value = remoteValue(found);
295
+ const out = { value, payload: value === false ? undefined : decodePayload(found.metadata?.payload ?? undefined), locally: false };
296
+ return found.metadata?.version === undefined ? out : { ...out, version: found.metadata.version };
297
+ }
298
+ /** The local value, or undefined when only the server can decide. */
299
+ local(flag, distinctId, options) {
300
+ const input = { distinctId };
301
+ if (options.personProperties)
302
+ input.personProperties = options.personProperties;
303
+ if (options.groups)
304
+ input.groups = options.groups;
305
+ if (options.groupProperties)
306
+ input.groupProperties = options.groupProperties;
307
+ try {
308
+ return evaluateLocally(flag, this.definitions?.group_type_mapping ?? {}, input);
309
+ }
310
+ catch (error) {
311
+ if (error instanceof InconclusiveMatchError)
312
+ return undefined;
313
+ this.report(error);
314
+ return undefined;
315
+ }
316
+ }
317
+ async remote(distinctId, options) {
318
+ if (this.options.disabled)
319
+ return undefined;
320
+ try {
321
+ const res = await this.request(`${this.host}/flags/?v=2`, {
322
+ method: 'POST',
323
+ headers: { 'content-type': 'application/json' },
324
+ body: JSON.stringify({
325
+ token: this.apiKey,
326
+ distinct_id: distinctId,
327
+ person_properties: options.personProperties ?? {},
328
+ groups: options.groups ?? {},
329
+ group_properties: options.groupProperties ?? {},
330
+ }),
331
+ });
332
+ if (!res.ok)
333
+ throw new Error(`POST /flags/: ${res.status} ${await res.text().catch(() => '')}`);
334
+ const body = (await res.json());
335
+ return body.flags ?? {};
336
+ }
337
+ catch (error) {
338
+ this.report(error);
339
+ return undefined;
340
+ }
341
+ }
342
+ featureProperties(distinctId, groups) {
343
+ const out = {};
344
+ const active = [];
345
+ for (const flag of this.definitions?.flags ?? []) {
346
+ const value = this.local(flag, distinctId, groups ? { groups } : {});
347
+ if (value === undefined)
348
+ continue;
349
+ out[`$feature/${flag.key}`] = value;
350
+ if (value !== false)
351
+ active.push(flag.key);
352
+ }
353
+ if (this.definitions)
354
+ out.$active_feature_flags = active;
355
+ return out;
356
+ }
357
+ flagCalled(distinctId, key, value, locally, version) {
358
+ const dedup = `${distinctId}\u0000${key}\u0000${String(value)}`;
359
+ if (this.calledSent.has(dedup))
360
+ return;
361
+ if (this.calledSent.size >= DEDUP_LIMIT)
362
+ this.calledSent.clear();
363
+ this.calledSent.add(dedup);
364
+ const properties = {
365
+ $feature_flag: key,
366
+ $feature_flag_response: value,
367
+ [`$feature/${key}`]: value,
368
+ locally_evaluated: locally,
369
+ };
370
+ if (version !== undefined)
371
+ properties.$feature_flag_version = version;
372
+ this.capture({ distinctId, event: '$feature_flag_called', properties });
373
+ }
374
+ // --- Plumbing --------------------------------------------------------------------------------------------------
375
+ async request(url, init) {
376
+ return this.fetchImpl(url, { ...init, signal: AbortSignal.timeout(this.options.requestTimeoutMs) });
377
+ }
378
+ report(error) {
379
+ if (this.options.onError)
380
+ this.options.onError(error);
381
+ }
382
+ }
383
+ function remoteValue(flag) {
384
+ return flag.variant ?? flag.enabled ?? false;
385
+ }
386
+ function toIso(timestamp) {
387
+ if (timestamp === undefined)
388
+ return new Date().toISOString();
389
+ return typeof timestamp === 'string' ? timestamp : timestamp.toISOString();
390
+ }
391
+ function stripUndefined(value) {
392
+ return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
393
+ }
394
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
395
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","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2
+ export interface OtelApi {
3
+ trace: {
4
+ getActiveSpan(): OtelSpan | undefined;
5
+ };
6
+ context: {
7
+ active(): unknown;
8
+ with<T>(context: unknown, fn: () => T): T;
9
+ };
10
+ propagation: {
11
+ getBaggage(context: unknown): OtelBaggage | undefined;
12
+ createBaggage(entries?: Record<string, {
13
+ value: string;
14
+ }>): OtelBaggage;
15
+ setBaggage(context: unknown, baggage: OtelBaggage): unknown;
16
+ };
17
+ }
18
+ export interface OtelSpan {
19
+ spanContext(): {
20
+ traceId: string;
21
+ spanId: string;
22
+ traceFlags: number;
23
+ };
24
+ setAttribute(key: string, value: string): unknown;
25
+ }
26
+ export interface OtelBaggage {
27
+ setEntry(key: string, entry: {
28
+ value: string;
29
+ }): OtelBaggage;
30
+ }
31
+ /** Loads `@opentelemetry/api` once if it is installed. Resolves to undefined otherwise. */
32
+ export declare function loadOtel(): Promise<OtelApi | undefined>;
33
+ /** Uses an explicitly passed `@opentelemetry/api` instead of the lazily imported one. */
34
+ export declare function useOtel(api: OtelApi): void;
35
+ /** `$trace_id` and `$span_id` of the active span, if OpenTelemetry is loaded and a valid span is active. */
36
+ export declare function activeTrace(): {
37
+ traceId: string;
38
+ spanId: string;
39
+ } | undefined;
40
+ /** Header containers: Node's `IncomingHttpHeaders`, a fetch `Headers`, or a plain record. */
41
+ export type HeadersLike = {
42
+ get(name: string): string | null | undefined;
43
+ } | Record<string, string | string[] | undefined>;
44
+ export interface RequestContext {
45
+ /** The browser's session ID (`session.id` baggage). */
46
+ sessionId?: string;
47
+ /** The browser's distinct ID (`user.id` baggage). */
48
+ distinctId?: string;
49
+ }
50
+ /** Parses a W3C `baggage` header into its entries (values percent-decoded, properties dropped). */
51
+ export declare function parseBaggage(value: string | undefined): Record<string, string>;
52
+ /** The session and distinct ID the browser SDK put in the request's `baggage` header. */
53
+ export declare function requestContext(headers: HeadersLike): RequestContext;
54
+ /** The request context of the current async context, if inside `withRequestContext`. */
55
+ export declare function currentRequestContext(): RequestContext | undefined;
56
+ /**
57
+ * Runs `fn` with the request's session and distinct ID as the defaults for captured events. With OpenTelemetry, also
58
+ * sets `session.id`/`user.id` on the active span and in the baggage of the context `fn` runs in.
59
+ */
60
+ export declare function withRequestContext<T>(headers: HeadersLike | RequestContext, fn: () => T): T;