@interfere/react 9.0.2 → 10.0.1-canary.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.
Files changed (189) hide show
  1. package/README.md +4 -4
  2. package/dist/api.d.mts +25 -0
  3. package/dist/api.d.mts.map +1 -0
  4. package/dist/api.mjs +1 -0
  5. package/dist/api.mjs.map +1 -0
  6. package/dist/error-boundary.d.mts +10 -4
  7. package/dist/error-boundary.d.mts.map +1 -1
  8. package/dist/error-boundary.mjs +1 -39
  9. package/dist/error-boundary.mjs.map +1 -1
  10. package/dist/internal/browser-context.d.mts +6 -0
  11. package/dist/internal/browser-context.d.mts.map +1 -0
  12. package/dist/internal/browser-context.mjs +1 -0
  13. package/dist/internal/browser-context.mjs.map +1 -0
  14. package/dist/internal/capture-boundary.d.mts +4 -1
  15. package/dist/internal/capture-boundary.d.mts.map +1 -1
  16. package/dist/internal/capture-boundary.mjs +1 -44
  17. package/dist/internal/capture-boundary.mjs.map +1 -1
  18. package/dist/internal/capture.d.mts +16 -5
  19. package/dist/internal/capture.d.mts.map +1 -1
  20. package/dist/internal/capture.mjs +1 -23
  21. package/dist/internal/capture.mjs.map +1 -1
  22. package/dist/internal/config.d.mts +22 -4
  23. package/dist/internal/config.d.mts.map +1 -1
  24. package/dist/internal/config.mjs +1 -33
  25. package/dist/internal/config.mjs.map +1 -1
  26. package/dist/internal/consent.d.mts.map +1 -1
  27. package/dist/internal/consent.mjs +1 -25
  28. package/dist/internal/consent.mjs.map +1 -1
  29. package/dist/internal/console-patch.d.mts +19 -0
  30. package/dist/internal/console-patch.d.mts.map +1 -0
  31. package/dist/internal/console-patch.mjs +1 -0
  32. package/dist/internal/console-patch.mjs.map +1 -0
  33. package/dist/internal/dom/actionable.d.mts +27 -0
  34. package/dist/internal/dom/actionable.d.mts.map +1 -0
  35. package/dist/internal/dom/actionable.mjs +1 -0
  36. package/dist/internal/dom/actionable.mjs.map +1 -0
  37. package/dist/internal/kernel-registry.d.mts +8 -0
  38. package/dist/internal/kernel-registry.d.mts.map +1 -0
  39. package/dist/internal/kernel-registry.mjs +1 -0
  40. package/dist/internal/kernel-registry.mjs.map +1 -0
  41. package/dist/internal/kernel.d.mts +267 -0
  42. package/dist/internal/kernel.d.mts.map +1 -0
  43. package/dist/internal/kernel.mjs +1 -0
  44. package/dist/internal/kernel.mjs.map +1 -0
  45. package/dist/internal/otel/exporter.d.mts +85 -0
  46. package/dist/internal/otel/exporter.d.mts.map +1 -0
  47. package/dist/internal/otel/exporter.mjs +1 -0
  48. package/dist/internal/otel/exporter.mjs.map +1 -0
  49. package/dist/internal/otel/index.d.mts +6 -0
  50. package/dist/internal/otel/index.mjs +1 -0
  51. package/dist/internal/otel/instrumentations.d.mts +42 -0
  52. package/dist/internal/otel/instrumentations.d.mts.map +1 -0
  53. package/dist/internal/otel/instrumentations.mjs +1 -0
  54. package/dist/internal/otel/instrumentations.mjs.map +1 -0
  55. package/dist/internal/otel/page-scope-context-manager.d.mts +32 -0
  56. package/dist/internal/otel/page-scope-context-manager.d.mts.map +1 -0
  57. package/dist/internal/otel/page-scope-context-manager.mjs +1 -0
  58. package/dist/internal/otel/page-scope-context-manager.mjs.map +1 -0
  59. package/dist/internal/otel/propagation.d.mts +21 -0
  60. package/dist/internal/otel/propagation.d.mts.map +1 -0
  61. package/dist/internal/otel/propagation.mjs +1 -0
  62. package/dist/internal/otel/propagation.mjs.map +1 -0
  63. package/dist/internal/otel/provider.d.mts +106 -0
  64. package/dist/internal/otel/provider.d.mts.map +1 -0
  65. package/dist/internal/otel/provider.mjs +1 -0
  66. package/dist/internal/otel/provider.mjs.map +1 -0
  67. package/dist/internal/otel/web-vitals.d.mts +35 -0
  68. package/dist/internal/otel/web-vitals.d.mts.map +1 -0
  69. package/dist/internal/otel/web-vitals.mjs +1 -0
  70. package/dist/internal/otel/web-vitals.mjs.map +1 -0
  71. package/dist/internal/page-lifecycle.d.mts +21 -0
  72. package/dist/internal/page-lifecycle.d.mts.map +1 -0
  73. package/dist/internal/page-lifecycle.mjs +1 -0
  74. package/dist/internal/page-lifecycle.mjs.map +1 -0
  75. package/dist/internal/plugin-runtime.d.mts +0 -2
  76. package/dist/internal/plugin-runtime.d.mts.map +1 -1
  77. package/dist/internal/plugin-runtime.mjs +1 -107
  78. package/dist/internal/plugin-runtime.mjs.map +1 -1
  79. package/dist/internal/react-context.d.mts +44 -0
  80. package/dist/internal/react-context.d.mts.map +1 -0
  81. package/dist/internal/react-context.mjs +1 -0
  82. package/dist/internal/react-context.mjs.map +1 -0
  83. package/dist/internal/sw.d.mts +22 -2
  84. package/dist/internal/sw.d.mts.map +1 -1
  85. package/dist/internal/sw.mjs +1 -10
  86. package/dist/internal/sw.mjs.map +1 -1
  87. package/dist/internal/version.d.mts +3 -1
  88. package/dist/internal/version.d.mts.map +1 -1
  89. package/dist/internal/version.mjs +1 -5
  90. package/dist/internal/version.mjs.map +1 -1
  91. package/dist/internal/wrapper-singleton.d.mts +47 -0
  92. package/dist/internal/wrapper-singleton.d.mts.map +1 -0
  93. package/dist/internal/wrapper-singleton.mjs +1 -0
  94. package/dist/internal/wrapper-singleton.mjs.map +1 -0
  95. package/dist/package.mjs +1 -5
  96. package/dist/plugins/errors.d.mts.map +1 -1
  97. package/dist/plugins/errors.mjs +1 -91
  98. package/dist/plugins/errors.mjs.map +1 -1
  99. package/dist/plugins/lib/loader.d.mts +1 -2
  100. package/dist/plugins/lib/loader.d.mts.map +1 -1
  101. package/dist/plugins/lib/loader.mjs +1 -43
  102. package/dist/plugins/lib/loader.mjs.map +1 -1
  103. package/dist/plugins/lib/types.d.mts +3 -2
  104. package/dist/plugins/lib/types.d.mts.map +1 -1
  105. package/dist/plugins/lib/types.mjs +1 -1
  106. package/dist/plugins/logs.d.mts +13 -0
  107. package/dist/plugins/logs.d.mts.map +1 -0
  108. package/dist/plugins/logs.mjs +1 -0
  109. package/dist/plugins/logs.mjs.map +1 -0
  110. package/dist/plugins/rage-clicks.d.mts.map +1 -1
  111. package/dist/plugins/rage-clicks.mjs +1 -53
  112. package/dist/plugins/rage-clicks.mjs.map +1 -1
  113. package/dist/plugins/replay.d.mts.map +1 -1
  114. package/dist/plugins/replay.mjs +1 -62
  115. package/dist/plugins/replay.mjs.map +1 -1
  116. package/dist/provider.d.mts +11 -20
  117. package/dist/provider.d.mts.map +1 -1
  118. package/dist/provider.mjs +1 -32
  119. package/dist/provider.mjs.map +1 -1
  120. package/dist/react-error-handler.d.mts +21 -5
  121. package/dist/react-error-handler.d.mts.map +1 -1
  122. package/dist/react-error-handler.mjs +1 -54
  123. package/dist/react-error-handler.mjs.map +1 -1
  124. package/dist/sw.d.mts +2 -0
  125. package/dist/sw.mjs +2 -0
  126. package/dist/tracking/api.d.mts +41 -15
  127. package/dist/tracking/api.d.mts.map +1 -1
  128. package/dist/tracking/api.mjs +1 -134
  129. package/dist/tracking/api.mjs.map +1 -1
  130. package/dist/tracking/device.d.mts +30 -7
  131. package/dist/tracking/device.d.mts.map +1 -1
  132. package/dist/tracking/device.mjs +1 -80
  133. package/dist/tracking/device.mjs.map +1 -1
  134. package/dist/tracking/geo.d.mts +11 -3
  135. package/dist/tracking/geo.d.mts.map +1 -1
  136. package/dist/tracking/geo.mjs +2 -44
  137. package/dist/tracking/geo.mjs.map +1 -1
  138. package/dist/tracking/session.d.mts +3 -1
  139. package/dist/tracking/session.d.mts.map +1 -1
  140. package/dist/tracking/session.mjs +1 -75
  141. package/dist/tracking/session.mjs.map +1 -1
  142. package/dist/util/bot.d.mts +10 -0
  143. package/dist/util/bot.d.mts.map +1 -0
  144. package/dist/util/bot.mjs +1 -0
  145. package/dist/util/bot.mjs.map +1 -0
  146. package/dist/util/global.d.mts +10 -0
  147. package/dist/util/global.d.mts.map +1 -0
  148. package/dist/util/global.mjs +1 -0
  149. package/dist/util/global.mjs.map +1 -0
  150. package/dist/util/log.d.mts.map +1 -1
  151. package/dist/util/log.mjs +1 -37
  152. package/dist/util/log.mjs.map +1 -1
  153. package/dist/util/stringify.d.mts +9 -0
  154. package/dist/util/stringify.d.mts.map +1 -0
  155. package/dist/util/stringify.mjs +1 -0
  156. package/dist/util/stringify.mjs.map +1 -0
  157. package/package.json +79 -25
  158. package/dist/internal/client.d.mts +0 -48
  159. package/dist/internal/client.d.mts.map +0 -1
  160. package/dist/internal/client.mjs +0 -146
  161. package/dist/internal/client.mjs.map +0 -1
  162. package/dist/internal/context.d.mts +0 -6
  163. package/dist/internal/context.d.mts.map +0 -1
  164. package/dist/internal/context.mjs +0 -32
  165. package/dist/internal/context.mjs.map +0 -1
  166. package/dist/internal/envelope.d.mts +0 -15
  167. package/dist/internal/envelope.d.mts.map +0 -1
  168. package/dist/internal/envelope.mjs +0 -24
  169. package/dist/internal/envelope.mjs.map +0 -1
  170. package/dist/internal/errors.d.mts +0 -4
  171. package/dist/internal/errors.d.mts.map +0 -1
  172. package/dist/internal/errors.mjs +0 -4
  173. package/dist/internal/errors.mjs.map +0 -1
  174. package/dist/plugins/device.d.mts +0 -6
  175. package/dist/plugins/device.d.mts.map +0 -1
  176. package/dist/plugins/device.mjs +0 -13
  177. package/dist/plugins/device.mjs.map +0 -1
  178. package/dist/plugins/pages.d.mts +0 -6
  179. package/dist/plugins/pages.d.mts.map +0 -1
  180. package/dist/plugins/pages.mjs +0 -102
  181. package/dist/plugins/pages.mjs.map +0 -1
  182. package/dist/transport/http.d.mts +0 -25
  183. package/dist/transport/http.d.mts.map +0 -1
  184. package/dist/transport/http.mjs +0 -80
  185. package/dist/transport/http.mjs.map +0 -1
  186. package/dist/transport/queue.d.mts +0 -34
  187. package/dist/transport/queue.d.mts.map +0 -1
  188. package/dist/transport/queue.mjs +0 -100
  189. package/dist/transport/queue.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionable.mjs","names":[],"sources":["../../../src/internal/dom/actionable.ts"],"sourcesContent":["/**\n * Single source of truth for \"what counts as a clickable element\" across\n * the SDK. Used by both the `pages` plugin (which captures `ui_event`\n * envelopes) and the OTel `UserInteractionInstrumentation` enrichment\n * hook (which gates span creation + stamps target attrs). Before this\n * was extracted, the two sites diverged and produced inconsistent\n * notions of \"actionable.\"\n *\n * `data-track-click` is the customer escape hatch — any element opted\n * in via that attribute is treated as actionable regardless of tag/role.\n */\n\nconst ACTIONABLE_TAGS = new Set([\n \"a\",\n \"button\",\n \"input\",\n \"select\",\n \"textarea\",\n \"summary\",\n \"label\",\n]);\n\nconst ACTIONABLE_ROLES = new Set([\n \"button\",\n \"link\",\n \"menuitem\",\n \"tab\",\n \"checkbox\",\n \"radio\",\n \"switch\",\n]);\n\nconst TEXT_TRUNCATE = 120;\n\nexport function isActionable(el: Element): boolean {\n if (ACTIONABLE_TAGS.has(el.tagName.toLowerCase())) {\n return true;\n }\n const role = el.getAttribute(\"role\");\n if (role && ACTIONABLE_ROLES.has(role)) {\n return true;\n }\n return el.hasAttribute(\"data-track-click\");\n}\n\nexport function closestActionable(target: EventTarget | null): Element | null {\n if (!(target instanceof Element)) {\n return null;\n }\n let el: Element | null = target;\n while (el) {\n if (isActionable(el)) {\n return el;\n }\n el = el.parentElement;\n }\n return null;\n}\n\nexport interface ActionableDescriptor {\n ariaLabel?: string | undefined;\n href?: string | undefined;\n id?: string | undefined;\n name?: string | undefined;\n role?: string | undefined;\n tag: string;\n text?: string | undefined;\n [key: string]: unknown;\n}\n\nexport function describeActionable(el: Element): ActionableDescriptor {\n const desc: ActionableDescriptor = {\n tag: el.tagName.toLowerCase(),\n };\n if (el.id) {\n desc.id = el.id;\n }\n const role = el.getAttribute(\"role\");\n if (role) {\n desc.role = role;\n }\n const name = el.getAttribute(\"name\");\n if (name) {\n desc.name = name;\n }\n const ariaLabel = el.getAttribute(\"aria-label\");\n if (ariaLabel) {\n desc.ariaLabel = ariaLabel;\n }\n if (el instanceof HTMLAnchorElement) {\n desc.href = el.href;\n }\n const text = el.textContent?.trim().slice(0, TEXT_TRUNCATE);\n if (text) {\n desc.text = text;\n }\n return desc;\n}\n"],"mappings":"AAYA,MAAM,gBAAkB,IAAI,IAAI,CAC9B,IACA,SACA,QACA,SACA,WACA,UACA,OACF,CAAC,EAEK,iBAAmB,IAAI,IAAI,CAC/B,SACA,OACA,WACA,MACA,WACA,QACA,QACF,CAAC,EAID,SAAgB,aAAa,GAAsB,CACjD,GAAI,gBAAgB,IAAI,GAAG,QAAQ,YAAY,CAAC,EAC9C,MAAO,GAET,IAAM,KAAO,GAAG,aAAa,MAAM,EAInC,OAHI,MAAQ,iBAAiB,IAAI,IAAI,EAC5B,GAEF,GAAG,aAAa,kBAAkB,CAC3C,CAEA,SAAgB,kBAAkB,OAA4C,CAC5E,GAAI,EAAE,kBAAkB,SACtB,OAAO,KAET,IAAI,GAAqB,OACzB,KAAO,IAAI,CACT,GAAI,aAAa,EAAE,EACjB,OAAO,GAET,GAAK,GAAG,aACV,CACA,OAAO,IACT,CAaA,SAAgB,mBAAmB,GAAmC,CACpE,IAAM,KAA6B,CACjC,IAAK,GAAG,QAAQ,YAAY,CAC9B,EACI,GAAG,KACL,KAAK,GAAK,GAAG,IAEf,IAAM,KAAO,GAAG,aAAa,MAAM,EAC/B,OACF,KAAK,KAAO,MAEd,IAAM,KAAO,GAAG,aAAa,MAAM,EAC/B,OACF,KAAK,KAAO,MAEd,IAAM,UAAY,GAAG,aAAa,YAAY,EAC1C,YACF,KAAK,UAAY,WAEf,cAAc,oBAChB,KAAK,KAAO,GAAG,MAEjB,IAAM,KAAO,GAAG,aAAa,KAAK,EAAE,MAAM,EAAG,GAAa,EAI1D,OAHI,OACF,KAAK,KAAO,MAEP,IACT"}
