@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/observe.d.ts CHANGED
@@ -234,6 +234,19 @@ declare type Hook = Omit<Hook_2, 'afterEvaluation'> & {
234
234
  */
235
235
  declare type HrTime = [number, number];
236
236
 
237
+ /**
238
+ * Describes the request behind an auto-instrumented browser `fetch` or
239
+ * `XMLHttpRequest` span.
240
+ */
241
+ declare type HttpSpanRequest = {
242
+ /** Which instrumentation created the span. */
243
+ type: 'fetch' | 'xhr';
244
+ /** Upper-cased HTTP method, e.g. `GET`. */
245
+ method: string;
246
+ /** The concrete request URL, e.g. `https://app.example.com/api/users/42`. */
247
+ url: string;
248
+ };
249
+
237
250
  declare type IntegrationOptions = {
238
251
  amplitude?: AmplitudeIntegrationOptions;
239
252
  intercom?: IntercomIntegrationOptions;
@@ -555,6 +568,40 @@ declare interface Observe_2 {
555
568
  * Useful when you don't want to emit a console log to the browser dev tools but still want to report a custom log.
556
569
  */
557
570
  recordLog: (message: any, level: ConsoleMethods, metadata?: Attributes) => void;
571
+ /**
572
+ * Adds attributes to all telemetry recorded from now on: every span
573
+ * (including automatically instrumented ones such as document load,
574
+ * fetch/XHR, clicks and page views), log, error and metric.
575
+ *
576
+ * Calling it again merges with the attributes already set; a `null` or
577
+ * `undefined` value removes that key. Attributes passed to an individual
578
+ * call (for example `recordLog` metadata or metric attributes) take
579
+ * precedence over these. Keys in namespaces the SDK sets itself
580
+ * (`highlight.*`, `launchdarkly.*`, `session.*`, `context.contextKeys.*`)
581
+ * are ignored.
582
+ *
583
+ * Attributes are held in memory for the current page load only: they are
584
+ * never persisted, and a full page load starts without them.
585
+ *
586
+ * Each attribute is also added to every metric, so a value with many
587
+ * distinct values (such as a user ID) creates as many metric series.
588
+ *
589
+ * @example
590
+ * ```typescript
591
+ * LDObserve.setAttributes({ utm_campaign: 'spring_promo', utm_source: 'email' })
592
+ * ```
593
+ */
594
+ setAttributes(attributes: Record<string, AttributeValue | null | undefined>): void;
595
+ /**
596
+ * Removes attributes previously added with `setAttributes`. Telemetry
597
+ * recorded afterwards no longer carries them.
598
+ *
599
+ * @example
600
+ * ```typescript
601
+ * LDObserve.removeAttributes(['utm_campaign'])
602
+ * ```
603
+ */
604
+ removeAttributes(keys: string[]): void;
558
605
  register(client: LDClientMin, environmentMetadata: LDPluginEnvironmentMetadata): void;
559
606
  getHooks?(metadata: LDPluginEnvironmentMetadata): Hook[];
560
607
  setLDContextKeyAttributes(contextKeys: Attributes): void;
@@ -666,6 +713,55 @@ declare type ObserveOptions = CommonOptions & {
666
713
  * @default 2000
667
714
  */
668
715
  flagExposureDedupeMaxSize?: number;
716
+ /**
717
+ * Query parameters to read from the page URL and add as attributes to all
718
+ * telemetry, as if passed to `LDObserve.setAttributes`.
719
+ *
720
+ * When the SDK initializes, each listed parameter present in
721
+ * `location.search` becomes an attribute named after the parameter (e.g.
722
+ * `utm_campaign`) on every span (including document load, page view and
723
+ * fetch/XHR spans), log, error and metric for the rest of the page load,
724
+ * including after SPA navigation drops it from the URL.
725
+ *
726
+ * Last touch: when an SPA navigation lands on a URL with any listed
727
+ * parameter, the captured values are replaced by that URL's values, and
728
+ * previously captured keys missing from it are removed, so the set always
729
+ * reflects one landing. A navigation without listed parameters keeps the
730
+ * current values. Spans already started keep the values they had.
731
+ *
732
+ * Values are kept in memory only; nothing is written to storage or
733
+ * cookies, so a later full page load captures again from its own URL.
734
+ *
735
+ * Only the listed keys are captured, so other query parameters (which may
736
+ * hold personal data such as emails or tokens) are never recorded this
737
+ * way. The default list contains UTM parameters only. A name ending in `*`
738
+ * matches every parameter with that prefix (e.g. `'utm_*'`).
739
+ *
740
+ * Keys set with `setAttributes` win: capture never replaces or removes a
741
+ * key the app set itself. `removeAttributes` removes a captured value
742
+ * (a later landing with that parameter captures it again). Keys in the
743
+ * namespaces the SDK sets itself (`highlight.*`, `launchdarkly.*`,
744
+ * `session.*`, `context.contextKeys.*`) are ignored.
745
+ *
746
+ * A custom list replaces the default. Set to `false` or `[]` to turn
747
+ * capture off.
748
+ * @default ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']
749
+ * @example captureQueryParams: ['utm_source', 'utm_campaign', 'gclid']
750
+ */
751
+ captureQueryParams?: string[] | false;
752
+ /**
753
+ * Specifies whether to record the page that linked to this one. When the
754
+ * SDK initializes and `document.referrer` is a different origin, it is
755
+ * added as the `landing.referrer` attribute to all telemetry for the rest
756
+ * of the page load, as if passed to `LDObserve.setAttributes`.
757
+ *
758
+ * Only the origin and path are kept: the query string, fragment and any
759
+ * credentials are stripped so tokens or personal data in the referrer URL
760
+ * are not recorded. An empty or same-origin referrer sets nothing, and
761
+ * the value is not updated on SPA navigation.
762
+ * @default true
763
+ */
764
+ captureReferrer?: boolean;
669
765
  };
670
766
 
671
767
  declare type OtelInstrumentatonOptions = {
@@ -685,6 +781,32 @@ declare interface OTelMetric {
685
781
 
686
782
  declare type OtelOptions = {
687
783
  instrumentations?: OtelInstrumentatonOptions;
784
+ /**
785
+ * Called for each auto-instrumented `fetch` and `XMLHttpRequest` span just
786
+ * before it ends, so the response and error status are already on it.
787
+ * Use it to rename the span or add attributes, for example to give it a
788
+ * route template:
789
+ *
790
+ * ```ts
791
+ * onHttpRequestSpan: (span, { method, url }) => {
792
+ * const route = matchRoute(url) // '/api/users/{userId}'
793
+ * if (!route) return
794
+ * span.updateName(`${method} ${route}`)
795
+ * span.setAttributes({
796
+ * 'http.route': route,
797
+ * 'url.template': route,
798
+ * 'launchdarkly.operation.name': route,
799
+ * })
800
+ * }
801
+ * ```
802
+ *
803
+ * The span's trace and span ids are fixed when the request starts, so
804
+ * renaming does not affect the `traceparent` sent to your backend.
805
+ * Errors thrown by the callback are swallowed. Requires
806
+ * `networkRecording` to be enabled, as the instrumentations are not
807
+ * installed otherwise.
808
+ */
809
+ onHttpRequestSpan?: (span: Span, request: HttpSpanRequest) => void;
688
810
  };
689
811
 
690
812
  declare class Plugin_2<T extends RecordOptions | ObserveOptions> {
package/dist/observe.js CHANGED
@@ -1,6 +1,6 @@
1
- import "./common-D8kkCWo3.js";
2
- import { O as e } from "./observe-BCebRa17.js";
3
- import "./LDObserve-BQr7RYVC.js";
1
+ import "./common-C6gSg2Rq.js";
2
+ import { O as e } from "./observe-CL-A2YiL.js";
3
+ import "./LDObserve-o8Ro1UV8.js";
4
4
  import "./buffer-CwCRPuMA.js";
5
5
  export {
6
6
  e as Observe