@launchdarkly/o11y 1.4.1 → 1.5.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;
@@ -1893,6 +1951,32 @@ declare interface OTelMetric {
1893
1951
 
1894
1952
  declare type OtelOptions = {
1895
1953
  instrumentations?: OtelInstrumentatonOptions;
1954
+ /**
1955
+ * Called for each auto-instrumented `fetch` and `XMLHttpRequest` span just
1956
+ * before it ends, so the response and error status are already on it.
1957
+ * Use it to rename the span or add attributes, for example to give it a
1958
+ * route template:
1959
+ *
1960
+ * ```ts
1961
+ * onHttpRequestSpan: (span, { method, url }) => {
1962
+ * const route = matchRoute(url) // '/api/users/{userId}'
1963
+ * if (!route) return
1964
+ * span.updateName(`${method} ${route}`)
1965
+ * span.setAttributes({
1966
+ * 'http.route': route,
1967
+ * 'url.template': route,
1968
+ * 'launchdarkly.operation.name': route,
1969
+ * })
1970
+ * }
1971
+ * ```
1972
+ *
1973
+ * The span's trace and span ids are fixed when the request starts, so
1974
+ * renaming does not affect the `traceparent` sent to your backend.
1975
+ * Errors thrown by the callback are swallowed. Requires
1976
+ * `networkRecording` to be enabled, as the instrumentations are not
1977
+ * installed otherwise.
1978
+ */
1979
+ onHttpRequestSpan?: (span: Span, request: HttpSpanRequest) => void;
1896
1980
  };
1897
1981
 
1898
1982
  declare class Plugin_2<T extends RecordOptions | ObserveOptions> {
@@ -2196,6 +2280,7 @@ declare class RecordSDK implements Record_3 {
2196
2280
  _isCrossOriginIframe: boolean;
2197
2281
  _eventBytesSinceSnapshot: number;
2198
2282
  _lastSnapshotTime: number;
2283
+ _snapshotPayloadIds: Set<number>;
2199
2284
  _lastVisibilityChangeTime: number;
2200
2285
  pushPayloadTimerId: ReturnType<typeof setTimeout> | undefined;
2201
2286
  hasSessionUnloaded: boolean;