@flareapp/core 2.10.0 → 2.12.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/dist/index.cjs CHANGED
@@ -26,17 +26,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  }) : target, mod));
27
27
 
28
28
  //#endregion
29
- const require_urlAttributes = require('./urlAttributes-B37JykP3.cjs');
29
+ const require_urlAttributes = require('./urlAttributes-D0eXRrGm.cjs');
30
30
  let error_stack_parser = require("error-stack-parser");
31
31
  error_stack_parser = __toESM(error_stack_parser);
32
32
 
33
33
  //#region src/framework.ts
34
34
  /**
35
- * Framework names the Flare backend recognises. Wire format, so the values never change: they ship as
36
- * `flare.framework.name` and (lowercased) as `context.custom.framework`.
35
+ * Framework names the Flare backend recognizes. Wire format: these values never change, since they
36
+ * ship as `flare.framework.name` and (lowercased) as `context.custom.framework`.
37
37
  *
38
- * `Js` and `Node` are the base SDKs' fallback claim, overwritten when a framework package tags its
39
- * own name. `NodeElectron` is an Electron main process; its renderers report their own.
38
+ * `Js` and `Node` are fallback claims from the base SDKs, overwritten when a framework package sets
39
+ * its own name. `NodeElectron` is the Electron main process; renderers report their own name.
40
40
  */
