@syntrologie/runtime-sdk 2.18.0 → 2.19.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.
@@ -9,6 +9,10 @@ export declare class HealthReporter {
9
9
  private timer;
10
10
  private pagehideHandler;
11
11
  private runtime;
12
+ /** Cleanup function for adapters that registered side effects (e.g. the
13
+ * web-vitals long-task observer). Called from `stop()` so SPA re-init
14
+ * via `initHealthReporter` doesn't accumulate observers. */
15
+ private adapterCleanup;
12
16
  constructor(config: HealthReporterConfig);
13
17
  /**
14
18
  * Bind runtime-derived attribute resolvers. Called after the canvas/telemetry
@@ -16,6 +20,13 @@ export declare class HealthReporter {
16
20
  * null-safe access at flush time.
17
21
  */
18
22
  bindRuntime(binding: ReporterRuntimeBinding): void;
23
+ /**
24
+ * Register a cleanup function to run on `stop()`. Used by adapters
25
+ * (e.g. webVitalsAdapter) that need to release per-bind resources
26
+ * like PerformanceObservers. Replaces any prior cleanup — only one
27
+ * adapter cleanup is tracked.
28
+ */
29
+ attachAdapterCleanup(cleanup: () => void): void;
19
30
  increment(signal: CounterSignal, by?: number): void;
20
31
  /**
21
32
  * @internal — exposed for test inspection only. Mid-window state is intentionally
@@ -1,3 +1,5 @@
1
1
  export { getHealthReporter, HealthReporter, initHealthReporter } from './healthReporter';
2
2
  export { createOtlpEmitter } from './otlpEmitter';
3
+ export { getSdkScriptUrl, getSdkScriptUrlPrefix } from './sdkScriptUrl';
3
4
  export type { CounterSignal, FlushPayload, HealthReporterConfig, HistogramSignal, ReporterResource, } from './types';
5
+ export { bindWebVitals } from './webVitalsAdapter';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The full URL of the SDK script, captured at module load. Returns
3
+ * `undefined` when the SDK is bundled into the host app (no separate
4
+ * `<script>` tag) or when running outside a browser.
5
+ */
6
+ export declare function getSdkScriptUrl(): string | undefined;
7
+ /**
8
+ * Directory prefix of the SDK script URL — useful for matching attribution
9
+ * entries from `PerformanceLongTaskTiming` against the SDK bundle and any
10
+ * sibling chunks (source maps, lazy-loaded adaptives) served from the same
11
+ * directory.
12
+ *
13
+ * Example: `https://cdn.syntrologie.com/runtime-sdk/v2/canary/smart-canvas.min.js`
14
+ * → `https://cdn.syntrologie.com/runtime-sdk/v2/canary/`
15
+ */
16
+ export declare function getSdkScriptUrlPrefix(): string | undefined;
@@ -2,8 +2,23 @@
2
2
  * Names of signals the SDK emits. Add new entries as the taxonomy grows.
3
3
  * Counter signals are unbounded integers; histogram signals are millisecond floats.
4
4
  */
5
- export type CounterSignal = 'bootstrap_ok' | 'bootstrap_errors' | 'flag_fetch_count' | 'flag_fetch_errors';
6
- export type HistogramSignal = 'flag_fetch_latency_ms';
5
+ export type CounterSignal = 'bootstrap_ok' | 'bootstrap_errors' | 'flag_fetch_count' | 'flag_fetch_errors' | 'longtasks_self_count'
6
+ /** Cumulative blocking time (ms) from long tasks attributed to the SDK
7
+ * script. Counter rather than histogram so HogQL sum() across windows
8
+ * gives the total — which is what alerts/dashboards actually want. */
9
+ | 'longtasks_self_blocking_ms';
10
+ /**
11
+ * Histogram signals. Web vitals are field-RUM measurements from the customer's
12
+ * browser, not synthetic Lighthouse audits — same metrics Lighthouse reports
13
+ * as "Core Web Vitals from CrUX," but measured live.
14
+ *
15
+ * - lcp_ms — Largest Contentful Paint
16
+ * - inp_ms — Interaction to Next Paint
17
+ * - cls_score — Cumulative Layout Shift (unitless 0..1+)
18
+ * - fcp_ms — First Contentful Paint
19
+ * - ttfb_ms — Time to First Byte
20
+ */
21
+ export type HistogramSignal = 'flag_fetch_latency_ms' | 'lcp_ms' | 'inp_ms' | 'cls_score' | 'fcp_ms' | 'ttfb_ms';
7
22
  /**
8
23
  * Resource attributes for the OTLP payload. The static fields are set at
9
24
  * reporter init; the dynamic fields are resolved at flush time via runtime
@@ -0,0 +1,22 @@
1
+ import type { HealthReporter } from './healthReporter';
2
+ /**
3
+ * Bind the web-vitals callbacks to the given HealthReporter. Each metric
4
+ * fires once per session per metric (with possible BFCache reactivations).
5
+ *
6
+ * Idempotent across `Syntro.init()` re-calls: web-vitals subscriptions are
7
+ * registered once per page; later binds re-route to the most recent
8
+ * reporter via a window-scoped pointer. Long-task observers are per-bind
9
+ * and disposed via the returned cleanup function.
10
+ *
11
+ * Long-task tracking is opt-in via `attributedScriptUrlPrefix`: when the
12
+ * browser exposes long-task attribution and the offending script's URL
13
+ * starts with this prefix, the long task is counted toward the SDK's own
14
+ * blocking time. Pass the SDK script URL prefix (typically the CDN
15
+ * directory the bundle was loaded from).
16
+ *
17
+ * Safe to call in non-browser environments — returns a no-op cleanup
18
+ * function when `window` is unavailable.
19
+ */
20
+ export declare function bindWebVitals(reporter: HealthReporter, options?: {
21
+ attributedScriptUrlPrefix?: string;
22
+ }): () => void;