@@ -0,0 +1,8 @@
1
+ import { Kernel } from "./kernel.mjs";
2
+
3
+ //#region src/internal/kernel-registry.d.ts
4
+ declare function registerKernel(kernel: Kernel): void;
5
+ declare function unregisterKernel(kernel: Kernel): void;
6
+ declare function activeKernel(): Kernel | null;
7
+ //#endregion
8
+ export { activeKernel, registerKernel, unregisterKernel };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel-registry.d.mts","names":[],"sources":["../../src/internal/kernel-registry.ts"],"mappings":";;;iBAsBgB,cAAA,CAAe,MAAc,EAAN,MAAM;AAAA,iBAS7B,gBAAA,CAAiB,MAAc,EAAN,MAAM;AAAA,iBAM/B,YAAA,CAAA,GAAgB,MAAM"}
@@ -0,0 +1 @@
1
+ import{createLogger}from"../util/log.mjs";const log=createLogger(`kernel-registry`);let active=null;function registerKernel(kernel){active&&active!==kernel&&log.warn(`init() called twice with different kernels; later one wins. The public capture()/span() helpers route only to the latest kernel — multi-surface apps should call kernel.recordException() directly.`),active=kernel}function unregisterKernel(kernel){active===kernel&&(active=null)}function activeKernel(){return active}export{activeKernel,registerKernel,unregisterKernel};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel-registry.mjs","names":[],"sources":["../../src/internal/kernel-registry.ts"],"sourcesContent":["import { createLogger } from \"../util/log.js\";\nimport type { Kernel } from \"./kernel.js\";\n\nconst log = createLogger(\"kernel-registry\");\n\n/**\n * Module-scoped active kernel reference. The framework wrapper\n * (`@interfere/next`, `@interfere/vite`) registers its kernel here on\n * `init()` so the public `api.ts` helpers can find it without each customer\n * call site threading the kernel through.\n *\n * Single-kernel by design: each app bundle has its own module instance, so\n * the common case (one app, one init) gets a clean global. The warn on\n * overwrite catches HMR / accidental double-init / module-federated MFEs\n * that share `@interfere/react` across surfaces — those setups need to\n * reach for `kernel.recordException()` directly rather than the registry.\n *\n * @internal Wrappers only. Importing this from app code will silently\n * de-fang the public api helpers.\n */\nlet active: Kernel | null = null;\n\nexport function registerKernel(kernel: Kernel): void {\n if (active && active !== kernel) {\n log.warn(\n \"init() called twice with different kernels; later one wins. The public capture()/span() helpers route only to the latest kernel — multi-surface apps should call kernel.recordException() directly.\"\n );\n }\n active = kernel;\n}\n\nexport function unregisterKernel(kernel: Kernel): void {\n if (active === kernel) {\n active = null;\n }\n}\n\nexport function activeKernel(): Kernel | null {\n return active;\n}\n"],"mappings":"0CAGA,MAAM,IAAM,aAAa,iBAAiB,EAiB1C,IAAI,OAAwB,KAE5B,SAAgB,eAAe,OAAsB,CAC/C,QAAU,SAAW,QACvB,IAAI,KACF,qMACF,EAEF,OAAS,MACX,CAEA,SAAgB,iBAAiB,OAAsB,CACjD,SAAW,SACb,OAAS,KAEb,CAEA,SAAgB,cAA8B,CAC5C,OAAO,MACT"}
@@ -0,0 +1,267 @@
1
+ import { PluginContext } from "../plugins/lib/types.mjs";
2
+ import { PluginOverrides } from "../plugins/lib/loader.mjs";
3
+ import { SessionTracker } from "../tracking/api.mjs";
4
+ import { OtelProviderHandle } from "./otel/provider.mjs";
5
+ import { PluginRuntime } from "./plugin-runtime.mjs";
6
+ import { NonErrorException } from "@interfere/types/sdk/errors";
7
+ import { ConsentState } from "@interfere/types/sdk/plugins/manifest";
8
+ import { ReleaseSlug } from "@interfere/types/releases/slug";
9
+ import { MetricReader } from "@opentelemetry/sdk-metrics";
10
+ import { LogRecordProcessor } from "@opentelemetry/sdk-logs";
11
+ import { SpanProcessor } from "@opentelemetry/sdk-trace-base";
12
+ import { IngestedFrame } from "@interfere/types/data/frame";
13
+ import { SessionId } from "@interfere/types/data/session";
14
+ import { IdentifyParams } from "@interfere/types/sdk/identify";
15
+ import { ErrorMechanism } from "@interfere/types/sdk/plugins/payload/errors";
16
+
17
+ //#region src/internal/kernel.d.ts
18
+ declare function buildSdkStack(wrapperVersions?: string[]): string[];
19
+ interface KernelOptions {
20
+ consent?: ConsentState;
21
+ /**
22
+ * Override the automatic dev-mode guard. When `undefined`, the SDK
23
+ * auto-detects: it disables itself if `process.env["NODE_ENV"]` is not
24
+ * `"production"` (Node / webpack / Next.js). In environments where
25
+ * `process` does not exist (Vite, CRA, plain browser) the SDK
26
+ * defaults to **enabled** — pass `false` to disable explicitly.
27
+ */
28
+ enabled?: boolean;
29
+ /** Override `globalThis.fetch` for tests / non-browser hosts. */
30
+ fetch?: typeof globalThis.fetch;
31
+ plugins?: PluginOverrides;
32
+ /**
33
+ * Override the OTel `service.name` resource attribute. Defaults to
34
+ * `"interfere-sdk"`. Customers running multiple frontends in one
35
+ * monitoring backend (e.g. `"@interfere/homepage"` vs
36
+ * `"@interfere/dashboard"`) set this so spans/metrics/logs slice
37
+ * cleanly by surface.
38
+ */
39
+ serviceName?: string;
40
+ /**
41
+ * `false` skips the OTel module entirely — the bundler code-splits
42
+ * `internal/otel/*` out of this path so the error-only bundle never
43
+ * imports the OTel SDK. `true` (default) loads it with default
44
+ * instrumentation config. An object loads it with the supplied
45
+ * config.
46
+ */
47
+ tracing?: boolean | TracingOptions;
48
+ }
49
+ /**
50
+ * Per-instrumentation tuning. Every field is optional; defaults match
51
+ * what `interfere/homepage` and `interfere/dashboard` use today via
52
+ * the internal `observability/browser/rum.ts`. New customers don't
53
+ * need to touch any of these — sensible defaults ship out of the box.
54
+ */
55
+ interface TracingOptions {
56
+ /**
57
+ * Additional URL patterns to skip when creating fetch / XHR spans.
58
+ * The SDK's own collector endpoint is always ignored; customer-side
59
+ * third-party SDKs (Clerk, Sentry, GTM, etc.) are also skipped by
60
+ * default — supplement with anything specific to your app.
61
+ */
62
+ ignoreUrls?: (string | RegExp)[];
63
+ /**
64
+ * URL patterns that should receive W3C `traceparent` + `baggage`
65
+ * headers on outgoing fetch / XHR. Same-origin requests always
66
+ * propagate; this allowlist enables cross-origin propagation
67
+ * (separate API origin, internal service mesh, etc.).
68
+ */
69
+ propagateContextUrls?: (string | RegExp)[];
70
+ /**
71
+ * Resolve a URL pathname to a low-cardinality route template
72
+ * (e.g. `/blog/[slug]`). Without this, dynamic routes produce one
73
+ * unique span / metric label per visited slug — a cardinality
74
+ * hazard. Used by fetch, document-load resource enrichment,
75
+ * user-interaction, long-task, and web-vitals.
76
+ */
77
+ resolveRoute?: (pathname: string) => string | undefined;
78
+ /**
79
+ * `false` disables Core Web Vitals capture (LCP/FCP/TTFB/INP/CLS).
80
+ * Defaults to enabled; customers who run their own vitals reporting
81
+ * can opt out.
82
+ */
83
+ webVitals?: boolean;
84
+ }
85
+ /**
86
+ * @internal
87
+ * Framework wrappers (`@interfere/next`, `@interfere/vite`) pass extra
88
+ * fields through `createKernel` that customers never set themselves.
89
+ * Kept off the customer-facing `KernelOptions` to make the public surface
90
+ * clean.
91
+ */
92
+ interface KernelInternalOptions extends KernelOptions {
93
+ /**
94
+ * Extra log-record processors fanned into the LoggerProvider's
95
+ * processor list. Used by `@interfere/observability` for internal-only
96
+ * dual-write to BetterStack from `interfere/homepage` +
97
+ * `interfere/dashboard`. **Not part of the customer surface** — the
98
+ * SDK doesn't expose a way to fan-out to other observability vendors.
99
+ */
100
+ _internalAdditionalLogRecordProcessors?: LogRecordProcessor[];
101
+ /**
102
+ * Extra metric readers fanned into the MeterProvider's reader list.
103
+ * See `_internalAdditionalLogRecordProcessors`. Used to keep web
104
+ * vitals histograms landing on the BetterStack-fronting OTel
105
+ * collector after the rum.ts → SDK migration moved the primary path
106
+ * to `/v2/sink` (Tinybird-only).
107
+ */
108
+ _internalAdditionalMetricReaders?: MetricReader[];
109
+ /**
110
+ * Extra span processors fanned into the WebTracerProvider's processor
111
+ * list. See `_internalAdditionalLogRecordProcessors`.
112
+ */
113
+ _internalAdditionalSpanProcessors?: SpanProcessor[];
114
+ /** Wrapper SDK versions (e.g. `@interfere/next@10.0.0`). */
115
+ _wrapperVersions?: string[];
116
+ }
117
+ interface KernelConsent {
118
+ get(): ConsentState | null;
119
+ set(value?: ConsentState): void;
120
+ }
121
+ interface KernelIdentity {
122
+ get(): IdentifyParams | null;
123
+ set(params: IdentifyParams): Promise<void>;
124
+ }
125
+ interface KernelDevice {
126
+ getDeviceId(): string | null;
127
+ getFpHash(): string | null;
128
+ }
129
+ interface KernelSession {
130
+ getId(): SessionId | null;
131
+ getWindowId(): string | null;
132
+ }
133
+ interface RecordExceptionOpts {
134
+ /**
135
+ * Frames always appended to the first exception's stack. Used by
136
+ * `<ErrorBoundary>` to inject React's component-stack frames as
137
+ * supplementary context — these add on top of the real JS frames, they
138
+ * don't replace them.
139
+ */
140
+ readonly appendFrames?: readonly IngestedFrame[];
141
+ /**
142
+ * `error.digest` from React when an RSC server-side throw is
143
+ * sanitised and rebuilt as a synthetic Error on the client. The only
144
+ * identifier that pairs the redacted client capture with the
145
+ * unredacted server capture — enrichment mixes this into the
146
+ * fingerprint so both events group as one problem.
147
+ */
148
+ readonly errorDigest?: string;
149
+ /**
150
+ * Frames adopted only when the first exception's parsed stack is empty.
151
+ * Used by the `window.onerror` handler when the browser hands us
152
+ * source/line/col but the `Error` itself has a degenerate stack — never
153
+ * glued on top of a real stack.
154
+ */
155
+ readonly fallbackFrames?: readonly IngestedFrame[];
156
+ readonly mechanism: ErrorMechanism;
157
+ }
158
+ /**
159
+ * The replacement for the old `Client` god-object. Pure construction graph
160
+ * via `createKernel`; no module-level mutable state, no global lookups.
161
+ * Framework wrappers (`@interfere/next`, `@interfere/vite`) own the
162
+ * singleton lifecycle.
163
+ *
164
+ * Implements `PluginContext` directly: plugins are wired with the kernel
165
+ * itself rather than a closure adapter. The kernel⇄runtime cycle is
166
+ * resolved by constructing the kernel first and binding the runtime via
167
+ * `attachRuntime` immediately after.
168
+ */
169
+ declare class Kernel implements PluginContext {
170
+ readonly consent: KernelConsent;
171
+ readonly identity: KernelIdentity;
172
+ readonly device: KernelDevice;
173
+ readonly session: KernelSession;
174
+ private readonly tracker;
175
+ private readonly seen;
176
+ private runtime;
177
+ private otel;
178
+ private otelDispose;
179
+ private unsubscribePageHidden;
180
+ constructor(tracker: SessionTracker);
181
+ /** @internal Bound by `createKernel` immediately after construction. */
182
+ attachRuntime(runtime: PluginRuntime): void;
183
+ private requireRuntime;
184
+ /** PluginContext shim: plugins expect a non-null string. */
185
+ getSessionId(): string;
186
+ /**
187
+ * Records an exception event on the active OTel span. No envelope
188
+ * path — the SDK is OTel-only. Single dedup boundary: drops repeats
189
+ * of the same `Error` instance, plus browser-extension noise and
190
+ * unresolvable stacks. Upstream callers (the errors plugin's
191
+ * `window.onerror` / `console.error` / `unhandledrejection`, the
192
+ * React error boundary) just call this — they don't pre-filter.
193
+ *
194
+ * Does NOT mark the active span as failed. A console.error inside a
195
+ * customer-owned `span()` block would otherwise taint the customer's
196
+ * span even when the customer caught the error explicitly. The
197
+ * customer's `span()` helper sets status itself when it observes a
198
+ * throw.
199
+ *
200
+ * `appendFrames` are always appended (component-stack supplements);
201
+ * `fallbackFrames` are only adopted when the parsed stack is empty
202
+ * (`window.onerror` source/line/col when the Error has no usable
203
+ * stack). Both ride on the serialised `interfere.exception.chain`
204
+ * attribute when the chain is non-trivial.
205
+ */
206
+ recordException(value: Error | NonErrorException, opts: RecordExceptionOpts): void;
207
+ /**
208
+ * Emits an OTel `LogRecord` via the kernel's logger provider. Used by
209
+ * `plugins/logs.ts` to capture string-only `console.*` calls (the
210
+ * errors plugin still owns Error-bearing console calls — class
211
+ * boundary). No-ops when OTel is not wired (`tracing: false`) since
212
+ * there's no logger provider to emit through.
213
+ */
214
+ recordLog(input: {
215
+ severityText: string;
216
+ severityNumber: number;
217
+ body: string;
218
+ attributes?: Record<string, string>;
219
+ }): void;
220
+ /**
221
+ * Force-flushes the OTel exporters. Returns once they've settled
222
+ * (success or failure) so callers driving unload — page-lifecycle
223
+ * handlers, integration test teardown — can actually await
224
+ * completion. The OTel SDK swallows export errors internally; we
225
+ * surface the resolution either way.
226
+ */
227
+ flush(): Promise<void>;
228
+ /**
229
+ * @internal Wired by `createKernel` after the OTel module has been
230
+ * lazy-loaded. Held on the kernel so `flush()` and `dispose()` can fan
231
+ * out to the providers. The tracer/meter providers stay private —
232
+ * customers don't get raw OTel access; the public surface is the
233
+ * `span()` / `capture()` helpers in `api.ts`.
234
+ */
235
+ attachOtel(handle: OtelProviderHandle, dispose: () => void): void;
236
+ /**
237
+ * Provider-driven consent sync. Pass `undefined` to clear consent (treats
238
+ * the prop as "unmanaged"); pass a state to apply it.
239
+ */
240
+ syncConsent(value: ConsentState | undefined): void;
241
+ dispose(): Promise<void>;
242
+ }
243
+ interface CreateKernelInput {
244
+ opts?: KernelInternalOptions;
245
+ }
246
+ /**
247
+ * Pure construction graph. Awaits the remote-config fetch before resolving,
248
+ * so the runtime sees a fully-applied config before any capture is attempted
249
+ * by the caller. Removes the capture-before-config race the old `Client`
250
+ * had.
251
+ */
252
+ declare function createKernel(input?: CreateKernelInput): Promise<Kernel>;
253
+ declare function isEnabledByEnvironment(): boolean;
254
+ /**
255
+ * Build-time-derived release slug. The build step
256
+ * (`@interfere/next/withInterfere`, `@interfere/vite/plugin`) takes the
257
+ * leading 16 hex chars of the commit SHA (`rel_<16hex>`) and stamps it into
258
+ * the bundle as `__INTERFERE_RELEASE_SLUG__`. The collector derives the same
259
+ * value from the create-release request, so the bundle's runtime slug is
260
+ * guaranteed to match the row without a round-trip.
261
+ *
262
+ * Returns `null` when no slug was injected (dev builds, customers who
263
+ * haven't wired up the plugin).
264
+ */
265
+ declare function readReleaseSlugFromGlobals(): ReleaseSlug | null;
266
+ //#endregion
267
+ export { Kernel, KernelConsent, KernelDevice, KernelIdentity, KernelInternalOptions, KernelOptions, KernelSession, RecordExceptionOpts, TracingOptions, buildSdkStack, createKernel, isEnabledByEnvironment, readReleaseSlugFromGlobals };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel.d.mts","names":[],"sources":["../../src/internal/kernel.ts"],"mappings":";;;;;;;;;;;;;;;;;iBAyCgB,aAAA,CAAc,eAA0B;AAAA,UAyDvC,aAAA;EACf,OAAA,GAAU,YAAA;EA1DI;;;;AAAwC;AAyDxD;;EASE,OAAA;EARU;EAUV,KAAA,UAAe,UAAA,CAAW,KAAA;EAC1B,OAAA,GAAU,eAAA;EAgBU;;;;;;;EARpB,WAAA;EAT0B;;;;;;;EAiB1B,OAAA,aAAoB,cAAA;AAAA;;;;;;;UASL,cAAA;EAsBf;;;;AAMS;AAUX;EA/BE,UAAA,aAAuB,MAAA;;;;;;;EAOvB,oBAAA,aAAiC,MAAM;EAwBM;;;;;;;EAhB7C,YAAA,IAAgB,QAAA;EAuCA;AAAA;AAGlB;;;EApCE,SAAA;AAAA;;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,cAAA;IACA,IAAA;IACA,UAAA,GAAa,MAAA;EAAA;EA+ER;;;;;AACQ;AA4PjB;EAxTQ,KAAA,CAAA,GAAS,OAAA;;;AAwTqB;AAyBtC;;;;EApUE,UAAA,CAAW,MAAA,EAAQ,kBAAA,EAAoB,OAAA;;;;;EASvC,WAAA,CAAY,KAAA,EAAO,YAAA;EASb,OAAA,CAAA,GAAW,OAAA;AAAA;AAAA,UAiBT,iBAAA;EACR,IAAA,GAAO,qBAAqB;AAAA;;;;;;;iBASR,YAAA,CACpB,KAAA,GAAO,iBAAA,GACN,OAAA,CAAQ,MAAA;AAAA,iBA4PK,sBAAA,CAAA;;;;;;;;;;;;iBAyBA,0BAAA,CAAA,GAA8B,WAAW"}
@@ -0,0 +1 @@
1
+ import{createLogger}from"../util/log.mjs";import{getGlobal}from"../util/global.mjs";import{resolveTargets}from"./config.mjs";import{SessionTracker}from"../tracking/api.mjs";import{safeStringify}from"../util/stringify.mjs";import{onPageHidden}from"./page-lifecycle.mjs";import{PluginRuntime}from"./plugin-runtime.mjs";import{registerServiceWorker}from"./sw.mjs";import{PRODUCER_VERSION}from"./version.mjs";import{isNonErrorException,shouldDropBrowserExtensionNoise,shouldDropUnresolvableStack,toExceptions}from"@interfere/types/sdk/errors";import{trace}from"@opentelemetry/api";import{releaseSlugSchema}from"@interfere/types/releases/slug";const log=createLogger(`kernel`),TRAILING_SLASH_RE=/\/$/;function buildSdkStack(wrapperVersions){return[...wrapperVersions??[],PRODUCER_VERSION]}function buildExceptionEventAttrs(value,opts){let attrs={"interfere.exception.mechanism":opts.mechanism.type,"interfere.exception.handled":String(opts.mechanism.handled)};return opts.errorDigest&&(attrs[`interfere.error.digest`]=opts.errorDigest),isNonErrorException(value)?(attrs[`exception.type`]=value.type,attrs[`exception.message`]=value.value,attrs[`interfere.exception.kind`]=`non-error`,attrs[`interfere.exception.serialized`]=safeStringify(value.serialized),attrs):(attrs[`exception.type`]=value.name,attrs[`exception.message`]=value.message,attrs[`interfere.exception.kind`]=`error`,value.stack&&(attrs[`exception.stacktrace`]=value.stack),attrs[`interfere.exception.chain`]=safeStringify(toExceptions(value,opts.mechanism)),opts.appendFrames&&opts.appendFrames.length>0&&(attrs[`interfere.exception.appended_frames`]=safeStringify(opts.appendFrames)),opts.fallbackFrames&&opts.fallbackFrames.length>0&&(attrs[`interfere.exception.fallback_frames`]=safeStringify(opts.fallbackFrames)),attrs)}var Kernel=class{consent;identity;device;session;tracker;seen=new WeakSet;runtime=null;otel=null;otelDispose=null;unsubscribePageHidden=null;constructor(tracker){this.tracker=tracker,this.consent={get:()=>this.requireRuntime().getConsent(),set:value=>{let runtime=this.requireRuntime();value?runtime.setConsent(value):runtime.resetConsent()}},this.identity={get:()=>this.tracker.getIdentity(),set:params=>this.tracker.identify(params)},this.device={getDeviceId:()=>this.tracker.getDeviceId(),getFpHash:()=>this.tracker.getFpHash()},this.session={getId:()=>this.tracker.sessionId(),getWindowId:()=>this.tracker.windowId()},this.unsubscribePageHidden=onPageHidden(()=>{this.flush().catch(()=>void 0)})}attachRuntime(runtime){this.runtime=runtime}requireRuntime(){if(!this.runtime)throw Error(`Kernel runtime not attached. createKernel must call attachRuntime before any consent/dispose path runs.`);return this.runtime}getSessionId(){return this.tracker.sessionId()??``}recordException(value,opts){if(!isNonErrorException(value)){if(this.seen.has(value))return;this.seen.add(value)}if(!isNonErrorException(value)){let stacks=[],current=value;for(let depth=0;current&&depth<5;depth+=1)current.stack&&stacks.push(current.stack),current=current.cause instanceof Error?current.cause:void 0;if(shouldDropBrowserExtensionNoise(stacks)||shouldDropUnresolvableStack(stacks))return}let span=trace.getActiveSpan();span&&span.addEvent(`exception`,buildExceptionEventAttrs(value,opts))}recordLog(input){this.otel&&this.otel.loggerProvider.getLogger(`@interfere/react`).emit({severityText:input.severityText,severityNumber:input.severityNumber,body:input.body,...input.attributes?{attributes:input.attributes}:{}})}async flush(){this.otel&&await this.otel.flush()}attachOtel(handle,dispose){this.otel=handle,this.otelDispose=dispose}syncConsent(value){let runtime=this.requireRuntime();if(value){runtime.setConsent(value);return}runtime.resetConsent()}async dispose(){this.unsubscribePageHidden?.(),this.unsubscribePageHidden=null,this.runtime&&await this.runtime.dispose(),this.tracker.dispose(),this.otelDispose?.(),this.otelDispose=null,this.otel&&=(await this.otel.shutdown(),null)}};async function createKernel(input={}){let{opts={}}=input,fetcher=opts.fetch??globalThis.fetch.bind(globalThis),targets=resolveTargets();log.info(`collector: %s`,targets.collectorBaseUrl),getGlobal(`__INTERFERE_FORCE_ENABLE__`)&&log.warn(`FORCE_ENABLE is active. Events will be dropped by production collectors. This should only be set during local development.`);let tracker=new SessionTracker({target:targets.session,fetcher});opts._wrapperVersions?.length&&(globalThis.__INTERFERE_SDK_STACK__=opts._wrapperVersions);let kernel=new Kernel(tracker),runtime=new PluginRuntime(kernel,opts.plugins,opts.consent);if(kernel.attachRuntime(runtime),tracker.start(),runtime.start(),opts.tracing!==!1){let tracingOpts=typeof opts.tracing==`object`?opts.tracing:void 0;await wireOtel(kernel,targets,opts._wrapperVersions,{...tracingOpts??{},...opts.serviceName?{serviceName:opts.serviceName}:{},...opts._internalAdditionalSpanProcessors?{additionalSpanProcessors:opts._internalAdditionalSpanProcessors}:{},...opts._internalAdditionalLogRecordProcessors?{additionalLogRecordProcessors:opts._internalAdditionalLogRecordProcessors}:{},...opts._internalAdditionalMetricReaders?{additionalMetricReaders:opts._internalAdditionalMetricReaders}:{}})}return await fetchRemoteConfig(targets.config,fetcher,runtime),registerServiceWorker({onMessage:msg=>recordSwMessage(kernel,msg)}).catch(()=>{}),kernel}function recordSwMessage(kernel,msg){kernel.recordLog({severityText:`info`,severityNumber:9,body:msg.type,attributes:{"url.full":msg.url,...msg.reason?{"interfere.sw.reason":msg.reason}:{}}})}async function wireOtel(kernel,targets,wrapperVersions,tracing){let{buildOtelProvider,captureWebVitals,readPropagationFromDocument,registerBundledInstrumentations}=await import(`./otel/index.mjs`),collectorUrl=targets.collectorBaseUrl.replace(TRAILING_SLASH_RE,``),releaseSlug=readReleaseSlugFromGlobals(),handle=buildOtelProvider({collectorUrl,authHeaders:targets.ingest.headers,sdkStack:buildSdkStack(wrapperVersions),getSessionId:()=>kernel.session.getId(),deviceId:kernel.device.getDeviceId(),releaseSlug,...tracing.serviceName?{serviceName:tracing.serviceName}:{},...tracing.additionalSpanProcessors?{additionalSpanProcessors:tracing.additionalSpanProcessors}:{},...tracing.additionalLogRecordProcessors?{additionalLogRecordProcessors:tracing.additionalLogRecordProcessors}:{},...tracing.additionalMetricReaders?{additionalMetricReaders:tracing.additionalMetricReaders}:{}}),extracted=readPropagationFromDocument();extracted&&handle.contextManager.setPageScope(extracted);let dispose=registerBundledInstrumentations({tracerProvider:handle.tracerProvider,ignoreUrls:[`${collectorUrl}/v2/sink`,targets.config.url,targets.session.url],...tracing.propagateContextUrls?{propagateContextUrls:tracing.propagateContextUrls}:{},...tracing.resolveRoute?{resolveRoute:tracing.resolveRoute}:{}});tracing.webVitals!==!1&&captureWebVitals({meter:handle.meterProvider.getMeter(`@interfere/react/web-vitals`),flush:()=>handle.flush(),...tracing.resolveRoute?{resolveRoute:tracing.resolveRoute}:{}}),kernel.attachOtel(handle,dispose)}async function fetchRemoteConfig(configTarget,fetcher,runtime){try{let headers=Object.fromEntries(configTarget.headers.entries()),res=await fetcher(configTarget.url,{method:`GET`,headers,signal:AbortSignal.timeout(1e4)});if(!res.ok)return;let config=await res.json();config?.plugins&&(runtime.applyRemoteConfig(config.plugins),log.debug(`applied remote config`))}catch{log.warn(`remote config fetch failed, using local defaults`)}}function isEnabledByEnvironment(){if(typeof process>`u`||!process.env)return!0;let nodeEnv=process.env.NODE_ENV;return nodeEnv===`production`||nodeEnv===void 0?!0:!!(getGlobal(`__INTERFERE_FORCE_ENABLE__`)||process.env.INTERFERE_FORCE_ENABLE)}function readReleaseSlugFromGlobals(){let value=getGlobal(`__INTERFERE_RELEASE_SLUG__`);return typeof value==`string`?releaseSlugSchema.parse(value):null}export{Kernel,buildSdkStack,createKernel,isEnabledByEnvironment,readReleaseSlugFromGlobals};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel.mjs","names":[],"sources":["../../src/internal/kernel.ts"],"sourcesContent":["import type { IngestedFrame } from \"@interfere/types/data/frame\";\nimport type { SessionId } from \"@interfere/types/data/session\";\nimport {\n type ReleaseSlug,\n releaseSlugSchema,\n} from \"@interfere/types/releases/slug\";\nimport {\n isNonErrorException,\n type NonErrorException,\n shouldDropBrowserExtensionNoise,\n shouldDropUnresolvableStack,\n toExceptions,\n} from \"@interfere/types/sdk/errors\";\nimport type { IdentifyParams } from \"@interfere/types/sdk/identify\";\nimport type { ConsentState } from \"@interfere/types/sdk/plugins/manifest\";\nimport type { ErrorMechanism } from \"@interfere/types/sdk/plugins/payload/errors\";\nimport type { RemoteConfig } from \"@interfere/types/sdk/remote-config\";\n\nimport { trace } from \"@opentelemetry/api\";\nimport type { LogRecordProcessor } from \"@opentelemetry/sdk-logs\";\nimport type { MetricReader } from \"@opentelemetry/sdk-metrics\";\nimport type { SpanProcessor } from \"@opentelemetry/sdk-trace-base\";\n\nimport type { PluginOverrides } from \"../plugins/lib/loader.js\";\nimport type { PluginContext } from \"../plugins/lib/types.js\";\nimport { SessionTracker } from \"../tracking/api.js\";\nimport { getGlobal } from \"../util/global.js\";\nimport { createLogger } from \"../util/log.js\";\nimport { safeStringify } from \"../util/stringify.js\";\nimport type { AuthHeaders, IngestTarget } from \"./config.js\";\nimport { resolveTargets } from \"./config.js\";\nimport type { OtelProviderHandle } from \"./otel/index.js\";\nimport { onPageHidden } from \"./page-lifecycle.js\";\nimport { PluginRuntime } from \"./plugin-runtime.js\";\nimport { registerServiceWorker, type SwMessage } from \"./sw.js\";\nimport { PRODUCER_VERSION } from \"./version.js\";\n\nconst log = createLogger(\"kernel\");\n\nconst TRAILING_SLASH_RE = /\\/$/;\n\nexport function buildSdkStack(wrapperVersions?: string[]): string[] {\n return [...(wrapperVersions ?? []), PRODUCER_VERSION];\n}\n\nfunction buildExceptionEventAttrs(\n value: Error | NonErrorException,\n opts: RecordExceptionOpts\n): Record<string, string> {\n const attrs: Record<string, string> = {\n \"interfere.exception.mechanism\": opts.mechanism.type,\n \"interfere.exception.handled\": String(opts.mechanism.handled),\n };\n if (opts.errorDigest) {\n attrs[\"interfere.error.digest\"] = opts.errorDigest;\n }\n if (isNonErrorException(value)) {\n attrs[\"exception.type\"] = value.type;\n attrs[\"exception.message\"] = value.value;\n attrs[\"interfere.exception.kind\"] = \"non-error\";\n // OTel attrs are scalars; serialize the structured payload so the\n // OTLP mapper can reconstruct it server-side.\n attrs[\"interfere.exception.serialized\"] = safeStringify(value.serialized);\n return attrs;\n }\n attrs[\"exception.type\"] = value.name;\n attrs[\"exception.message\"] = value.message;\n attrs[\"interfere.exception.kind\"] = \"error\";\n if (value.stack) {\n attrs[\"exception.stacktrace\"] = value.stack;\n }\n // Walk Error.cause and ship every entry on a single attr. Each entry\n // carries `{type, value, mechanism?, kind, stack}` — the SDK does not\n // parse stacks; the collector parses `stack` server-side.\n attrs[\"interfere.exception.chain\"] = safeStringify(\n toExceptions(value, opts.mechanism)\n );\n // Supplementary frames the SDK has runtime context to assemble that\n // the server can't synthesise from the raw stack:\n // - `appendFrames`: parsed React component-stack frames (regex\n // parser stays in the SDK — React-specific format, tiny).\n // - `fallbackFrames`: source/line/col tuple from `window.onerror`\n // when the Error's `.stack` is degenerate (CORS-masked, etc.).\n // The collector mapper merges these into the `frames` column after\n // parsing the raw JS stack.\n if (opts.appendFrames && opts.appendFrames.length > 0) {\n attrs[\"interfere.exception.appended_frames\"] = safeStringify(\n opts.appendFrames\n );\n }\n if (opts.fallbackFrames && opts.fallbackFrames.length > 0) {\n attrs[\"interfere.exception.fallback_frames\"] = safeStringify(\n opts.fallbackFrames\n );\n }\n return attrs;\n}\n\nexport interface KernelOptions {\n consent?: ConsentState;\n /**\n * Override the automatic dev-mode guard. When `undefined`, the SDK\n * auto-detects: it disables itself if `process.env[\"NODE_ENV\"]` is not\n * `\"production\"` (Node / webpack / Next.js). In environments where\n * `process` does not exist (Vite, CRA, plain browser) the SDK\n * defaults to **enabled** — pass `false` to disable explicitly.\n */\n enabled?: boolean;\n /** Override `globalThis.fetch` for tests / non-browser hosts. */\n fetch?: typeof globalThis.fetch;\n plugins?: PluginOverrides;\n /**\n * Override the OTel `service.name` resource attribute. Defaults to\n * `\"interfere-sdk\"`. Customers running multiple frontends in one\n * monitoring backend (e.g. `\"@interfere/homepage\"` vs\n * `\"@interfere/dashboard\"`) set this so spans/metrics/logs slice\n * cleanly by surface.\n */\n serviceName?: string;\n /**\n * `false` skips the OTel module entirely — the bundler code-splits\n * `internal/otel/*` out of this path so the error-only bundle never\n * imports the OTel SDK. `true` (default) loads it with default\n * instrumentation config. An object loads it with the supplied\n * config.\n */\n tracing?: boolean | TracingOptions;\n}\n\n/**\n * Per-instrumentation tuning. Every field is optional; defaults match\n * what `interfere/homepage` and `interfere/dashboard` use today via\n * the internal `observability/browser/rum.ts`. New customers don't\n * need to touch any of these — sensible defaults ship out of the box.\n */\nexport interface TracingOptions {\n /**\n * Additional URL patterns to skip when creating fetch / XHR spans.\n * The SDK's own collector endpoint is always ignored; customer-side\n * third-party SDKs (Clerk, Sentry, GTM, etc.) are also skipped by\n * default — supplement with anything specific to your app.\n */\n ignoreUrls?: (string | RegExp)[];\n /**\n * URL patterns that should receive W3C `traceparent` + `baggage`\n * headers on outgoing fetch / XHR. Same-origin requests always\n * propagate; this allowlist enables cross-origin propagation\n * (separate API origin, internal service mesh, etc.).\n */\n propagateContextUrls?: (string | RegExp)[];\n /**\n * Resolve a URL pathname to a low-cardinality route template\n * (e.g. `/blog/[slug]`). Without this, dynamic routes produce one\n * unique span / metric label per visited slug — a cardinality\n * hazard. Used by fetch, document-load resource enrichment,\n * user-interaction, long-task, and web-vitals.\n */\n resolveRoute?: (pathname: string) => string | undefined;\n /**\n * `false` disables Core Web Vitals capture (LCP/FCP/TTFB/INP/CLS).\n * Defaults to enabled; customers who run their own vitals reporting\n * can opt out.\n */\n webVitals?: boolean;\n}\n\n/**\n * @internal\n * Framework wrappers (`@interfere/next`, `@interfere/vite`) pass extra\n * fields through `createKernel` that customers never set themselves.\n * Kept off the customer-facing `KernelOptions` to make the public surface\n * clean.\n */\nexport interface KernelInternalOptions extends KernelOptions {\n /**\n * Extra log-record processors fanned into the LoggerProvider's\n * processor list. Used by `@interfere/observability` for internal-only\n * dual-write to BetterStack from `interfere/homepage` +\n * `interfere/dashboard`. **Not part of the customer surface** — the\n * SDK doesn't expose a way to fan-out to other observability vendors.\n */\n _internalAdditionalLogRecordProcessors?: LogRecordProcessor[];\n /**\n * Extra metric readers fanned into the MeterProvider's reader list.\n * See `_internalAdditionalLogRecordProcessors`. Used to keep web\n * vitals histograms landing on the BetterStack-fronting OTel\n * collector after the rum.ts → SDK migration moved the primary path\n * to `/v2/sink` (Tinybird-only).\n */\n _internalAdditionalMetricReaders?: MetricReader[];\n /**\n * Extra span processors fanned into the WebTracerProvider's processor\n * list. See `_internalAdditionalLogRecordProcessors`.\n */\n _internalAdditionalSpanProcessors?: SpanProcessor[];\n /** Wrapper SDK versions (e.g. `@interfere/next@10.0.0`). */\n _wrapperVersions?: string[];\n}\n\nexport interface KernelConsent {\n get(): ConsentState | null;\n set(value?: ConsentState): void;\n}\n\nexport interface KernelIdentity {\n get(): IdentifyParams | null;\n set(params: IdentifyParams): Promise<void>;\n}\n\nexport interface KernelDevice {\n getDeviceId(): string | null;\n getFpHash(): string | null;\n}\n\nexport interface KernelSession {\n getId(): SessionId | null;\n getWindowId(): string | null;\n}\n\nexport interface RecordExceptionOpts {\n /**\n * Frames always appended to the first exception's stack. Used by\n * `<ErrorBoundary>` to inject React's component-stack frames as\n * supplementary context — these add on top of the real JS frames, they\n * don't replace them.\n */\n readonly appendFrames?: readonly IngestedFrame[];\n /**\n * `error.digest` from React when an RSC server-side throw is\n * sanitised and rebuilt as a synthetic Error on the client. The only\n * identifier that pairs the redacted client capture with the\n * unredacted server capture — enrichment mixes this into the\n * fingerprint so both events group as one problem.\n */\n readonly errorDigest?: string;\n /**\n * Frames adopted only when the first exception's parsed stack is empty.\n * Used by the `window.onerror` handler when the browser hands us\n * source/line/col but the `Error` itself has a degenerate stack — never\n * glued on top of a real stack.\n */\n readonly fallbackFrames?: readonly IngestedFrame[];\n readonly mechanism: ErrorMechanism;\n}\n\n/**\n * The replacement for the old `Client` god-object. Pure construction graph\n * via `createKernel`; no module-level mutable state, no global lookups.\n * Framework wrappers (`@interfere/next`, `@interfere/vite`) own the\n * singleton lifecycle.\n *\n * Implements `PluginContext` directly: plugins are wired with the kernel\n * itself rather than a closure adapter. The kernel⇄runtime cycle is\n * resolved by constructing the kernel first and binding the runtime via\n * `attachRuntime` immediately after.\n */\nexport class Kernel implements PluginContext {\n readonly consent: KernelConsent;\n readonly identity: KernelIdentity;\n readonly device: KernelDevice;\n readonly session: KernelSession;\n\n private readonly tracker: SessionTracker;\n // Single dedup authority for `recordException`. WeakSet so GC'd errors\n // don't pin memory. Upstream callers do not pre-filter.\n private readonly seen = new WeakSet<Error>();\n // Lateinit. `createKernel` constructs the kernel first, then the runtime\n // (passing the kernel as `PluginContext`), then calls `attachRuntime`.\n // Anything kernel-side that touches `runtime` (consent / dispose) runs\n // after the bind.\n private runtime: PluginRuntime | null = null;\n private otel: OtelProviderHandle | null = null;\n private otelDispose: (() => void) | null = null;\n private unsubscribePageHidden: (() => void) | null = null;\n\n constructor(tracker: SessionTracker) {\n this.tracker = tracker;\n\n this.consent = {\n get: () => this.requireRuntime().getConsent(),\n set: (value) => {\n const runtime = this.requireRuntime();\n if (value) {\n runtime.setConsent(value);\n } else {\n runtime.resetConsent();\n }\n },\n };\n\n this.identity = {\n get: () => this.tracker.getIdentity(),\n set: (params) => this.tracker.identify(params),\n };\n\n this.device = {\n getDeviceId: () => this.tracker.getDeviceId(),\n getFpHash: () => this.tracker.getFpHash(),\n };\n\n this.session = {\n getId: () => this.tracker.sessionId(),\n getWindowId: () => this.tracker.windowId(),\n };\n\n // Force-flush the OTel exporters when the tab is about to be hidden.\n // Tail spans + web vitals (CLS/INP fire on visibility hidden) are\n // otherwise lost when the user navigates away. Subscription removed\n // in `dispose()`.\n this.unsubscribePageHidden = onPageHidden(() => {\n // Fire-and-forget — we can't block the unload path.\n this.flush().catch(() => undefined);\n });\n }\n\n /** @internal Bound by `createKernel` immediately after construction. */\n attachRuntime(runtime: PluginRuntime): void {\n this.runtime = runtime;\n }\n\n private requireRuntime(): PluginRuntime {\n if (!this.runtime) {\n throw new Error(\n \"Kernel runtime not attached. createKernel must call attachRuntime before any consent/dispose path runs.\"\n );\n }\n return this.runtime;\n }\n\n /** PluginContext shim: plugins expect a non-null string. */\n getSessionId(): string {\n return this.tracker.sessionId() ?? \"\";\n }\n\n /**\n * Records an exception event on the active OTel span. No envelope\n * path — the SDK is OTel-only. Single dedup boundary: drops repeats\n * of the same `Error` instance, plus browser-extension noise and\n * unresolvable stacks. Upstream callers (the errors plugin's\n * `window.onerror` / `console.error` / `unhandledrejection`, the\n * React error boundary) just call this — they don't pre-filter.\n *\n * Does NOT mark the active span as failed. A console.error inside a\n * customer-owned `span()` block would otherwise taint the customer's\n * span even when the customer caught the error explicitly. The\n * customer's `span()` helper sets status itself when it observes a\n * throw.\n *\n * `appendFrames` are always appended (component-stack supplements);\n * `fallbackFrames` are only adopted when the parsed stack is empty\n * (`window.onerror` source/line/col when the Error has no usable\n * stack). Both ride on the serialised `interfere.exception.chain`\n * attribute when the chain is non-trivial.\n */\n recordException(\n value: Error | NonErrorException,\n opts: RecordExceptionOpts\n ): void {\n // Dedup applies only to real Errors. NonErrorException is a fresh\n // object on every capture site (`toException(event.reason)` allocates\n // it inline) so the WeakSet would never see a repeat anyway.\n if (!isNonErrorException(value)) {\n if (this.seen.has(value)) {\n return;\n }\n this.seen.add(value);\n }\n\n // Noise filters operate on the raw stack strings — Error variants\n // only. Non-Error rejections carry no stack to inspect, but they\n // ship structured payloads the agent can reason over directly, so\n // they're never dropped here.\n if (!isNonErrorException(value)) {\n const stacks: string[] = [];\n let current: Error | undefined = value;\n for (let depth = 0; current && depth < 5; depth += 1) {\n if (current.stack) {\n stacks.push(current.stack);\n }\n current = current.cause instanceof Error ? current.cause : undefined;\n }\n if (\n shouldDropBrowserExtensionNoise(stacks) ||\n shouldDropUnresolvableStack(stacks)\n ) {\n return;\n }\n }\n\n // Stamp our mechanism taxonomy onto the OTel exception event so the\n // collector mapper can recover handled / unhandled and the\n // originating mechanism (browser.onerror / unhandledrejection /\n // manual.api.capture / etc.). OTel's standard `recordException`\n // only carries type/message/stack; mechanism is our enrichment, so\n // we emit the event ourselves via `addEvent` with the full attr\n // set.\n const span = trace.getActiveSpan();\n if (span) {\n span.addEvent(\"exception\", buildExceptionEventAttrs(value, opts));\n }\n }\n\n /**\n * Emits an OTel `LogRecord` via the kernel's logger provider. Used by\n * `plugins/logs.ts` to capture string-only `console.*` calls (the\n * errors plugin still owns Error-bearing console calls — class\n * boundary). No-ops when OTel is not wired (`tracing: false`) since\n * there's no logger provider to emit through.\n */\n recordLog(input: {\n severityText: string;\n severityNumber: number;\n body: string;\n attributes?: Record<string, string>;\n }): void {\n if (!this.otel) {\n return;\n }\n this.otel.loggerProvider.getLogger(\"@interfere/react\").emit({\n severityText: input.severityText,\n severityNumber: input.severityNumber,\n body: input.body,\n ...(input.attributes ? { attributes: input.attributes } : {}),\n });\n }\n\n /**\n * Force-flushes the OTel exporters. Returns once they've settled\n * (success or failure) so callers driving unload — page-lifecycle\n * handlers, integration test teardown — can actually await\n * completion. The OTel SDK swallows export errors internally; we\n * surface the resolution either way.\n */\n async flush(): Promise<void> {\n if (this.otel) {\n await this.otel.flush();\n }\n }\n\n /**\n * @internal Wired by `createKernel` after the OTel module has been\n * lazy-loaded. Held on the kernel so `flush()` and `dispose()` can fan\n * out to the providers. The tracer/meter providers stay private —\n * customers don't get raw OTel access; the public surface is the\n * `span()` / `capture()` helpers in `api.ts`.\n */\n attachOtel(handle: OtelProviderHandle, dispose: () => void): void {\n this.otel = handle;\n this.otelDispose = dispose;\n }\n\n /**\n * Provider-driven consent sync. Pass `undefined` to clear consent (treats\n * the prop as \"unmanaged\"); pass a state to apply it.\n */\n syncConsent(value: ConsentState | undefined): void {\n const runtime = this.requireRuntime();\n if (value) {\n runtime.setConsent(value);\n return;\n }\n runtime.resetConsent();\n }\n\n async dispose(): Promise<void> {\n this.unsubscribePageHidden?.();\n this.unsubscribePageHidden = null;\n if (this.runtime) {\n await this.runtime.dispose();\n }\n this.tracker.dispose();\n\n this.otelDispose?.();\n this.otelDispose = null;\n if (this.otel) {\n await this.otel.shutdown();\n this.otel = null;\n }\n }\n}\n\ninterface CreateKernelInput {\n opts?: KernelInternalOptions;\n}\n\n/**\n * Pure construction graph. Awaits the remote-config fetch before resolving,\n * so the runtime sees a fully-applied config before any capture is attempted\n * by the caller. Removes the capture-before-config race the old `Client`\n * had.\n */\nexport async function createKernel(\n input: CreateKernelInput = {}\n): Promise<Kernel> {\n const { opts = {} } = input;\n const fetcher = opts.fetch ?? globalThis.fetch.bind(globalThis);\n const targets = resolveTargets();\n\n log.info(\"collector: %s\", targets.collectorBaseUrl);\n\n // Misconfigured prod (NODE_ENV missing/wrong + force-enable on) would\n // happily ship the header to a prod collector and have every event\n // silently dropped. The collector returns a structured `dropped` reason\n // so dev tools can surface it, but the warning here is the first line\n // of defense — fires at most once per kernel construction.\n if (getGlobal<boolean>(\"__INTERFERE_FORCE_ENABLE__\")) {\n log.warn(\n \"FORCE_ENABLE is active. Events will be dropped by production collectors. This should only be set during local development.\"\n );\n }\n\n const tracker = new SessionTracker({ target: targets.session, fetcher });\n\n // Single write site for the SDK-stack global. The OTLP exporter\n // headers and the OTel resource attribute both attribute events to\n // the producer chain (`@interfere/next@10.0.0`,\n // `@interfere/react@10.0.0`, …). Wrapper passes `_wrapperVersions`;\n // the kernel publishes the resulting stack here.\n if (opts._wrapperVersions?.length) {\n (globalThis as Record<string, unknown>)[\"__INTERFERE_SDK_STACK__\"] =\n opts._wrapperVersions;\n }\n\n // Resolve the kernel⇄runtime cycle by constructing the kernel first\n // (without runtime), then the runtime with the kernel as PluginContext,\n // then binding. No closure adapter — plugins call the kernel directly.\n const kernel = new Kernel(tracker);\n const runtime = new PluginRuntime(kernel, opts.plugins, opts.consent);\n kernel.attachRuntime(runtime);\n\n tracker.start();\n runtime.start();\n\n if (opts.tracing !== false) {\n const tracingOpts =\n typeof opts.tracing === \"object\" ? opts.tracing : undefined;\n await wireOtel(kernel, targets, opts._wrapperVersions, {\n ...(tracingOpts ?? {}),\n ...(opts.serviceName ? { serviceName: opts.serviceName } : {}),\n ...(opts._internalAdditionalSpanProcessors\n ? {\n additionalSpanProcessors: opts._internalAdditionalSpanProcessors,\n }\n : {}),\n ...(opts._internalAdditionalLogRecordProcessors\n ? {\n additionalLogRecordProcessors:\n opts._internalAdditionalLogRecordProcessors,\n }\n : {}),\n ...(opts._internalAdditionalMetricReaders\n ? {\n additionalMetricReaders: opts._internalAdditionalMetricReaders,\n }\n : {}),\n });\n }\n\n await fetchRemoteConfig(targets.config, fetcher, runtime);\n\n // Service-worker registration is best-effort and never blocks\n // kernel resolution. The SW intercepts `/api/interfere/*` POSTs\n // from the page and queues failures in IndexedDB so OTel batches\n // survive page-hide / offline / >30s collector blips. See\n // `internal/sw.ts`.\n registerServiceWorker({\n onMessage: (msg) => recordSwMessage(kernel, msg),\n }).catch(() => {\n // registerServiceWorker is best-effort and swallows its own\n // failures; this catch is just to satisfy biome's no-floating-\n // promise rule without using `void`.\n });\n\n return kernel;\n}\n\nfunction recordSwMessage(\n kernel: { recordLog: Kernel[\"recordLog\"] },\n msg: SwMessage\n): void {\n // SW activity rides as INFO LogRecords so dashboards can rank\n // queued vs replayed vs dropped without a new metric surface. The\n // SW runs in its own context — we only see what gets posted back\n // when a page is open, which is fine: \"did the SW catch anything\"\n // is the question dashboards need to answer.\n kernel.recordLog({\n severityText: \"info\",\n severityNumber: 9,\n body: msg.type,\n attributes: {\n \"url.full\": msg.url,\n ...(msg.reason ? { \"interfere.sw.reason\": msg.reason } : {}),\n },\n });\n}\n\n/**\n * Lazy-imports the OTel module so `init({ tracing: false })` keeps the\n * error-only bundle path light — the dynamic `import()` is what tells the\n * bundler to code-split. Inherits the kernel's resolved auth headers so\n * OTLP exports use the same collector URL and headers the rest of the SDK\n * resolved; no separate auth knob.\n *\n * Module-load failures are NOT caught — a bundled dynamic import only\n * fails on OOM or module-federation split-brain, both real problems we\n * want to surface, not silently flip into \"tracing disabled.\"\n */\ninterface ResolvedTracingOptions extends TracingOptions {\n additionalLogRecordProcessors?: LogRecordProcessor[];\n additionalMetricReaders?: MetricReader[];\n additionalSpanProcessors?: SpanProcessor[];\n serviceName?: string;\n}\n\nasync function wireOtel(\n kernel: Kernel,\n targets: {\n collectorBaseUrl: string;\n config: IngestTarget;\n ingest: AuthHeaders;\n session: IngestTarget;\n },\n wrapperVersions: string[] | undefined,\n tracing: ResolvedTracingOptions\n): Promise<void> {\n const {\n buildOtelProvider,\n captureWebVitals,\n readPropagationFromDocument,\n registerBundledInstrumentations,\n } = await import(\"./otel/index.js\");\n\n const collectorUrl = targets.collectorBaseUrl.replace(TRAILING_SLASH_RE, \"\");\n const releaseSlug = readReleaseSlugFromGlobals();\n\n const handle = buildOtelProvider({\n collectorUrl,\n authHeaders: targets.ingest.headers,\n sdkStack: buildSdkStack(wrapperVersions),\n // Session id is read per-span by the session span processor, so a\n // mid-page session rotation is reflected on subsequent spans\n // without rebuilding the provider.\n getSessionId: () => kernel.session.getId(),\n // `device.id` is stable for the page lifetime — `DeviceManager.init()`\n // ran during `createKernel` before this point, so the id is in\n // localStorage / cookie / memory by the time the provider boots.\n // Stamped as a resource attribute so every span / log / metric\n // carries it without per-record re-stamping; the collector projects\n // it into `spans.deviceId`. Without this the column is permanently\n // null in production (which is exactly what we observed in\n // 2026-05-12 telemetry — 0/50,632 spans had a device id).\n deviceId: kernel.device.getDeviceId(),\n releaseSlug,\n ...(tracing.serviceName ? { serviceName: tracing.serviceName } : {}),\n ...(tracing.additionalSpanProcessors\n ? { additionalSpanProcessors: tracing.additionalSpanProcessors }\n : {}),\n ...(tracing.additionalLogRecordProcessors\n ? {\n additionalLogRecordProcessors: tracing.additionalLogRecordProcessors,\n }\n : {}),\n ...(tracing.additionalMetricReaders\n ? { additionalMetricReaders: tracing.additionalMetricReaders }\n : {}),\n });\n\n // Phase 4: stitch the client trace onto whatever the SSR renderer was\n // already in. SSR injects a `traceparent` meta tag; we extract it into a\n // Context and seed the page-scope context manager with it. Spans created\n // outside any zone (DocumentLoad, Fetch listeners attached by OTel\n // instrumentations, app code in `useEffect`) fall back to that context\n // and become children of the server-side parent. No meta tag → page\n // scope stays at ROOT_CONTEXT; spans default to fresh roots.\n const extracted = readPropagationFromDocument();\n if (extracted) {\n handle.contextManager.setPageScope(extracted);\n }\n\n const dispose = registerBundledInstrumentations({\n tracerProvider: handle.tracerProvider,\n // Skip auto-instrumenting every fetch the SDK itself makes.\n // Without this we trace OTLP sink POSTs (infinite loop) and the\n // SDK's own config / session-sync requests — and worse, those\n // self-fetches' transient failures (DOMException timeouts on\n // flaky networks, ECONNRESET on the homepage's outbound\n // collector calls) get recorded as `exception` events and end up\n // in `events_pending`, burning enrichment cycles on\n // pipeline-internal noise that has nothing to do with the\n // customer's app. Measured 2026-05-12: 100% of `events_pending`\n // exceptions were children of `fetch GET …/v2/config` / `…/v2/sink`\n // spans.\n //\n // Exact-string ignore on the resolved target URLs (set at SDK\n // boot from `resolveTargets`) so customer proxies on\n // `/api/interfere/v2/*` are caught too. The OTLP sink lives at\n // `${collectorBaseUrl}/v2/sink` (`COLLECTOR_SINK_PATH` in the\n // exporter); config and session land on full URLs already.\n ignoreUrls: [\n `${collectorUrl}/v2/sink`,\n targets.config.url,\n targets.session.url,\n ],\n ...(tracing.propagateContextUrls\n ? { propagateContextUrls: tracing.propagateContextUrls }\n : {}),\n ...(tracing.resolveRoute ? { resolveRoute: tracing.resolveRoute } : {}),\n });\n\n if (tracing.webVitals !== false) {\n captureWebVitals({\n meter: handle.meterProvider.getMeter(\"@interfere/react/web-vitals\"),\n flush: () => handle.flush(),\n ...(tracing.resolveRoute ? { resolveRoute: tracing.resolveRoute } : {}),\n });\n }\n\n kernel.attachOtel(handle, dispose);\n}\n\nasync function fetchRemoteConfig(\n configTarget: IngestTarget,\n fetcher: typeof globalThis.fetch,\n runtime: PluginRuntime\n): Promise<void> {\n try {\n const headers = Object.fromEntries(configTarget.headers.entries());\n const res = await fetcher(configTarget.url, {\n method: \"GET\",\n headers,\n signal: AbortSignal.timeout(10_000),\n });\n if (!res.ok) {\n return;\n }\n const config = (await res.json()) as RemoteConfig;\n if (config?.plugins) {\n runtime.applyRemoteConfig(config.plugins);\n log.debug(\"applied remote config\");\n }\n } catch {\n log.warn(\"remote config fetch failed, using local defaults\");\n }\n}\n\nexport function isEnabledByEnvironment(): boolean {\n if (typeof process === \"undefined\" || !process.env) {\n return true;\n }\n const nodeEnv = process.env[\"NODE_ENV\"];\n if (nodeEnv === \"production\" || nodeEnv === undefined) {\n return true;\n }\n return !!(\n getGlobal<boolean>(\"__INTERFERE_FORCE_ENABLE__\") ||\n process.env[\"INTERFERE_FORCE_ENABLE\"]\n );\n}\n\n/**\n * Build-time-derived release slug. The build step\n * (`@interfere/next/withInterfere`, `@interfere/vite/plugin`) takes the\n * leading 16 hex chars of the commit SHA (`rel_<16hex>`) and stamps it into\n * the bundle as `__INTERFERE_RELEASE_SLUG__`. The collector derives the same\n * value from the create-release request, so the bundle's runtime slug is\n * guaranteed to match the row without a round-trip.\n *\n * Returns `null` when no slug was injected (dev builds, customers who\n * haven't wired up the plugin).\n */\nexport function readReleaseSlugFromGlobals(): ReleaseSlug | null {\n const value = getGlobal<unknown>(\"__INTERFERE_RELEASE_SLUG__\");\n\n return typeof value === \"string\" ? releaseSlugSchema.parse(value) : null;\n}\n"],"mappings":"+nBAqCA,MAAM,IAAM,aAAa,QAAQ,EAE3B,kBAAoB,MAE1B,SAAgB,cAAc,gBAAsC,CAClE,MAAO,CA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e,CAAE,aAAc,QAAQ,YAAa,EAAI,CAAC,CACvE,CAAC,EAEG,QAAQ,YAAc,IACxB,iBAAiB,CACf,MAAO,OAAO,cAAc,SAAS,6BAA6B,EAClE,UAAa,OAAO,MAAM,EAC1B,GAAI,QAAQ,aAAe,CAAE,aAAc,QAAQ,YAAa,EAAI,CAAC,CACvE,CAAC,EAGH,OAAO,WAAW,OAAQ,OAAO,CACnC,CAEA,eAAe,kBACb,aACA,QACA,QACe,CACf,GAAI,CACF,IAAM,QAAU,OAAO,YAAY,aAAa,QAAQ,QAAQ,CAAC,EAC3D,IAAM,MAAM,QAAQ,aAAa,IAAK,CAC1C,OAAQ,MACR,QACA,OAAQ,YAAY,QAAQ,GAAM,CACpC,CAAC,EACD,GAAI,CAAC,IAAI,GACP,OAEF,IAAM,OAAU,MAAM,IAAI,KAAK,EAC3B,QAAQ,UACV,QAAQ,kBAAkB,OAAO,OAAO,EACxC,IAAI,MAAM,uBAAuB,EAErC,MAAQ,CACN,IAAI,KAAK,kDAAkD,CAC7D,CACF,CAEA,SAAgB,wBAAkC,CAChD,GAAI,OAAO,QAAY,KAAe,CAAC,QAAQ,IAC7C,MAAO,GAET,IAAM,QAAU,QAAQ,IAAI,SAI5B,OAHI,UAAY,cAAgB,UAAY,IAAA,GACnC,GAEF,CAAC,EACN,UAAmB,4BAA4B,GAC/C,QAAQ,IAAI,uBAEhB,CAaA,SAAgB,4BAAiD,CAC/D,IAAM,MAAQ,UAAmB,4BAA4B,EAE7D,OAAO,OAAO,OAAU,SAAW,kBAAkB,MAAM,KAAK,EAAI,IACtE"}
@@ -0,0 +1,85 @@
1
+ import { ExportResult } from "@opentelemetry/core";
2
+ import { AggregationTemporality, PushMetricExporter, ResourceMetrics } from "@opentelemetry/sdk-metrics";
3
+ import { ReadableLogRecord } from "@opentelemetry/sdk-logs";
4
+ import { ReadableSpan, SpanExporter } from "@opentelemetry/sdk-trace-base";
5
+
6
+ //#region src/internal/otel/exporter.d.ts
7
+ interface ExporterCommon {
8
+ /**
9
+ * Kept for wrapper compatibility. Public-key identity is baked into
10
+ * `collectorUrl` as a `pk` query parameter before exporters are built.
11
+ */
12
+ authHeaders: Headers;
13
+ /** Base collector URL — the opaque sink path is appended. */
14
+ collectorUrl: string;
15
+ }
16
+ /** Exported for direct unit testing. */
17
+ declare function buildSinkUrl(collectorUrl: string): string;
18
+ /**
19
+ * Beacon-flavoured sink URL — encodes the producer-version (always)
20
+ * while preserving the `pk` query already baked into `collectorUrl`.
21
+ *
22
+ * Exported for direct unit testing.
23
+ */
24
+ declare function buildBeaconUrl(input: ExporterCommon): string;
25
+ /**
26
+ * Browser-side OTLP trace exporter.
27
+ *
28
+ * Dispatches every export via `navigator.sendBeacon` — which is the
29
+ * only browser transport that reliably commits a request the page is
30
+ * also tearing down (`visibilitychange→hidden`, hard navigation). The
31
+ * `keepalive: true` fetch path the OTLP HTTP exporter ships with
32
+ * works for small payloads but falls back to ordinary fetch (which
33
+ * the renderer aborts on unload) once the cumulative 64KiB / 9-
34
+ * concurrent budget is exhausted. Production data on 2026-05-11
35
+ * attributed ~15% browser-fetch span loss to that fallback; the
36
+ * beacon path closes that hole by design.
37
+ *
38
+ * Identity rides the URL because beacons can't carry custom headers.
39
+ *
40
+ * No retry on failure. The service worker backstop captures 5xx /
41
+ * network failures separately by intercepting the same beacon POST
42
+ * and queueing into IndexedDB for replay (`internal/sw.ts`).
43
+ */
44
+ declare class BeaconTraceExporter implements SpanExporter {
45
+ private readonly url;
46
+ constructor(url: string);
47
+ export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
48
+ shutdown(): Promise<void>;
49
+ forceFlush(): Promise<void>;
50
+ }
51
+ /**
52
+ * Browser-side OTLP log exporter — same beacon transport, log
53
+ * payload. See `BeaconTraceExporter` for the design rationale.
54
+ */
55
+ declare class BeaconLogExporter {
56
+ private readonly url;
57
+ constructor(url: string);
58
+ export(logs: ReadableLogRecord[], resultCallback: (result: ExportResult) => void): void;
59
+ shutdown(): Promise<void>;
60
+ forceFlush(): Promise<void>;
61
+ }
62
+ /**
63
+ * Browser-side OTLP metric exporter — beacon transport, metric
64
+ * payload, `DELTA` temporality.
65
+ *
66
+ * `DELTA` matches what the OTLP HTTP exporter the kit's previous
67
+ * `OTLPMetricExporter` was configured with (see the
68
+ * `temporalityPreference: AggregationTemporalityPreference.DELTA`
69
+ * arg `provider.ts` used to pass). Returning the same temporality
70
+ * for every instrument type keeps the wire shape downstream
71
+ * consumers receive unchanged across the migration.
72
+ */
73
+ declare class BeaconMetricExporter implements PushMetricExporter {
74
+ private readonly url;
75
+ constructor(url: string);
76
+ export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void;
77
+ selectAggregationTemporality(): AggregationTemporality;
78
+ forceFlush(): Promise<void>;
79
+ shutdown(): Promise<void>;
80
+ }
81
+ declare function createBeaconTraceExporter(input: ExporterCommon): BeaconTraceExporter;
82
+ declare function createBeaconMetricExporter(input: ExporterCommon): BeaconMetricExporter;
83
+ declare function createBeaconLogExporter(input: ExporterCommon): BeaconLogExporter;
84
+ //#endregion
85
+ export { buildBeaconUrl, buildSinkUrl, createBeaconLogExporter, createBeaconMetricExporter, createBeaconTraceExporter };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exporter.d.mts","names":[],"sources":["../../../src/internal/otel/exporter.ts"],"mappings":";;;;;;UA0EU,cAAA;EAAA;;;;EAKR,WAAA,EAAa,OAAO;EAAP;EAEb,YAAA;AAAA;AAAY;AAAA,iBAIE,YAAA,CAAa,YAAoB;;;;AAAA;AAUjD;;iBAAgB,cAAA,CAAe,KAAqB,EAAd,cAAc;;AAAA;AAMnD;;;;;;;;;;;;;;;;;cAoGK,mBAAA,YAA+B,YAAA;EAAA,iBAClB,GAAA;cAEL,GAAA;EAIZ,MAAA,CACE,KAAA,EAAO,YAAA,IACP,cAAA,GAAiB,MAAA,EAAQ,YAAA;EAc3B,QAAA,CAAA,GAAY,OAAA;EAIZ,UAAA,CAAA,GAAc,OAAA;AAAA;;AAAO;AAAA;;cASjB,iBAAA;EAAA,iBACa,GAAA;cAEL,GAAA;EAIZ,MAAA,CACE,IAAA,EAAM,iBAAA,IACN,cAAA,GAAiB,MAAA,EAAQ,YAAA;EAc3B,QAAA,CAAA,GAAY,OAAA;EAIZ,UAAA,CAAA,GAAc,OAAA;AAAA;;;;;;;;;;;;cAgBV,oBAAA,YAAgC,kBAAA;EAAA,iBACnB,GAAA;cAEL,GAAA;EAIZ,MAAA,CACE,OAAA,EAAS,eAAA,EACT,cAAA,GAAiB,MAAA,EAAQ,YAAA;EAU3B,4BAAA,CAAA,GAAgC,sBAAA;EAIhC,UAAA,CAAA,GAAc,OAAA;EAId,QAAA,CAAA,GAAY,OAAA;AAAA;AAAA,iBAKE,yBAAA,CACd,KAAA,EAAO,cAAA,GACN,mBAAmB;AAAA,iBAIN,0BAAA,CACd,KAAA,EAAO,cAAA,GACN,oBAAoB;AAAA,iBAIP,uBAAA,CACd,KAAA,EAAO,cAAA,GACN,iBAAiB"}
@@ -0,0 +1 @@
1
+ import{appendPathBeforeQuery,withQueryParam}from"../config.mjs";import{PRODUCER_VERSION}from"../version.mjs";import{diag}from"@opentelemetry/api";import{ExportResultCode}from"@opentelemetry/core";import{JsonLogsSerializer}from"@opentelemetry/otlp-transformer/build/esm/logs/json/logs.js";import{JsonMetricsSerializer}from"@opentelemetry/otlp-transformer/build/esm/metrics/json/metrics.js";import{JsonTraceSerializer}from"@opentelemetry/otlp-transformer/build/esm/trace/json/trace.js";import{AggregationTemporality}from"@opentelemetry/sdk-metrics";function buildSinkUrl(collectorUrl){return appendPathBeforeQuery(collectorUrl,`/v2/sink`)}function buildBeaconUrl(input){return withQueryParam(buildSinkUrl(input.collectorUrl),`_pv`,PRODUCER_VERSION)}function canSendBeacon(){return typeof navigator<`u`&&typeof navigator.sendBeacon==`function`}function reportBeacon(url,payload,signal,resultCallback){if(!payload||payload.byteLength===0){diag.debug(`[interfere/beacon] ${signal} serializer returned no bytes`),resultCallback({code:ExportResultCode.SUCCESS});return}if(!canSendBeacon()){diag.debug(`[interfere/beacon] navigator.sendBeacon unavailable; dropping ${signal} batch (${payload.byteLength}B)`),resultCallback({code:ExportResultCode.SUCCESS});return}let blob=new Blob([payload],{type:`application/json`});navigator.sendBeacon(url,blob)||diag.debug(`[interfere/beacon] navigator.sendBeacon refused ${signal} payload (oversized or queue full); dropping ${payload.byteLength}B`),resultCallback({code:ExportResultCode.SUCCESS})}var BeaconTraceExporter=class{url;constructor(url){this.url=url}export(spans,resultCallback){if(spans.length===0){resultCallback({code:ExportResultCode.SUCCESS});return}reportBeacon(this.url,JsonTraceSerializer.serializeRequest(spans),`trace`,resultCallback)}shutdown(){return Promise.resolve()}forceFlush(){return Promise.resolve()}},BeaconLogExporter=class{url;constructor(url){this.url=url}export(logs,resultCallback){if(logs.length===0){resultCallback({code:ExportResultCode.SUCCESS});return}reportBeacon(this.url,JsonLogsSerializer.serializeRequest(logs),`log`,resultCallback)}shutdown(){return Promise.resolve()}forceFlush(){return Promise.resolve()}},BeaconMetricExporter=class{url;constructor(url){this.url=url}export(metrics,resultCallback){reportBeacon(this.url,JsonMetricsSerializer.serializeRequest(metrics),`metric`,resultCallback)}selectAggregationTemporality(){return AggregationTemporality.DELTA}forceFlush(){return Promise.resolve()}shutdown(){return Promise.resolve()}};function createBeaconTraceExporter(input){return new BeaconTraceExporter(buildBeaconUrl(input))}function createBeaconMetricExporter(input){return new BeaconMetricExporter(buildBeaconUrl(input))}function createBeaconLogExporter(input){return new BeaconLogExporter(buildBeaconUrl(input))}export{buildBeaconUrl,buildSinkUrl,createBeaconLogExporter,createBeaconMetricExporter,createBeaconTraceExporter};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exporter.mjs","names":[],"sources":["../../../src/internal/otel/exporter.ts"],"sourcesContent":["import { diag } from \"@opentelemetry/api\";\nimport type { ExportResult } from \"@opentelemetry/core\";\nimport { ExportResultCode } from \"@opentelemetry/core\";\n// Deep imports against the package build output — the barrel\n// (`@opentelemetry/otlp-transformer`) re-exports the JSON *and*\n// Protobuf serializers, and the protobuf side reaches `protobufjs`\n// which transitively hits `worker_threads.MessageChannel` (via\n// `import-in-the-middle`). Vite externalizes `worker_threads` for\n// the browser test environment with a runtime-throwing stub; the\n// kernel's `await import(\"./otel/index.js\")` chunk inherits any file\n// reachable from the package root through Vite's dep optimizer, so\n// importing from the barrel breaks `provider.test.tsx` with\n// \"Failed to fetch dynamically imported module\" on the chunk URL.\n//\n// The `*/json/trace.js` (etc.) modules import only `@opentelemetry/\n// api` and the package's own JSON-only utility files — no protobuf\n// in the transitive graph. We also pin the file extension (`.js`)\n// instead of letting the directory's `index.js` resolution kick in\n// because resolvers (bun on Linux vs macOS, vite vs raw esbuild)\n// disagree about whether a missing extension on a directory-shaped\n// specifier should resolve to `<dir>/index.js` or fail. The explicit\n// `.js` is the only spelling all of them agree on.\n//\n// `@opentelemetry/otlp-transformer` doesn't ship an `\"exports\"` field\n// in its `package.json`, so these deep paths are the supported escape\n// hatch (the OTel HTTP exporters take the same approach internally —\n// see `@opentelemetry/exporter-trace-otlp-http/build/esm/platform/\n// browser/OTLPTraceExporter.js`). Pinned via the workspace catalog so\n// a minor version bump can't quietly relocate the build directory.\nimport { JsonLogsSerializer } from \"@opentelemetry/otlp-transformer/build/esm/logs/json/logs.js\";\nimport { JsonMetricsSerializer } from \"@opentelemetry/otlp-transformer/build/esm/metrics/json/metrics.js\";\nimport { JsonTraceSerializer } from \"@opentelemetry/otlp-transformer/build/esm/trace/json/trace.js\";\nimport type { ReadableLogRecord } from \"@opentelemetry/sdk-logs\";\nimport type {\n PushMetricExporter,\n ResourceMetrics,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AggregationTemporality } from \"@opentelemetry/sdk-metrics\";\nimport type { ReadableSpan, SpanExporter } from \"@opentelemetry/sdk-trace-base\";\n\nimport { appendPathBeforeQuery, withQueryParam } from \"../config.js\";\nimport { PRODUCER_VERSION } from \"../version.js\";\n\n/**\n * Opaque collector ingest path. Single endpoint for every OTLP signal —\n * server-side dispatches by which `resource*` block the request carries.\n *\n * Semantically nondescript so common adblock filter lists (EasyPrivacy,\n * uBlock) don't fingerprint it the way they do `traces` / `metrics` /\n * `logs` / `telemetry`. Customer-domain proxy mode is still the\n * recommended path for browser SDKs; this is the second line of defence\n * for direct-ingestion clients.\n */\nconst COLLECTOR_SINK_PATH = \"/v2/sink\";\n\n/**\n * Identity gate values the collector accepts via URL query when their\n * matching headers can't be set.\n *\n * `navigator.sendBeacon` (the only browser transport that survives\n * `visibilitychange→hidden`) only attaches `Content-Type` via the\n * `Blob` — no other request headers. We rely on that exclusively for\n * the browser SDK's primary path, so the identity gates the collector\n * enforces have to ride the URL instead.\n *\n * Public-key query exposure note: public keys ship in browser bundles\n * and are visible in DevTools by design, so URL exposure is no worse\n * than the existing header path. API keys deliberately have **no**\n * query fallback — see `surfaceAkAuth` for the matching server-side\n * rationale.\n */\nconst PRODUCER_VERSION_QUERY = \"_pv\";\n\nconst JSON_CONTENT_TYPE = \"application/json\";\ninterface ExporterCommon {\n /**\n * Kept for wrapper compatibility. Public-key identity is baked into\n * `collectorUrl` as a `pk` query parameter before exporters are built.\n */\n authHeaders: Headers;\n /** Base collector URL — the opaque sink path is appended. */\n collectorUrl: string;\n}\n\n/** Exported for direct unit testing. */\nexport function buildSinkUrl(collectorUrl: string): string {\n return appendPathBeforeQuery(collectorUrl, COLLECTOR_SINK_PATH);\n}\n\n/**\n * Beacon-flavoured sink URL — encodes the producer-version (always)\n * while preserving the `pk` query already baked into `collectorUrl`.\n *\n * Exported for direct unit testing.\n */\nexport function buildBeaconUrl(input: ExporterCommon): string {\n return withQueryParam(\n buildSinkUrl(input.collectorUrl),\n PRODUCER_VERSION_QUERY,\n PRODUCER_VERSION\n );\n}\n\n/**\n * Returns true iff the runtime can dispatch a `navigator.sendBeacon`\n * call. Browser-only; server contexts (SSR, prerender, Vitest's `node`\n * environment) trip the typeof guards.\n */\nfunction canSendBeacon(): boolean {\n return (\n typeof navigator !== \"undefined\" &&\n typeof navigator.sendBeacon === \"function\"\n );\n}\n\n/**\n * Dispatches an OTLP payload via `navigator.sendBeacon` and always\n * reports `SUCCESS` to the BSP. `sendBeacon` is fire-and-forget by\n * spec — a `true` return only means \"the user agent accepted the\n * payload into its delivery queue\", not \"the server received it\".\n *\n * Why never report `FAILED`:\n * - `BatchSpanProcessor._flushOneBatch` rejects its promise on\n * `code !== SUCCESS`, and that rejection propagates up through\n * `forceFlush()` / `shutdown()`. In production, that surfaces\n * during Vercel function teardown (and other awaited unload\n * paths) as an unhandled rejection. In tests, it surfaces as\n * `provider.test.tsx > passes through useSession` — vitest's\n * `afterEach(close)` awaits `kernel.dispose() → BSP.shutdown\n * → _flushAll`, the rejection bubbles, and the test fails.\n * - `sendBeacon`'s `false` return signals a *local* drop (per-call\n * ~64KiB ceiling, per-page queue full, disallowed scheme). No\n * network request was attempted, so the service-worker backstop\n * in `internal/sw.ts` can't intercept it either. Retrying inside\n * the exporter would just hit the same browser limit again.\n *\n * The data is gone, but the export *completed* in the only sense\n * that matters to the BSP. A `diag.debug` keeps visibility for any\n * OTel diag listener wired into the kernel.\n */\nfunction reportBeacon(\n url: string,\n payload: Uint8Array | undefined,\n signal: \"trace\" | \"log\" | \"metric\",\n resultCallback: (result: ExportResult) => void\n): void {\n if (!payload || payload.byteLength === 0) {\n diag.debug(`[interfere/beacon] ${signal} serializer returned no bytes`);\n resultCallback({ code: ExportResultCode.SUCCESS });\n return;\n }\n if (!canSendBeacon()) {\n diag.debug(\n `[interfere/beacon] navigator.sendBeacon unavailable; dropping ${signal} batch (${payload.byteLength}B)`\n );\n resultCallback({ code: ExportResultCode.SUCCESS });\n return;\n }\n // `Blob` is the only sendBeacon argument shape that lets us pin\n // `Content-Type: application/json` on the request — using the raw\n // `Uint8Array` would default to `application/octet-stream`, which\n // the collector's content-type allowlist rejects with 415.\n //\n // The cast is necessary because `JsonTraceSerializer.serializeRequest`\n // returns `Uint8Array<ArrayBufferLike>`, but `Blob`'s constructor\n // narrows `BlobPart` to `Uint8Array<ArrayBuffer>` (excluding\n // `SharedArrayBuffer`). The serializer never returns shared-buffer-\n // backed bytes (it allocates a fresh `Uint8Array(byteLength)`\n // internally) so the runtime check the type system is asking for is\n // already true; a structural cast preserves that without forcing an\n // unnecessary buffer copy.\n const blob = new Blob([payload as Uint8Array<ArrayBuffer>], {\n type: JSON_CONTENT_TYPE,\n });\n if (!navigator.sendBeacon(url, blob)) {\n diag.debug(\n `[interfere/beacon] navigator.sendBeacon refused ${signal} payload (oversized or queue full); dropping ${payload.byteLength}B`\n );\n }\n resultCallback({ code: ExportResultCode.SUCCESS });\n}\n\n/**\n * Browser-side OTLP trace exporter.\n *\n * Dispatches every export via `navigator.sendBeacon` — which is the\n * only browser transport that reliably commits a request the page is\n * also tearing down (`visibilitychange→hidden`, hard navigation). The\n * `keepalive: true` fetch path the OTLP HTTP exporter ships with\n * works for small payloads but falls back to ordinary fetch (which\n * the renderer aborts on unload) once the cumulative 64KiB / 9-\n * concurrent budget is exhausted. Production data on 2026-05-11\n * attributed ~15% browser-fetch span loss to that fallback; the\n * beacon path closes that hole by design.\n *\n * Identity rides the URL because beacons can't carry custom headers.\n *\n * No retry on failure. The service worker backstop captures 5xx /\n * network failures separately by intercepting the same beacon POST\n * and queueing into IndexedDB for replay (`internal/sw.ts`).\n */\nclass BeaconTraceExporter implements SpanExporter {\n private readonly url: string;\n\n constructor(url: string) {\n this.url = url;\n }\n\n export(\n spans: ReadableSpan[],\n resultCallback: (result: ExportResult) => void\n ): void {\n if (spans.length === 0) {\n resultCallback({ code: ExportResultCode.SUCCESS });\n return;\n }\n reportBeacon(\n this.url,\n JsonTraceSerializer.serializeRequest(spans),\n \"trace\",\n resultCallback\n );\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n}\n\n/**\n * Browser-side OTLP log exporter — same beacon transport, log\n * payload. See `BeaconTraceExporter` for the design rationale.\n */\nclass BeaconLogExporter {\n private readonly url: string;\n\n constructor(url: string) {\n this.url = url;\n }\n\n export(\n logs: ReadableLogRecord[],\n resultCallback: (result: ExportResult) => void\n ): void {\n if (logs.length === 0) {\n resultCallback({ code: ExportResultCode.SUCCESS });\n return;\n }\n reportBeacon(\n this.url,\n JsonLogsSerializer.serializeRequest(logs),\n \"log\",\n resultCallback\n );\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n}\n\n/**\n * Browser-side OTLP metric exporter — beacon transport, metric\n * payload, `DELTA` temporality.\n *\n * `DELTA` matches what the OTLP HTTP exporter the kit's previous\n * `OTLPMetricExporter` was configured with (see the\n * `temporalityPreference: AggregationTemporalityPreference.DELTA`\n * arg `provider.ts` used to pass). Returning the same temporality\n * for every instrument type keeps the wire shape downstream\n * consumers receive unchanged across the migration.\n */\nclass BeaconMetricExporter implements PushMetricExporter {\n private readonly url: string;\n\n constructor(url: string) {\n this.url = url;\n }\n\n export(\n metrics: ResourceMetrics,\n resultCallback: (result: ExportResult) => void\n ): void {\n reportBeacon(\n this.url,\n JsonMetricsSerializer.serializeRequest(metrics),\n \"metric\",\n resultCallback\n );\n }\n\n selectAggregationTemporality(): AggregationTemporality {\n return AggregationTemporality.DELTA;\n }\n\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n}\n\nexport function createBeaconTraceExporter(\n input: ExporterCommon\n): BeaconTraceExporter {\n return new BeaconTraceExporter(buildBeaconUrl(input));\n}\n\nexport function createBeaconMetricExporter(\n input: ExporterCommon\n): BeaconMetricExporter {\n return new BeaconMetricExporter(buildBeaconUrl(input));\n}\n\nexport function createBeaconLogExporter(\n input: ExporterCommon\n): BeaconLogExporter {\n return new BeaconLogExporter(buildBeaconUrl(input));\n}\n"],"mappings":"miBAqFA,SAAgB,aAAa,aAA8B,CACzD,OAAO,sBAAsB,aAAc,UAAmB,CAChE,CAQA,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BAAiB,IAAI,EACxC,MACA,cACF,CACF,CAEA,UAA0B,CACxB,OAAO,QAAQ,QAAQ,CACzB,CAEA,YAA4B,CAC1B,OAAO,QAAQ,QAAQ,CACzB,CACF,EAaM,qBAAN,KAAyD,CACvD,IAEA,YAAY,IAAa,CACvB,KAAK,IAAM,GACb,CAEA,OACE,QACA,eACM,CACN,aACE,KAAK,IACL,sBAAsB,iBAAiB,OAAO,EAC9C,SACA,cACF,CACF,CAEA,8BAAuD,CACrD,OAAO,uBAAuB,KAChC,CAEA,YAA4B,CAC1B,OAAO,QAAQ,QAAQ,CACzB,CAEA,UAA0B,CACxB,OAAO,QAAQ,QAAQ,CACzB,CACF,EAEA,SAAgB,0BACd,MACqB,CACrB,OAAO,IAAI,oBAAoB,eAAe,KAAK,CAAC,CACtD,CAEA,SAAgB,2BACd,MACsB,CACtB,OAAO,IAAI,qBAAqB,eAAe,KAAK,CAAC,CACvD,CAEA,SAAgB,wBACd,MACmB,CACnB,OAAO,IAAI,kBAAkB,eAAe,KAAK,CAAC,CACpD"}
@@ -0,0 +1,6 @@
1
+ import { createBeaconMetricExporter, createBeaconTraceExporter } from "./exporter.mjs";
2
+ import { InstrumentationsInput, registerBundledInstrumentations } from "./instrumentations.mjs";
3
+ import { readPropagationFromDocument } from "./propagation.mjs";
4
+ import { OtelProviderHandle, OtelProviderInput, buildOtelProvider } from "./provider.mjs";
5
+ import { captureWebVitals } from "./web-vitals.mjs";
6
+ export { type InstrumentationsInput, type OtelProviderHandle, type OtelProviderInput, buildOtelProvider, captureWebVitals, createBeaconMetricExporter, createBeaconTraceExporter, readPropagationFromDocument, registerBundledInstrumentations };
@@ -0,0 +1 @@
1
+ import{createBeaconMetricExporter,createBeaconTraceExporter}from"./exporter.mjs";import{registerBundledInstrumentations}from"./instrumentations.mjs";import{readPropagationFromDocument}from"./propagation.mjs";import{buildOtelProvider}from"./provider.mjs";import{captureWebVitals}from"./web-vitals.mjs";export{buildOtelProvider,captureWebVitals,createBeaconMetricExporter,createBeaconTraceExporter,readPropagationFromDocument,registerBundledInstrumentations};
@@ -0,0 +1,42 @@
1
+ import { WebTracerProvider } from "@opentelemetry/sdk-trace-web";
2
+
3
+ //#region src/internal/otel/instrumentations.d.ts
4
+ interface InstrumentationsInput {
5
+ /**
6
+ * URLs the SDK exempts from `fetch` and `XHR` instrumentation —
7
+ * typically our own ingest/OTLP endpoints, so the SDK doesn't trace
8
+ * its own export requests in an infinite loop. Combined with the
9
+ * `THIRD_PARTY_IGNORE` defaults and the customer's `ignoreUrls`.
10
+ */
11
+ ignoreUrls: (string | RegExp)[];
12
+ /**
13
+ * Customer-supplied URL patterns the fetch + XHR instrumentations
14
+ * inject `traceparent` + `baggage` headers on. Same-origin requests
15
+ * always propagate.
16
+ */
17
+ propagateContextUrls?: (string | RegExp)[];
18
+ /**
19
+ * Pathname → low-cardinality route template (e.g. `/blog/[slug]`).
20
+ * Drives span renaming + `url.path` / `http.route` attrs across
21
+ * fetch, document-load, user-interaction, and long-task.
22
+ */
23
+ resolveRoute?: (pathname: string) => string | undefined;
24
+ /**
25
+ * The kernel's private provider — instrumentations register against
26
+ * it, not the global one, so customer OTel setups stay untouched.
27
+ */
28
+ tracerProvider: WebTracerProvider;
29
+ }
30
+ /**
31
+ * Registers every browser auto-instrumentation against the kernel's
32
+ * private provider. Every instrumentation is enriched with the same
33
+ * route-template-aware URL attributes so dashboards can slice fetch /
34
+ * interaction / long-task / resource-load by `http.route` without
35
+ * cardinality blow-up from raw pathnames.
36
+ *
37
+ * Returns a disposer that unregisters everything; called by
38
+ * `kernel.dispose()`.
39
+ */
40
+ declare function registerBundledInstrumentations(input: InstrumentationsInput): () => void;
41
+ //#endregion
42
+ export { InstrumentationsInput, registerBundledInstrumentations };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumentations.d.mts","names":[],"sources":["../../../src/internal/otel/instrumentations.ts"],"mappings":";;;UAgHiB,qBAAA;;AAAjB;;;;;EAOE,UAAA,YAAsB,MAAA;EAiBW;;;;;EAXjC,oBAAA,aAAiC,MAAA;EAMjC;;;;;EAAA,YAAA,IAAgB,QAAA;EAkBF;;;;EAbd,cAAA,EAAgB,iBAAA;AAAA;;;;;;;;;;;iBAaF,+BAAA,CACd,KAA4B,EAArB,qBAAqB"}
@@ -0,0 +1 @@
1
+ import{describeActionable,isActionable}from"../dom/actionable.mjs";import{registerInstrumentations}from"@opentelemetry/instrumentation";import{BrowserNavigationInstrumentation,defaultSanitizeUrl}from"@opentelemetry/instrumentation-browser-navigation";import{DocumentLoadInstrumentation}from"@opentelemetry/instrumentation-document-load";import{FetchInstrumentation}from"@opentelemetry/instrumentation-fetch";import{LongTaskInstrumentation}from"@opentelemetry/instrumentation-long-task";import{UserInteractionInstrumentation}from"@opentelemetry/instrumentation-user-interaction";import{XMLHttpRequestInstrumentation}from"@opentelemetry/instrumentation-xml-http-request";const ATTR_HTTP_ROUTE=`http.route`,ATTR_URL_FULL=`url.full`,ATTR_URL_PATH=`url.path`,SEMCONV_STABILITY_OPT_IN=`http,database,messaging,gen_ai_latest_experimental`,THIRD_PARTY_IGNORE=[/(?:^|\/\/)clerk\./,/\.clerk\./,/\.sentry\./,/\.intercom\./,/\.posthog\./,/\.googletagmanager\.com/,/\.google-analytics\.com/,/\.googleapis\.com/,/\.doubleclick\.net/,/\.facebook\.com/,/\.fbcdn\.net/,/\.analytics\.google\.com/,/px\.ads\.linkedin\.com/,/[?&]_rsc=/],NEVER_MATCH=/^$/,ESCAPE_RE=/[.*+?^${}()|[\]\\]/g;function sameOriginPattern(){if(typeof window>`u`)return NEVER_MATCH;let{protocol,host}=window.location;return RegExp(`^${protocol}//${host.replace(ESCAPE_RE,`\\$&`)}`)}function stampInteractionAttrs(eventType,element,span){let desc=describeActionable(element);span.setAttribute(`ui.event_type`,eventType),span.setAttribute(`ui.target.tag`,desc.tag),desc.id&&span.setAttribute(`ui.target.id`,desc.id),desc.name&&span.setAttribute(`ui.target.name`,desc.name),desc.role&&span.setAttribute(`ui.target.role`,desc.role),desc.ariaLabel&&span.setAttribute(`ui.target.aria_label`,desc.ariaLabel),desc.text&&span.setAttribute(`ui.target.text`,desc.text)}function stampUrlAttrs(span,resolveRoute){if(typeof window>`u`)return;let pathname=window.location.pathname,route=resolveRoute?.(pathname);span.setAttribute(ATTR_URL_PATH,route??pathname),span.setAttribute(ATTR_URL_FULL,window.location.href),route&&span.setAttribute(ATTR_HTTP_ROUTE,route)}function registerBundledInstrumentations(input){let{tracerProvider,ignoreUrls,propagateContextUrls=[]}=input,resolveRoute=input.resolveRoute,origin=sameOriginPattern(),fetchIgnore=[...ignoreUrls,...THIRD_PARTY_IGNORE];return registerInstrumentations({tracerProvider,instrumentations:[new FetchInstrumentation({propagateTraceHeaderCorsUrls:[origin,...propagateContextUrls],ignoreUrls:fetchIgnore,semconvStabilityOptIn:SEMCONV_STABILITY_OPT_IN,measureRequestSize:!0,applyCustomAttributesOnSpan:(span,request)=>{let url=request instanceof Request?request.url:request?.toString();if(typeof url==`string`)try{let parsed=new URL(url);if(span.setAttribute(ATTR_URL_PATH,parsed.pathname),origin.test(url)||propagateContextUrls.some(re=>re instanceof RegExp?re.test(url):url.includes(re))){let method=(request instanceof Request?request.method:void 0)??`GET`,route=resolveRoute?.(parsed.pathname);route&&span.setAttribute(ATTR_HTTP_ROUTE,route),span.updateName(`${method} ${route??parsed.pathname}`)}}catch{return}}}),new XMLHttpRequestInstrumentation({propagateTraceHeaderCorsUrls:[origin,...propagateContextUrls],ignoreUrls:fetchIgnore,semconvStabilityOptIn:SEMCONV_STABILITY_OPT_IN}),new DocumentLoadInstrumentation({semconvStabilityOptIn:SEMCONV_STABILITY_OPT_IN,applyCustomAttributesOnSpan:{resourceFetch:(span,entry)=>{let name=entry?.name;if(typeof name==`string`)try{let url=new URL(name),isCrossOrigin=typeof window<`u`&&url.origin!==window.location.origin;span.updateName(isCrossOrigin?`resource: ${url.host}${url.pathname}`:`resource: ${url.pathname}`),span.setAttribute(ATTR_URL_FULL,name),span.setAttribute(ATTR_URL_PATH,url.pathname),span.setAttribute(`server.address`,url.host)}catch{}}}}),new BrowserNavigationInstrumentation({sanitizeUrl:defaultSanitizeUrl}),new UserInteractionInstrumentation({eventNames:[`click`,`submit`],shouldPreventSpanCreation:(eventType,element,span)=>eventType===`click`&&!isActionable(element)?!0:(stampInteractionAttrs(eventType,element,span),stampUrlAttrs(span,resolveRoute),!1)}),new LongTaskInstrumentation({observerCallback:(span,info)=>{stampUrlAttrs(span,resolveRoute);let containerType=info.longtaskEntry.attribution[0]?.containerType;containerType&&span.setAttribute(`longtask.container_type`,containerType)}})]})}export{registerBundledInstrumentations};