41
41
  const FrameworkName = {
42
42
  Js: "js",
@@ -52,7 +52,7 @@ const FrameworkName = {
52
52
  //#endregion
53
53
  //#region src/spanTypes.ts
54
54
  /**
55
- * Span types the Flare backend recognises. Wire format, so the values never change: they ship as the
55
+ * Span types the Flare backend recognizes. Wire format, so the values never change: they ship as the
56
56
  * `flare.span_type` attribute and the backend groups performance data by them.
57
57
  *
58
58
  * These are the browser client's set. They live in core because core's `SpanOptions.spanType` needs
@@ -66,6 +66,10 @@ const BrowserSpanType = {
66
66
  Component: "browser_component",
67
67
  WebVital: "browser_web_vital"
68
68
  };
69
+ /**
70
+ * Span event types on an error report. Kept apart from `BrowserSpanType`: these are points in time,
71
+ * not spans with a duration. That is also why a route change is not called `browser_navigation`.
72
+ */
69
73
  const BrowserSpanEventType = {
70
74
  Click: "browser_click",
71
75
  Input: "browser_input",
@@ -84,7 +88,6 @@ const SpanStatusCode = {
84
88
  //#endregion
85
89
  //#region src/util/utf8Bytes.ts
86
90
  const textEncoder = new TextEncoder();
87
- /** UTF-8 byte length of `value`. */
88
91
  function utf8Bytes(value) {
89
92
  return textEncoder.encode(value).length;
90
93
  }
@@ -98,8 +101,7 @@ var Api = class {
98
101
  pendingKeepaliveRequests = 0;
99
102
  /**
100
103
  * How many keepalive bytes are still available. Logs and traces share one browser allowance and both
101
- * flush on page hide, so whichever goes second has to pack against what is left rather than assume the
102
- * whole budget, or it exceeds the gate in send() and silently degrades to a cancellable fetch.
104
+ * flush on page hide, so whichever goes second must pack against what is left, not the whole budget.
103
105
  */
104
106
  keepaliveBudgetRemaining() {
105
107
  if (this.pendingKeepaliveRequests >= MAX_PENDING_KEEPALIVE_REQUESTS) return 0;
@@ -199,11 +201,6 @@ function recordBreadcrumb(scopeProvider, config, type, attributes, startTimeUnix
199
201
 
200
202
  //#endregion
201
203
  //#region src/telemetry/TelemetryBuffer.ts
202
- /**
203
- * The batching machine behind both telemetry signals: hold records, ship them when a size, weight or time
204
- * trigger fires, and shed the oldest when nothing can drain. One instance owns one signal; what that signal
205
- * is comes entirely from the policy.
206
- */
207
204
  var TelemetryBuffer = class {
208
205
  entries = [];
209
206
  bufferedBytes = 0;
@@ -313,11 +310,6 @@ var TelemetryBuffer = class {
313
310
  if (dropped) this.bufferedBytes -= dropped.bytes;
314
311
  }
315
312
  }
316
- /**
317
- * Newest-wins. An over-budget record is skipped, not a stop signal, so a smaller older record behind a fat
318
- * one still ships. Runs on visibilitychange:hidden, which fires on plain backgrounding too, so the tail this
319
- * leaves behind is retained and re-armed rather than dropped (see flush).
320
- */
321
313
  packForKeepalive(config, resource) {
322
314
  const fixedBytes = this.policy.emptyEnvelopeBytes(resource);
323
315
  const budget = Math.min(config.keepaliveMaxBytes, this.policy.keepaliveBudget?.(config) ?? config.keepaliveMaxBytes);
@@ -346,11 +338,6 @@ var TelemetryBuffer = class {
346
338
 
347
339
  //#endregion
348
340
  //#region src/telemetry/resourceIdentity.ts
349
- /**
350
- * Builds the attributes that go on every logs or traces envelope: the caller's own attributes in `base`, with
351
- * our SDK, service and framework identity on top. Our keys win, so a user value cannot overwrite something
352
- * like `telemetry.sdk.name`.
353
- */
354
341
  function buildResourceIdentity(base, config, sdk, framework) {
355
342
  const identity = {
356
343
  "telemetry.sdk.language": "javascript",
@@ -371,18 +358,6 @@ function buildResourceIdentity(base, config, sdk, framework) {
371
358
 
372
359
  //#endregion
373
360
  //#region src/logging/otel.ts
374
- /**
375
- * Converts one attribute value into the OpenTelemetry `AnyValue` shape. Strings, numbers and booleans become
376
- * leaves, arrays and objects are walked recursively. Anything OpenTelemetry cannot carry (null, undefined,
377
- * NaN, functions) returns null and the caller drops that key.
378
- *
379
- * A value that contains itself becomes the string `[Circular]`. `inPath` only holds the parents of the value
380
- * being converted right now, so the same object used twice side by side is converted twice instead of being
381
- * wrongly called circular.
382
- *
383
- * The walk also stops at a maximum depth and a maximum number of nodes, see traversalBudget.ts. Pass `budget`
384
- * to let several calls share one allowance, otherwise every call gets its own.
385
- */
386
361
  function valueToOpenTelemetry(value, inPath = /* @__PURE__ */ new WeakSet(), budget = require_urlAttributes.createTraversalBudget()) {
387
362
  return convert(value, inPath, 0, budget);
388
363
  }
@@ -467,17 +442,9 @@ function buildLogsEnvelope(records, resourceAttributes, scopeName, scopeVersion)
467
442
  }]
468
443
  }] };
469
444
  }
470
- /**
471
- * How many UTF-8 bytes one record adds to an envelope. We measure the real toOtelLogRecord output instead of
472
- * reusing the cached BufferedLog estimate, because keepaliveMaxBytes is a hard browser limit and an estimate
473
- * is not good enough.
474
- *
475
- * Uses flatJsonStringify to match Api.logs, which sends the envelope through the same encoder.
476
- */
477
445
  function otelLogRecordBytes(record) {
478
446
  return utf8Bytes(require_urlAttributes.flatJsonStringify(toOtelLogRecord(record)));
479
447
  }
480
- /** UTF-8 bytes of an empty envelope: the fixed overhead every batch has, before any records are added. */
481
448
  function emptyLogsEnvelopeBytes(resourceAttributes, scopeName, scopeVersion) {
482
449
  return utf8Bytes(require_urlAttributes.flatJsonStringify(buildLogsEnvelope([], resourceAttributes, scopeName, scopeVersion)));
483
450
  }
@@ -618,6 +585,8 @@ const RESOURCE_PREFIXES = [
618
585
  "host.",
619
586
  "os.",
620
587
  "process.",
588
+ "device.",
589
+ "network.",
621
590
  "flare.framework.",
622
591
  "flare.language."
623
592
  ];
@@ -635,7 +604,6 @@ function partitionAttributes(attributes) {
635
604
 
636
605
  //#endregion
637
606
  //#region src/Scope.ts
638
- /** `USER_IDENTITY_KEYS` derives from this, so adding a field here can never leave the clear pass stale. */
639
607
  const USER_FIELD_KEYS = {
640
608
  id: "user.id",
641
609
  email: "user.email",
@@ -815,11 +783,9 @@ function isApplicationFrame(fileName) {
815
783
  //#endregion
816
784
  //#region src/stacktrace/NullFileReader.ts
817
785
  /**
818
- * No-op `FileReader` returning `null` for every URL. Default for `Flare`'s `fileReader` param so `new Flare()` builds
819
- * reports without picking an environment; stack frames just omit source snippets. Consumer packages inject the real
820
- * ones: `@flareapp/js` a fetch-based reader, `@flareapp/node` a disk reader. The `read(url) -> Promise<string | null>`
821
- * interface lets the stack-trace builder treat all three the same (render on text, skip on null), so core needs no
822
- * environment checks.
786
+ * No-op `FileReader` returning `null` for every URL. Default for `Flare`'s `fileReader` param, so
787
+ * `new Flare()` builds reports without picking an environment; stack frames just omit source snippets.
788
+ * `@flareapp/js` and `@flareapp/node` inject a real fetch- or disk-based reader instead.
823
789
  */
824
790
  var NullFileReader = class {
825
791
  read(_url) {
@@ -1005,28 +971,15 @@ function buildTracesEnvelope(spans, resourceAttributes, scopeName, scopeVersion)
1005
971
  }]
1006
972
  }] };
1007
973
  }
1008
- /**
1009
- * How many UTF-8 bytes one span adds to an envelope. We measure the real toOtelSpan output instead of reusing
1010
- * the cached BufferedSpan estimate, because keepaliveMaxBytes is a hard browser limit and an estimate is not
1011
- * good enough.
1012
- *
1013
- * We use flatJsonStringify instead of JSON.stringify because a span keeps values the caller still owns, like
1014
- * status.message, and those can turn unserializable after the span ended. This runs from a visibilitychange
1015
- * listener with no try/catch around it, so a throw here loses the flush. flatJsonStringify handles the usual
1016
- * suspects (circular references, BigInt, a getter that throws on a plain object) but is not bulletproof: a
1017
- * class instance with a throwing getter goes through untouched and can still throw.
1018
- */
1019
974
  function otelSpanBytes(span) {
1020
975
  return utf8Bytes(require_urlAttributes.flatJsonStringify(toOtelSpan(span)));
1021
976
  }
1022
- /** UTF-8 bytes of an empty envelope: the fixed overhead every batch has, before any spans are added. */
1023
977
  function emptyTracesEnvelopeBytes(resourceAttributes, scopeName, scopeVersion) {
1024
978
  return utf8Bytes(JSON.stringify(buildTracesEnvelope([], resourceAttributes, scopeName, scopeVersion)));
1025
979
  }
1026
980
 
1027
981
  //#endregion
1028
982
  //#region src/tracing/SpanBuffer.ts
1029
- /** The span half of the shared telemetry buffer: names the config keys, the envelope and the ingest call. */
1030
983
  var SpanBuffer = class {
1031
984
  inner;
1032
985
  constructor(deps) {
@@ -1111,11 +1064,9 @@ function parseTraceparent(header) {
1111
1064
  function isPromiseLike(value) {
1112
1065
  return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
1113
1066
  }
1114
- /** `SpanOptions.parent` is a structurally overlapping union; `isRecording` is what tells a real Span apart. */
1115
1067
  function isSpan(parent) {
1116
1068
  return "isRecording" in parent;
1117
1069
  }
1118
- /** A SpanImpl carries the epoch it was created under; a hand-stitched `{traceId, spanId}` parent does not. */
1119
1070
  function hasEpoch(parent) {
1120
1071
  return "epoch" in parent && typeof parent.epoch === "number";
1121
1072
  }
@@ -1124,16 +1075,6 @@ function defaultNowNano() {
1124
1075
  const ms = performanceApi && typeof performanceApi.now === "function" && typeof performanceApi.timeOrigin === "number" ? performanceApi.timeOrigin + performanceApi.now() : Date.now();
1125
1076
  return Math.round(ms * 1e6);
1126
1077
  }
1127
- /**
1128
- * Both trace maps cap their size the same way: insertion order is LRU, so the first key is the one to drop.
1129
- * Only evicts when `key` is not already in the map. A set() that overwrites an existing key does not grow the
1130
- * map, so it must not evict an unrelated entry to make room for it.
1131
- */
1132
- function evictLruIfNew(map, key, cap) {
1133
- if (map.has(key) || map.size < cap) return;
1134
- const lru = map.keys().next().value;
1135
- if (lru !== void 0) map.delete(lru);
1136
- }
1137
1078
  const MAX_CLOSED_TRACES = 100;
1138
1079
  /** Bounded backstop for the live TraceState map: an app that never ends spans must not grow it forever. */
1139
1080
  const DEFAULT_MAX_LIVE_TRACES = 1e3;
@@ -1172,10 +1113,9 @@ var Tracer = class {
1172
1113
  this.holder.setActiveRoot?.(span);
1173
1114
  }
1174
1115
  /**
1175
- * Take one span against `traceId`'s cap up front, for a caller that publishes a span id before the
1176
- * span exists (the component profilers do; their descendants record first). False means the trace is
1177
- * full and the caller should stay transparent instead of handing out an id the cap will refuse.
1178
- * Consumed by the matching `startSpan({ claimed: true })`.
1116
+ * Claims a span slot before the span exists, for a caller that publishes a span id early (the
1117
+ * component profilers do; their descendants record first). Returns false when the trace is full.
1118
+ * Paired with `startSpan({ claimed: true })`.
1179
1119
  */
1180
1120
  claimSpanSlot(traceId) {
1181
1121
  const config = this.deps.getConfig();
@@ -1214,7 +1154,7 @@ var Tracer = class {
1214
1154
  this.pendingContinuation = parseTraceparent(header);
1215
1155
  }
1216
1156
  /**
1217
- * Runs `fn` with the span active, so spans started inside auto-parent to it, then ends it.
1157
+ * Runs `fn` with the span active, so spans started inside it auto-parent to it, then ends the span.
1218
1158
  * Records an error status first if `fn` throws or its returned promise rejects.
1219
1159
  */
1220
1160
  withSpan(name, fn, opts = {}) {
@@ -1244,8 +1184,10 @@ var Tracer = class {
1244
1184
  }
1245
1185
  });
1246
1186
  }
1247
- /** Starts a span the caller must end. Unlike `withSpan`, it does not become the active span,
1248
- * so spans started after it do not auto-parent to it. */
1187
+ /**
1188
+ * Starts a span the caller must end. Unlike `withSpan`, it does not become the active span, so spans
1189
+ * started after it do not auto-parent to it.
1190
+ */
1249
1191
  startSpan(name, opts = {}) {
1250
1192
  const config = this.deps.getConfig();
1251
1193
  const spanId$1 = opts.spanId ?? spanId();
@@ -1275,7 +1217,6 @@ var Tracer = class {
1275
1217
  this.emitSpanEvent("start", span);
1276
1218
  return span;
1277
1219
  }
1278
- /** A real Span handle that records nothing, so callers never have to branch on whether tracing is on. */
1279
1220
  startInertSpan(name, spanId, opts, config) {
1280
1221
  const span = this.makeSpan({
1281
1222
  traceId: traceId(),
@@ -1350,7 +1291,7 @@ var Tracer = class {
1350
1291
  return this.createState(traceId, localRootSpanId, fallbackRecording());
1351
1292
  }
1352
1293
  createState(traceId, localRootSpanId, recording) {
1353
- evictLruIfNew(this.traceStates, traceId, this.maxLiveTraces);
1294
+ require_urlAttributes.evictLruIfNew(this.traceStates, traceId, this.maxLiveTraces);
1354
1295
  const state = {
1355
1296
  traceId,
1356
1297
  recording,
@@ -1382,9 +1323,8 @@ var Tracer = class {
1382
1323
  if (opts.attributes) for (const [key, value] of Object.entries(opts.attributes)) span.setAttribute(key, value);
1383
1324
  return span;
1384
1325
  }
1385
- /** Bounded, LRU by insertion order, like traceStates. Holds primitives only, never a span. */
1386
1326
  rememberClosed(state) {
1387
- evictLruIfNew(this.closedTraces, state.traceId, MAX_CLOSED_TRACES);
1327
+ require_urlAttributes.evictLruIfNew(this.closedTraces, state.traceId, MAX_CLOSED_TRACES);
1388
1328
  this.closedTraces.set(state.traceId, {
1389
1329
  localRootSpanId: state.localRootSpanId,
1390
1330
  recording: state.recording,
@@ -1437,8 +1377,6 @@ var Tracer = class {
1437
1377
 
1438
1378
  //#endregion
1439
1379
  //#region src/Flare.ts
1440
- /** Scope attributes a span never inherits. Derived from `USER_IDENTITY_KEYS` so a future user field is
1441
- * excluded automatically, without anyone needing to remember to list it here. See `getScopeAttributes`. */
1442
1380
  const SPAN_SCOPE_EXCLUDED_KEYS = USER_IDENTITY_KEYS.filter((key) => key !== USER_FIELD_KEYS.id);
1443
1381
  const DEFAULT_SDK_NAME = "@flareapp/core";
1444
1382
  var Flare = class {
@@ -1523,14 +1461,6 @@ var Flare = class {
1523
1461
  activeSpanHolder
1524
1462
  });
1525
1463
  }
1526
- /**
1527
- * Register an in-flight report so `flush()` can wait for it. Every entry point wraps its whole async
1528
- * pipeline, from beforeEvaluate through api.report, so flush() waits on all of it.
1529
- *
1530
- * What goes in the Set is a shadow promise that mirrors `p`'s timing but cannot reject, so a failed
1531
- * report never surfaces as an unhandled rejection warning. `p` itself is returned untouched, so the
1532
- * caller still observes real success or failure.
1533
- */
1534
1464
  track(p) {
1535
1465
  const tracked = p.then(() => void 0, () => void 0);
1536
1466
  this.inflight.add(tracked);
@@ -1538,12 +1468,11 @@ var Flare = class {
1538
1468
  return p;
1539
1469
  }
1540
1470
  /**
1541
- * Wait until every in-flight report settles or `timeoutMs` elapses. Always resolves, never rejects.
1542
- * Written for `@flareapp/node`'s fatal handler, which awaits the fatal report itself then flushes to
1543
- * drain any other concurrent reports before `process.exit`.
1471
+ * Waits until every in-flight report settles, or `timeoutMs` elapses. Always resolves, never rejects.
1472
+ * Used by `@flareapp/node`'s fatal handler to drain other reports before `process.exit`.
1544
1473
  *
1545
- * Snapshotting the Set bounds the wait: reports started after this line are not awaited, so a handler
1546
- * that keeps emitting during shutdown cannot block the process forever. Call flush again for those.
1474
+ * Only reports already in flight are awaited, so a handler still emitting during shutdown cannot block
1475
+ * forever. Call flush again to catch those.
1547
1476
  */
1548
1477
  flush(timeoutMs = 2e3) {
1549
1478
  this._logger.flush();
@@ -1690,10 +1619,6 @@ var Flare = class {
1690
1619
  this.framework = framework;
1691
1620
  return this;
1692
1621
  }
1693
- /**
1694
- * True when a report must not be captured: consent withdrawn, or dropped by sampling. Consent is
1695
- * checked first, so a blocked report never runs the sampler or assembles a report (no cookie read).
1696
- */
1697
1622
  shouldSkipCapture() {
1698
1623
  if (this._config.hasConsent === false) return true;
1699
1624
  return this._config.sampleRate < 1 && Math.random() >= this._config.sampleRate;
@@ -1818,15 +1743,6 @@ var Flare = class {
1818
1743
  record: this.assembleAttributes(collectorRecord, userAttributes, false)
1819
1744
  };
1820
1745
  }
1821
- /**
1822
- * Local roots only, snapshotted by the Tracer at span START so a long-lived root does not drift into
1823
- * the next page's scope. Children get none, and no span ever runs the DOM collector.
1824
- *
1825
- * Everything assembled is inherited except user identity (excluding the opaque `user.id`): a root span
1826
- * goes out for every page view, so email, full name, IP and `user.attributes` would turn normal
1827
- * browsing into PII traffic. The rest — `context.custom`, `addContextGroup` bags — stays in, because
1828
- * the trace viewer renders any span attribute whose key does not start with `flare.`.
1829
- */
1830
1746
  getScopeAttributes() {
1831
1747
  const scoped = { ...this.assembleAttributes({}, {}, false) };
1832
1748
  for (const key of SPAN_SCOPE_EXCLUDED_KEYS) delete scoped[key];
@@ -1861,6 +1777,73 @@ var Flare = class {
1861
1777
  }
1862
1778
  };
1863
1779
 
1780
+ //#endregion
1781
+ //#region src/device/DeviceInfoProvider.ts
1782
+ /** Default for platforms with no device info. */
1783
+ var NullDeviceInfoProvider = class {
1784
+ collect() {
1785
+ return {};
1786
+ }
1787
+ };
1788
+
1789
+ //#endregion
1790
+ //#region src/device/deviceInfoToAttributes.ts
1791
+ /** Map `DeviceInfo` to wire attributes: flat keys plus a `context.device` card. Shared by every SDK, so keys never drift. */
1792
+ function deviceInfoToAttributes(info) {
1793
+ const attrs = {};
1794
+ require_urlAttributes.setDefined(attrs, "os.name", info.os?.name);
1795
+ require_urlAttributes.setDefined(attrs, "os.version", info.os?.version);
1796
+ require_urlAttributes.setDefined(attrs, "process.runtime.name", info.runtime?.name);
1797
+ require_urlAttributes.setDefined(attrs, "process.runtime.version", info.runtime?.version);
1798
+ require_urlAttributes.setDefined(attrs, "device.type", info.device?.type);
1799
+ require_urlAttributes.setDefined(attrs, "device.model.name", info.device?.model);
1800
+ require_urlAttributes.setDefined(attrs, "device.memory_gb", info.device?.memoryGb);
1801
+ require_urlAttributes.setDefined(attrs, "device.cpu_cores", info.device?.cpuCores);
1802
+ require_urlAttributes.setDefined(attrs, "device.screen.width", info.device?.screen?.width);
1803
+ require_urlAttributes.setDefined(attrs, "device.screen.height", info.device?.screen?.height);
1804
+ require_urlAttributes.setDefined(attrs, "device.screen.scale", info.device?.screen?.scale);
1805
+ require_urlAttributes.setDefined(attrs, "network.effective_type", info.network?.effectiveType);
1806
+ require_urlAttributes.setDefined(attrs, "network.downlink_mbps", info.network?.downlinkMbps);
1807
+ require_urlAttributes.setDefined(attrs, "network.rtt_ms", info.network?.rttMs);
1808
+ require_urlAttributes.setDefined(attrs, "network.online", info.network?.online);
1809
+ require_urlAttributes.setDefined(attrs, "app.version", info.app?.version);
1810
+ require_urlAttributes.setDefined(attrs, "app.id", info.app?.id);
1811
+ const group = buildDeviceContextGroup(info);
1812
+ if (Object.keys(group).length > 0) attrs["context.device"] = group;
1813
+ return attrs;
1814
+ }
1815
+ /**
1816
+ * `context.device` card for the error UI. Rendered one level deep, so values stay scalar. Built only when
1817
+ * a device or network signal exists (an os-only Node report gets none).
1818
+ */
1819
+ function buildDeviceContextGroup(info) {
1820
+ if (!hasDeviceSignal(info.device) && !hasNetworkSignal(info.network)) return {};
1821
+ const group = {};
1822
+ const os = [info.os?.name, info.os?.version].filter((value) => value != null).join(" ");
1823
+ if (os) group.OS = os;
1824
+ require_urlAttributes.setDefined(group, "Model", info.device?.model);
1825
+ require_urlAttributes.setDefined(group, "Type", info.device?.type);
1826
+ const screen = info.device?.screen;
1827
+ if (screen?.width != null && screen?.height != null) group.Screen = screen.scale != null ? `${screen.width} × ${screen.height} @ ${screen.scale}x` : `${screen.width} × ${screen.height}`;
1828
+ if (info.device?.memoryGb != null) group.Memory = `${info.device.memoryGb} GB`;
1829
+ require_urlAttributes.setDefined(group, "CPU cores", info.device?.cpuCores);
1830
+ require_urlAttributes.setDefined(group, "Connection", info.network?.effectiveType);
1831
+ if (info.network?.downlinkMbps != null) group.Downlink = `${info.network.downlinkMbps} Mbps`;
1832
+ if (info.network?.rttMs != null) group.RTT = `${info.network.rttMs} ms`;
1833
+ require_urlAttributes.setDefined(group, "Online", info.network?.online);
1834
+ require_urlAttributes.setDefined(group, "App version", info.app?.version);
1835
+ require_urlAttributes.setDefined(group, "App ID", info.app?.id);
1836
+ require_urlAttributes.setDefined(group, "Language", info.locale?.language);
1837
+ require_urlAttributes.setDefined(group, "Timezone", info.locale?.timezone);
1838
+ return group;
1839
+ }
1840
+ function hasDeviceSignal(device) {
1841
+ return device != null && (device.type != null || device.model != null || device.memoryGb != null || device.cpuCores != null || device.screen?.width != null || device.screen?.height != null);
1842
+ }
1843
+ function hasNetworkSignal(network) {
1844
+ return network != null && (network.effectiveType != null || network.downlinkMbps != null || network.rttMs != null || network.online != null);
1845
+ }
1846
+
1864
1847
  //#endregion
1865
1848
  exports.Api = Api;
1866
1849
  exports.BrowserSpanEventType = BrowserSpanEventType;
@@ -1874,6 +1857,7 @@ exports.InMemoryActiveSpanHolder = InMemoryActiveSpanHolder;
1874
1857
  exports.Logger = Logger;
1875
1858
  exports.MAX_BREADCRUMB_URL_LENGTH = MAX_BREADCRUMB_URL_LENGTH;
1876
1859
  exports.NoopFlushScheduler = NoopFlushScheduler;
1860
+ exports.NullDeviceInfoProvider = NullDeviceInfoProvider;
1877
1861
  exports.NullFileReader = NullFileReader;
1878
1862
  exports.Scope = Scope;
1879
1863
  exports.SpanStatusCode = SpanStatusCode;
@@ -1882,6 +1866,7 @@ exports.USER_IDENTITY_KEYS = USER_IDENTITY_KEYS;
1882
1866
  exports.assert = require_urlAttributes.assert;
1883
1867
  exports.assertKey = require_urlAttributes.assertKey;
1884
1868
  exports.breadcrumbUrl = breadcrumbUrl;
1869
+ exports.buildDeviceContextGroup = buildDeviceContextGroup;
1885
1870
  exports.buildTraceparent = buildTraceparent;
1886
1871
  exports.buildTracesEnvelope = buildTracesEnvelope;
1887
1872
  exports.convertToError = require_urlAttributes.convertToError;
@@ -1889,6 +1874,8 @@ exports.createIdentityTagger = require_urlAttributes.createIdentityTagger;
1889
1874
  exports.createStackTrace = createStackTrace;
1890
1875
  exports.defaultNowNano = defaultNowNano;
1891
1876
  exports.describeRejectionReason = require_urlAttributes.describeRejectionReason;
1877
+ exports.deviceInfoToAttributes = deviceInfoToAttributes;
1878
+ exports.evictLruIfNew = require_urlAttributes.evictLruIfNew;
1892
1879
  exports.extractCode = require_urlAttributes.extractCode;
1893
1880
  exports.flatJsonStringify = require_urlAttributes.flatJsonStringify;
1894
1881
  exports.getCodeSnippet = getCodeSnippet;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as TracesSampler, A as BufferedLog, B as OtelLogRecord, D as AnyValue, E as assert, F as Framework, G as SdkInfo, H as OverriddenGrouping, I as Glow, J as SpanOptions, K as Span, L as KeyValue, M as Config, N as EntryPointHandler, O as AttributeValue, P as EntryPointType, Q as TracesEnvelope, R as LogsEnvelope, S as convertToError, T as assertKey, U as Report, V as OtelSpan, W as SamplingContext, X as SpanStatusCode, Y as SpanStatus, Z as StackFrame, _ as glowsToEvents, a as SafeCloneOptions, b as SdkTaggable, c as describeRejectionReason, d as redactObjectValues, et as User, f as redactUrlQuery, h as now, it as FrameworkName, j as BufferedSpan, k as Attributes, l as routeRejection, m as safeDecode, n as urlAttributes, nt as BrowserSpanType, o as safeClone, p as resolveDenylist, q as SpanEvent, r as toCustomContext, rt as SpanTypeName, s as RejectionReporter, tt as BrowserSpanEventType, u as DEFAULT_URL_DENYLIST, v as flatJsonStringify, x as createIdentityTagger, y as extractCode, z as MessageLevel } from "./urlAttributes-DW_i-YQ3.cjs";
1
+ import { $ as StackFrame, A as AttributeValue, B as LogsEnvelope, C as createIdentityTagger, D as assertKey, F as EntryPointHandler, G as Report, H as OtelLogRecord, I as EntryPointType, J as Span, K as SamplingContext, L as Framework, M as BufferedLog, N as BufferedSpan, O as assert, P as Config, Q as SpanStatusCode, R as Glow, S as SdkTaggable, U as OtelSpan, V as MessageLevel, W as OverriddenGrouping, X as SpanOptions, Y as SpanEvent, Z as SpanStatus, at as SpanTypeName, b as extractCode, c as RejectionReporter, d as DEFAULT_URL_DENYLIST, et as TracesEnvelope, f as redactObjectValues, g as now, h as safeDecode, it as BrowserSpanType, j as Attributes, k as AnyValue, l as describeRejectionReason, m as resolveDenylist, n as urlAttributes, nt as User, o as SafeCloneOptions, ot as FrameworkName, p as redactUrlQuery, q as SdkInfo, r as toCustomContext, rt as BrowserSpanEventType, s as safeClone, tt as TracesSampler, u as routeRejection, v as glowsToEvents, w as convertToError, x as evictLruIfNew, y as flatJsonStringify, z as KeyValue } from "./urlAttributes-CU2Yr37w.cjs";
2
2
 
3
3
  //#region src/api/Api.d.ts
4
4
  declare class Api {
@@ -6,8 +6,7 @@ declare class Api {
6
6
  private pendingKeepaliveRequests;
7
7
  /**
8
8
  * How many keepalive bytes are still available. Logs and traces share one browser allowance and both
9
- * flush on page hide, so whichever goes second has to pack against what is left rather than assume the
10
- * whole budget, or it exceeds the gate in send() and silently degrades to a cancellable fetch.
9
+ * flush on page hide, so whichever goes second must pack against what is left, not the whole budget.
11
10
  */
12
11
  keepaliveBudgetRemaining(): number;
13
12
  report(report: Report, url: string, key: string | null, reportBrowserExtensionErrors: boolean, debug?: boolean): Promise<void>;
@@ -127,14 +126,13 @@ declare function readLinesFromFile(fileText: string, lineNumber: number, columnN
127
126
  interface ActiveSpanHolder {
128
127
  getActive(): Span | undefined;
129
128
  /**
130
- * Run `fn` with `span` active, restoring the prior active span afterward. A callback (not a bare setter) so a Node
131
- * holder can back it with AsyncLocalStorage.run(...) to preserve async-scoped context.
129
+ * Runs `fn` with `span` active, then restores the previous active span. Takes a callback, not a
130
+ * setter, so a Node holder can implement it with `AsyncLocalStorage.run(...)`.
132
131
  */
133
132
  withActive<T>(span: Span, fn: () => T): T;
134
133
  /**
135
- * Persistent "active root" that getActive() falls back to when no withActive scope is on the stack. Used by
136
- * long-lived pageload/navigation roots so child spans (e.g. fetches) auto-parent to them. Optional; a holder that
137
- * omits it simply has no active-root support.
134
+ * Fallback span that getActive() returns when no withActive scope is active. Long-lived
135
+ * pageload/navigation roots use it so child spans auto-parent to them. Optional.
138
136
  */
139
137
  setActiveRoot?(span: Span | undefined): void;
140
138
  }
@@ -187,10 +185,9 @@ declare class Tracer {
187
185
  getActiveSpan(): Span | undefined;
188
186
  setActiveRoot(span?: Span): void;
189
187
  /**
190
- * Take one span against `traceId`'s cap up front, for a caller that publishes a span id before the
191
- * span exists (the component profilers do; their descendants record first). False means the trace is
192
- * full and the caller should stay transparent instead of handing out an id the cap will refuse.
193
- * Consumed by the matching `startSpan({ claimed: true })`.
188
+ * Claims a span slot before the span exists, for a caller that publishes a span id early (the
189
+ * component profilers do; their descendants record first). Returns false when the trace is full.
190
+ * Paired with `startSpan({ claimed: true })`.
194
191
  */
195
192
  claimSpanSlot(traceId: string): boolean;
196
193
  addSpanListener(fn: SpanLifecycleListener): () => void;
@@ -201,20 +198,20 @@ declare class Tracer {
201
198
  clear(): void;
202
199
  continueFromTraceparent(header: string): void;
203
200
  /**
204
- * Runs `fn` with the span active, so spans started inside auto-parent to it, then ends it.
201
+ * Runs `fn` with the span active, so spans started inside it auto-parent to it, then ends the span.
205
202
  * Records an error status first if `fn` throws or its returned promise rejects.
206
203
  */
207
204
  withSpan<T>(name: string, fn: (span: Span) => T, opts?: SpanOptions): T;
208
- /** Starts a span the caller must end. Unlike `withSpan`, it does not become the active span,
209
- * so spans started after it do not auto-parent to it. */
205
+ /**
206
+ * Starts a span the caller must end. Unlike `withSpan`, it does not become the active span, so spans
207
+ * started after it do not auto-parent to it.
208
+ */
210
209
  startSpan(name: string, opts?: SpanOptions): Span;
211
- /** A real Span handle that records nothing, so callers never have to branch on whether tracing is on. */
212
210
  private startInertSpan;
213
211
  private resolveTrace;
214
212
  private getOrSeedState;
215
213
  private createState;
216
214
  private makeSpan;
217
- /** Bounded, LRU by insertion order, like traceStates. Holds primitives only, never a span. */
218
215
  private rememberClosed;
219
216
  private onSpanEnd;
220
217
  }
@@ -246,22 +243,13 @@ declare class Flare {
246
243
  * default; a platform can back it with AsyncLocalStorage instead.
247
244
  */
248
245
  constructor(api?: Api, contextCollector?: ContextCollector, fileReader?: FileReader, scopeProvider?: ScopeProvider, scheduler?: FlushScheduler, activeSpanHolder?: ActiveSpanHolder);
249
- /**
250
- * Register an in-flight report so `flush()` can wait for it. Every entry point wraps its whole async
251
- * pipeline, from beforeEvaluate through api.report, so flush() waits on all of it.
252
- *
253
- * What goes in the Set is a shadow promise that mirrors `p`'s timing but cannot reject, so a failed
254
- * report never surfaces as an unhandled rejection warning. `p` itself is returned untouched, so the
255
- * caller still observes real success or failure.
256
- */
257
246
  private track;
258
247
  /**
259
- * Wait until every in-flight report settles or `timeoutMs` elapses. Always resolves, never rejects.
260
- * Written for `@flareapp/node`'s fatal handler, which awaits the fatal report itself then flushes to
261
- * drain any other concurrent reports before `process.exit`.
248
+ * Waits until every in-flight report settles, or `timeoutMs` elapses. Always resolves, never rejects.
249
+ * Used by `@flareapp/node`'s fatal handler to drain other reports before `process.exit`.
262
250
  *
263
- * Snapshotting the Set bounds the wait: reports started after this line are not awaited, so a handler
264
- * that keeps emitting during shutdown cannot block the process forever. Call flush again for those.
251
+ * Only reports already in flight are awaited, so a handler still emitting during shutdown cannot block
252
+ * forever. Call flush again to catch those.
265
253
  */
266
254
  flush(timeoutMs?: number): Promise<void>;
267
255
  get config(): Readonly<Config>;
@@ -298,10 +286,6 @@ declare class Flare {
298
286
  setEntryPoint(handler: EntryPointHandler): this;
299
287
  setSdkInfo(info: SdkInfo): this;
300
288
  setFramework(framework: Framework): this;
301
- /**
302
- * True when a report must not be captured: consent withdrawn, or dropped by sampling. Consent is
303
- * checked first, so a blocked report never runs the sampler or assembles a report (no cookie read).
304
- */
305
289
  private shouldSkipCapture;
306
290
  report(error: Error, attributes?: Attributes): Promise<void>;
307
291
  private reportInternal;
@@ -314,15 +298,6 @@ declare class Flare {
314
298
  private buildBaseAttributes;
315
299
  private assembleAttributes;
316
300
  private buildLogAttributes;
317
- /**
318
- * Local roots only, snapshotted by the Tracer at span START so a long-lived root does not drift into
319
- * the next page's scope. Children get none, and no span ever runs the DOM collector.
320
- *
321
- * Everything assembled is inherited except user identity (excluding the opaque `user.id`): a root span
322
- * goes out for every page view, so email, full name, IP and `user.attributes` would turn normal
323
- * browsing into PII traffic. The rest — `context.custom`, `addContextGroup` bags — stays in, because
324
- * the trace viewer renders any span attribute whose key does not start with `flare.`.
325
- */
326
301
  private getScopeAttributes;
327
302
  private spanResourceAttributes;
328
303
  private buildReport;
@@ -350,17 +325,74 @@ declare function spanId(): string;
350
325
  //#endregion
351
326
  //#region src/stacktrace/NullFileReader.d.ts
352
327
  /**
353
- * No-op `FileReader` returning `null` for every URL. Default for `Flare`'s `fileReader` param so `new Flare()` builds
354
- * reports without picking an environment; stack frames just omit source snippets. Consumer packages inject the real
355
- * ones: `@flareapp/js` a fetch-based reader, `@flareapp/node` a disk reader. The `read(url) -> Promise<string | null>`
356
- * interface lets the stack-trace builder treat all three the same (render on text, skip on null), so core needs no
357
- * environment checks.
328
+ * No-op `FileReader` returning `null` for every URL. Default for `Flare`'s `fileReader` param, so
329
+ * `new Flare()` builds reports without picking an environment; stack frames just omit source snippets.
330
+ * `@flareapp/js` and `@flareapp/node` inject a real fetch- or disk-based reader instead.
358
331
  */
359
332
  declare class NullFileReader implements FileReader {
360
333
  read(_url: string): Promise<string | null>;
361
334
  }
362
335
  //#endregion
336
+ //#region src/device/types.d.ts
337
+ /** Effective connection quality. The API never reports 5g: a 5g device reports '4g'. */
338
+ type EffectiveConnectionType = 'slow-2g' | '2g' | '3g' | '4g';
339
+ /** Normalised device info. Every field optional: each provider fills what it reads, the mapper drops the rest. */
340
+ type DeviceInfo = {
341
+ os?: {
342
+ name?: string;
343
+ version?: string;
344
+ };
345
+ runtime?: {
346
+ name?: string;
347
+ version?: string;
348
+ };
349
+ device?: {
350
+ type?: string;
351
+ model?: string;
352
+ memoryGb?: number;
353
+ cpuCores?: number;
354
+ screen?: {
355
+ width?: number;
356
+ height?: number;
357
+ scale?: number;
358
+ };
359
+ };
360
+ network?: {
361
+ effectiveType?: EffectiveConnectionType;
362
+ downlinkMbps?: number;
363
+ rttMs?: number;
364
+ online?: boolean;
365
+ };
366
+ app?: {
367
+ version?: string;
368
+ id?: string;
369
+ };
370
+ locale?: {
371
+ language?: string;
372
+ timezone?: string;
373
+ };
374
+ };
375
+ //#endregion
376
+ //#region src/device/DeviceInfoProvider.d.ts
377
+ /** The seam each platform implements to read device info. A `ContextCollector` maps it with `deviceInfoToAttributes`. */
378
+ interface DeviceInfoProvider {
379
+ collect(): DeviceInfo;
380
+ }
381
+ /** Default for platforms with no device info. */
382
+ declare class NullDeviceInfoProvider implements DeviceInfoProvider {
383
+ collect(): DeviceInfo;
384
+ }
385
+ //#endregion
386
+ //#region src/device/deviceInfoToAttributes.d.ts
387
+ /** Map `DeviceInfo` to wire attributes: flat keys plus a `context.device` card. Shared by every SDK, so keys never drift. */
388
+ declare function deviceInfoToAttributes(info: DeviceInfo): Attributes;
389
+ /**
390
+ * `context.device` card for the error UI. Rendered one level deep, so values stay scalar. Built only when
391
+ * a device or network signal exists (an os-only Node report gets none).
392
+ */
393
+ declare function buildDeviceContextGroup(info: DeviceInfo): Record<string, AttributeValue>;
394
+ //#endregion
363
395
  //#region src/stacktrace/createStackTrace.d.ts
364
396
  declare function createStackTrace(error: Error, debug: boolean, fileReader: FileReader): Promise<Array<StackFrame>>;
365
397
  //#endregion
366
- export { type ActiveSpanHolder, type AnyValue, Api, type AttributeValue, type Attributes, BrowserSpanEventType, BrowserSpanType, type BufferedLog, type BufferedSpan, type Config, type ContextCollector, DEFAULT_MAX_LIVE_TRACES, DEFAULT_URL_DENYLIST, type EntryPointHandler, type EntryPointType, type FileReader, Flare, type FlushFn, type FlushScheduler, type Framework, FrameworkName, GlobalScopeProvider, type Glow, InMemoryActiveSpanHolder, type KeyValue, Logger, type LoggerDeps, type LogsEnvelope, MAX_BREADCRUMB_URL_LENGTH, type MessageLevel, NoopFlushScheduler, NullFileReader, type OtelLogRecord, type OtelSpan, type OverriddenGrouping, type RejectionReporter, type Report, type SafeCloneOptions, type SamplingContext, Scope, type ScopeProvider, type SdkInfo, type SdkTaggable, type Span, type SpanEvent, type SpanLifecycleEvent, type SpanLifecycleListener, type SpanOptions, type SpanPhase, type SpanStatus, SpanStatusCode, type SpanTypeName, type StackFrame, Tracer, type TracerDeps, type TracesEnvelope, type TracesSampler, USER_IDENTITY_KEYS, type User, assert, assertKey, breadcrumbUrl, buildTraceparent, buildTracesEnvelope, convertToError, createIdentityTagger, createStackTrace, defaultNowNano, describeRejectionReason, extractCode, flatJsonStringify, getCodeSnippet, glowsToEvents, now, parseTraceparent, readLinesFromFile, recordBreadcrumb, redactObjectValues, redactUrlQuery, resolveDenylist, routeRejection, safeClone, safeDecode, spanId, toCustomContext, urlAttributes, userIdentityAttributes };
398
+ export { type ActiveSpanHolder, type AnyValue, Api, type AttributeValue, type Attributes, BrowserSpanEventType, BrowserSpanType, type BufferedLog, type BufferedSpan, type Config, type ContextCollector, DEFAULT_MAX_LIVE_TRACES, DEFAULT_URL_DENYLIST, type DeviceInfo, type DeviceInfoProvider, type EffectiveConnectionType, type EntryPointHandler, type EntryPointType, type FileReader, Flare, type FlushFn, type FlushScheduler, type Framework, FrameworkName, GlobalScopeProvider, type Glow, InMemoryActiveSpanHolder, type KeyValue, Logger, type LoggerDeps, type LogsEnvelope, MAX_BREADCRUMB_URL_LENGTH, type MessageLevel, NoopFlushScheduler, NullDeviceInfoProvider, NullFileReader, type OtelLogRecord, type OtelSpan, type OverriddenGrouping, type RejectionReporter, type Report, type SafeCloneOptions, type SamplingContext, Scope, type ScopeProvider, type SdkInfo, type SdkTaggable, type Span, type SpanEvent, type SpanLifecycleEvent, type SpanLifecycleListener, type SpanOptions, type SpanPhase, type SpanStatus, SpanStatusCode, type SpanTypeName, type StackFrame, Tracer, type TracerDeps, type TracesEnvelope, type TracesSampler, USER_IDENTITY_KEYS, type User, assert, assertKey, breadcrumbUrl, buildDeviceContextGroup, buildTraceparent, buildTracesEnvelope, convertToError, createIdentityTagger, createStackTrace, defaultNowNano, describeRejectionReason, deviceInfoToAttributes, evictLruIfNew, extractCode, flatJsonStringify, getCodeSnippet, glowsToEvents, now, parseTraceparent, readLinesFromFile, recordBreadcrumb, redactObjectValues, redactUrlQuery, resolveDenylist, routeRejection, safeClone, safeDecode, spanId, toCustomContext, urlAttributes, userIdentityAttributes };