@launchdarkly/o11y 1.4.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -623,6 +623,7 @@ declare class Highlight_2 {
623
623
  _isCrossOriginIframe: boolean;
624
624
  _eventBytesSinceSnapshot: number;
625
625
  _lastSnapshotTime: number;
626
+ _snapshotPayloadIds: Set<number>;
626
627
  _lastVisibilityChangeTime: number;
627
628
  pushPayloadTimerId: ReturnType<typeof setTimeout> | undefined;
628
629
  hasSessionUnloaded: boolean;
@@ -1160,6 +1161,19 @@ declare type Hook = Omit<Hook_2, 'afterEvaluation'> & {
1160
1161
  */
1161
1162
  declare type HrTime = [number, number];
1162
1163
 
1164
+ /**
1165
+ * Describes the request behind an auto-instrumented browser `fetch` or
1166
+ * `XMLHttpRequest` span.
1167
+ */
1168
+ export declare type HttpSpanRequest = {
1169
+ /** Which instrumentation created the span. */
1170
+ type: 'fetch' | 'xhr';
1171
+ /** Upper-cased HTTP method, e.g. `GET`. */
1172
+ method: string;
1173
+ /** The concrete request URL, e.g. `https://app.example.com/api/users/42`. */
1174
+ url: string;
1175
+ };
1176
+
1163
1177
  declare type IdentifyMessage = {
1164
1178
  type: MessageType.Identify;
1165
1179
  userIdentifier: string;
@@ -1240,6 +1254,14 @@ declare interface LDClientMin {
1240
1254
  export declare let LDObserve: _LDObserve;
1241
1255
 
1242
1256
  declare class _LDObserve extends BufferedClass<Observe_2> implements Observe_2 {
1257
+ /**
1258
+ * Applies buffered `setAttributes`/`removeAttributes` calls to `sdk`
1259
+ * without attaching it. Call it before `sdk.start()` so attributes set
1260
+ * before init reach spans recorded synchronously during start (e.g. the
1261
+ * document load span). `load` also does this, so calling it is optional.
1262
+ */
1263
+ applyBufferedAttributes(sdk: Observe_2): void;
1264
+ load(sdk: Observe_2, options?: BufferedLoadOptions): void;
1243
1265
  protected _startSdk(): Promise<void>;
1244
1266
  start(): Promise<void>;
1245
1267
  stop(): Promise<void>;
@@ -1257,6 +1279,8 @@ declare class _LDObserve extends BufferedClass<Observe_2> implements Observe_2 {
1257
1279
  [key: string]: string;
1258
1280
  }, source?: string, type?: ErrorMessageType): any;
1259
1281
  setLDContextKeyAttributes(contextKeys: Attributes): any;
1282
+ setAttributes(attributes: Record<string, AttributeValue | null | undefined>): any;
1283
+ removeAttributes(keys: string[]): any;
1260
1284
  getLDContextKeyAttributes(): Attributes | undefined;
1261
1285
  }
1262
1286
 
@@ -1756,6 +1780,40 @@ declare interface Observe_2 {
1756
1780
  * Useful when you don't want to emit a console log to the browser dev tools but still want to report a custom log.
1757
1781
  */
1758
1782
  recordLog: (message: any, level: ConsoleMethods, metadata?: Attributes) => void;
1783
+ /**
1784
+ * Adds attributes to all telemetry recorded from now on: every span
1785
+ * (including automatically instrumented ones such as document load,
1786
+ * fetch/XHR, clicks and page views), log, error and metric.
1787
+ *
1788
+ * Calling it again merges with the attributes already set; a `null` or
1789
+ * `undefined` value removes that key. Attributes passed to an individual
1790
+ * call (for example `recordLog` metadata or metric attributes) take
1791
+ * precedence over these. Keys in namespaces the SDK sets itself
1792
+ * (`highlight.*`, `launchdarkly.*`, `session.*`, `context.contextKeys.*`)
1793
+ * are ignored.
1794
+ *
1795
+ * Attributes are held in memory for the current page load only: they are
1796
+ * never persisted, and a full page load starts without them.
1797
+ *
1798
+ * Each attribute is also added to every metric, so a value with many
1799
+ * distinct values (such as a user ID) creates as many metric series.
1800
+ *
1801
+ * @example
1802
+ * ```typescript
1803
+ * LDObserve.setAttributes({ utm_campaign: 'spring_promo', utm_source: 'email' })
1804
+ * ```
1805
+ */
1806
+ setAttributes(attributes: Record<string, AttributeValue | null | undefined>): void;
1807
+ /**
1808
+ * Removes attributes previously added with `setAttributes`. Telemetry
1809
+ * recorded afterwards no longer carries them.
1810
+ *
1811
+ * @example
1812
+ * ```typescript
1813
+ * LDObserve.removeAttributes(['utm_campaign'])
1814
+ * ```
1815
+ */
1816
+ removeAttributes(keys: string[]): void;
1759
1817
  register(client: LDClientMin, environmentMetadata: LDPluginEnvironmentMetadata): void;
1760
1818
  getHooks?(metadata: LDPluginEnvironmentMetadata): Hook[];
1761
1819
  setLDContextKeyAttributes(contextKeys: Attributes): void;
@@ -1867,6 +1925,55 @@ export declare type ObserveOptions = CommonOptions & {
1867
1925
  * @default 2000
1868
1926
  */
1869
1927
  flagExposureDedupeMaxSize?: number;
1928
+ /**
1929
+ * Query parameters to read from the page URL and add as attributes to all
1930
+ * telemetry, as if passed to `LDObserve.setAttributes`.
1931
+ *
1932
+ * When the SDK initializes, each listed parameter present in
1933
+ * `location.search` becomes an attribute named after the parameter (e.g.
1934
+ * `utm_campaign`) on every span (including document load, page view and
1935
+ * fetch/XHR spans), log, error and metric for the rest of the page load,
1936
+ * including after SPA navigation drops it from the URL.
1937
+ *
1938
+ * Last touch: when an SPA navigation lands on a URL with any listed
1939
+ * parameter, the captured values are replaced by that URL's values, and
1940
+ * previously captured keys missing from it are removed, so the set always
1941
+ * reflects one landing. A navigation without listed parameters keeps the
1942
+ * current values. Spans already started keep the values they had.
1943
+ *
1944
+ * Values are kept in memory only; nothing is written to storage or
1945
+ * cookies, so a later full page load captures again from its own URL.
1946
+ *
1947
+ * Only the listed keys are captured, so other query parameters (which may
1948
+ * hold personal data such as emails or tokens) are never recorded this
1949
+ * way. The default list contains UTM parameters only. A name ending in `*`
1950
+ * matches every parameter with that prefix (e.g. `'utm_*'`).
1951
+ *
1952
+ * Keys set with `setAttributes` win: capture never replaces or removes a
1953
+ * key the app set itself. `removeAttributes` removes a captured value
1954
+ * (a later landing with that parameter captures it again). Keys in the
1955
+ * namespaces the SDK sets itself (`highlight.*`, `launchdarkly.*`,
1956
+ * `session.*`, `context.contextKeys.*`) are ignored.
1957
+ *
1958
+ * A custom list replaces the default. Set to `false` or `[]` to turn
1959
+ * capture off.
1960
+ * @default ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']
1961
+ * @example captureQueryParams: ['utm_source', 'utm_campaign', 'gclid']
1962
+ */
1963
+ captureQueryParams?: string[] | false;
1964
+ /**
1965
+ * Specifies whether to record the page that linked to this one. When the
1966
+ * SDK initializes and `document.referrer` is a different origin, it is
1967
+ * added as the `landing.referrer` attribute to all telemetry for the rest
1968
+ * of the page load, as if passed to `LDObserve.setAttributes`.
1969
+ *
1970
+ * Only the origin and path are kept: the query string, fragment and any
1971
+ * credentials are stripped so tokens or personal data in the referrer URL
1972
+ * are not recorded. An empty or same-origin referrer sets nothing, and
1973
+ * the value is not updated on SPA navigation.
1974
+ * @default true
1975
+ */
1976
+ captureReferrer?: boolean;
1870
1977
  };
1871
1978
 
1872
1979
  declare interface OnHighlightReadyOptions {
@@ -1893,6 +2000,32 @@ declare interface OTelMetric {
1893
2000
 
1894
2001
  declare type OtelOptions = {
1895
2002
  instrumentations?: OtelInstrumentatonOptions;
2003
+ /**
2004
+ * Called for each auto-instrumented `fetch` and `XMLHttpRequest` span just
2005
+ * before it ends, so the response and error status are already on it.
2006
+ * Use it to rename the span or add attributes, for example to give it a
2007
+ * route template:
2008
+ *
2009
+ * ```ts
2010
+ * onHttpRequestSpan: (span, { method, url }) => {
2011
+ * const route = matchRoute(url) // '/api/users/{userId}'
2012
+ * if (!route) return
2013
+ * span.updateName(`${method} ${route}`)
2014
+ * span.setAttributes({
2015
+ * 'http.route': route,
2016
+ * 'url.template': route,
2017
+ * 'launchdarkly.operation.name': route,
2018
+ * })
2019
+ * }
2020
+ * ```
2021
+ *
2022
+ * The span's trace and span ids are fixed when the request starts, so
2023
+ * renaming does not affect the `traceparent` sent to your backend.
2024
+ * Errors thrown by the callback are swallowed. Requires
2025
+ * `networkRecording` to be enabled, as the instrumentations are not
2026
+ * installed otherwise.
2027
+ */
2028
+ onHttpRequestSpan?: (span: Span, request: HttpSpanRequest) => void;
1896
2029
  };
1897
2030
 
1898
2031
  declare class Plugin_2<T extends RecordOptions | ObserveOptions> {
@@ -2196,6 +2329,7 @@ declare class RecordSDK implements Record_3 {
2196
2329
  _isCrossOriginIframe: boolean;
2197
2330
  _eventBytesSinceSnapshot: number;
2198
2331
  _lastSnapshotTime: number;
2332
+ _snapshotPayloadIds: Set<number>;
2199
2333
  _lastVisibilityChangeTime: number;
2200
2334
  pushPayloadTimerId: ReturnType<typeof setTimeout> | undefined;
2201
2335
  hasSessionUnloaded: boolean;