@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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.5.0](https://github.com/launchdarkly/observability-sdk/compare/o11y-1.4.1...o11y-1.5.0) (2026-11-03)
4
+
5
+
6
+ ### Features
7
+
8
+ * **o11y:** add otel.onHttpRequestSpan hook for auto fetch/XHR spans ([#872](https://github.com/launchdarkly/observability-sdk/issues/872)) ([4387ead](https://github.com/launchdarkly/observability-sdk/commit/4387eadbeddfbdd6f2449d81c906b63f42c1736d))
9
+ * **o11y:** add setAttributes/removeAttributes and stamp context keys on every span ([#855](https://github.com/launchdarkly/observability-sdk/issues/855)) ([c086c84](https://github.com/launchdarkly/observability-sdk/commit/c086c846eb1ea0832f4337885c0064004a2c2de4))
10
+ * **o11y:** link a new browser session to the one it replaces ([#857](https://github.com/launchdarkly/observability-sdk/issues/857)) ([cf5ccbe](https://github.com/launchdarkly/observability-sdk/commit/cf5ccbe5374983262a9b42783bef791cec9b1497))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **o11y:** don't count a full snapshot's bytes toward the next snapshot ([#874](https://github.com/launchdarkly/observability-sdk/issues/874)) ([0ca2e72](https://github.com/launchdarkly/observability-sdk/commit/0ca2e72da05567fa1b53205a5406b9a6dc4de733))
16
+
3
17
  ## [1.4.1](https://github.com/launchdarkly/observability-sdk/compare/o11y-1.4.0...o11y-1.4.1) (2026-10-29)
4
18
 
5
19
 
@@ -0,0 +1,160 @@
1
+ var o = (s, t, r) => new Promise((e, a) => {
2
+ var n = (i) => {
3
+ try {
4
+ l(r.next(i));
5
+ } catch (f) {
6
+ a(f);
7
+ }
8
+ }, h = (i) => {
9
+ try {
10
+ l(r.throw(i));
11
+ } catch (f) {
12
+ a(f);
13
+ }
14
+ }, l = (i) => i.done ? e(i.value) : Promise.resolve(i.value).then(n, h);
15
+ l((r = r.apply(s, t)).next());
16
+ });
17
+ import { B as p, d as g } from "./buffer-CwCRPuMA.js";
18
+ const d = () => {
19
+ const s = {
20
+ end: () => {
21
+ },
22
+ spanContext: () => ({
23
+ traceId: "",
24
+ spanId: "",
25
+ traceFlags: 0
26
+ }),
27
+ setAttribute: (t, r) => s,
28
+ setAttributes: (t) => s,
29
+ addEvent: (t, r, e) => s,
30
+ addLinks: (t) => s,
31
+ setStatus: (t) => s,
32
+ recordException: () => {
33
+ },
34
+ addLink: () => s,
35
+ updateName: () => s,
36
+ isRecording: () => !1
37
+ };
38
+ return s;
39
+ };
40
+ function b(s, t, r) {
41
+ if (typeof r == "function")
42
+ return r;
43
+ if (typeof t == "function")
44
+ return t;
45
+ if (typeof s == "function")
46
+ return s;
47
+ }
48
+ const c = /* @__PURE__ */ new Set(["setAttributes", "removeAttributes"]);
49
+ class _ extends p {
50
+ /**
51
+ * Applies buffered `setAttributes`/`removeAttributes` calls to `sdk`
52
+ * without attaching it. Call it before `sdk.start()` so attributes set
53
+ * before init reach spans recorded synchronously during start (e.g. the
54
+ * document load span). `load` also does this, so calling it is optional.
55
+ */
56
+ applyBufferedAttributes(t) {
57
+ const r = this._callBuffer.filter(
58
+ ({ method: e }) => c.has(e)
59
+ );
60
+ if (r.length) {
61
+ this._callBuffer = this._callBuffer.filter(
62
+ ({ method: e }) => !c.has(e)
63
+ ), this._sdk = t;
64
+ for (const { method: e, args: a } of r)
65
+ this._callSdk(e, a);
66
+ }
67
+ }
68
+ load(t, r) {
69
+ this.applyBufferedAttributes(t), super.load(t, r);
70
+ }
71
+ _startSdk() {
72
+ return o(this, null, function* () {
73
+ yield this._sdk.start();
74
+ });
75
+ }
76
+ // Never buffered: with `manualStart`, `start()` may run before the plugin
77
+ // has attached an SDK. It then stays pending and resolves once `load`
78
+ // attaches and starts the SDK.
79
+ start() {
80
+ return o(this, null, function* () {
81
+ return this._start();
82
+ });
83
+ }
84
+ // Never buffered, and never throws: before an SDK is attached it just
85
+ // cancels a start that has not run yet.
86
+ stop() {
87
+ return o(this, null, function* () {
88
+ yield this._stop(() => this._sdk.stop());
89
+ });
90
+ }
91
+ recordGauge(t) {
92
+ return this._bufferCall("recordGauge", [t]);
93
+ }
94
+ recordCount(t) {
95
+ return this._bufferCall("recordCount", [t]);
96
+ }
97
+ recordIncr(t) {
98
+ return this._bufferCall("recordIncr", [t]);
99
+ }
100
+ recordHistogram(t) {
101
+ return this._bufferCall("recordHistogram", [t]);
102
+ }
103
+ recordUpDownCounter(t) {
104
+ return this._bufferCall("recordUpDownCounter", [t]);
105
+ }
106
+ // The callback holds the caller's own work, so it must never be buffered:
107
+ // deferring it would replay that work at an arbitrary later time, or drop it.
108
+ startSpan(t, r, e, a) {
109
+ var n;
110
+ return this._isReady ? this._bufferCall("startSpan", [t, r, e, a]) : (this._logNoopSpanWarning(), (n = b(r, e, a)) == null ? void 0 : n(d()));
111
+ }
112
+ startManualSpan(t, r, e, a) {
113
+ var n;
114
+ return this._isReady ? this._bufferCall("startManualSpan", [t, r, e, a]) : (this._logNoopSpanWarning(), (n = b(r, e, a)) == null ? void 0 : n(d()));
115
+ }
116
+ _logNoopSpanWarning() {
117
+ g(
118
+ "startSpan/startManualSpan called before start()",
119
+ "span-before-start",
120
+ "warn",
121
+ "The span callback runs on a no-op span and the span is not recorded."
122
+ );
123
+ }
124
+ register(t, r) {
125
+ return this._bufferCall("register", [t, r]);
126
+ }
127
+ recordLog(t, r, e) {
128
+ return this._bufferCall("recordLog", [t, r, e]);
129
+ }
130
+ recordError(t, r, e, a, n) {
131
+ return this._bufferCall("recordError", [
132
+ t,
133
+ r,
134
+ e,
135
+ a,
136
+ n
137
+ ]);
138
+ }
139
+ setLDContextKeyAttributes(t) {
140
+ return this._bufferCall("setLDContextKeyAttributes", [t]);
141
+ }
142
+ // Applied directly once an SDK is attached, even before it starts (see
143
+ // ATTRIBUTE_METHODS).
144
+ setAttributes(t) {
145
+ return this._isLoaded ? this._callSdk("setAttributes", [t]) : this._bufferCall("setAttributes", [t]);
146
+ }
147
+ removeAttributes(t) {
148
+ return this._isLoaded ? this._callSdk("removeAttributes", [t]) : this._bufferCall("removeAttributes", [t]);
149
+ }
150
+ getLDContextKeyAttributes() {
151
+ return this._isLoaded ? this._callSdk("getLDContextKeyAttributes", []) : void 0;
152
+ }
153
+ }
154
+ let u;
155
+ typeof globalThis != "undefined" ? globalThis.LDObserve ? u = globalThis.LDObserve : (u = new _(), globalThis.LDObserve = u) : u = new _();
156
+ export {
157
+ u as L,
158
+ d as g
159
+ };
160
+ //# sourceMappingURL=LDObserve-o8Ro1UV8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LDObserve-o8Ro1UV8.js","sources":["../src/client/otel/utils.ts","../src/sdk/LDObserve.ts"],"sourcesContent":["import {\n\tAttributes,\n\tAttributeValue,\n\tLink,\n\tSpan,\n\tSpanStatus,\n\tTimeInput,\n} from '@opentelemetry/api'\n\nexport const getNoopSpan = () => {\n\tconst noopSpan: Span = {\n\t\tend: () => {},\n\t\tspanContext: () => ({\n\t\t\ttraceId: '',\n\t\t\tspanId: '',\n\t\t\ttraceFlags: 0,\n\t\t}),\n\t\tsetAttribute: (_key: string, _value: AttributeValue) => noopSpan,\n\t\tsetAttributes: (_attributes: Attributes) => noopSpan,\n\t\taddEvent: (\n\t\t\t_name: string,\n\t\t\t_attributesOrStartTime?: Attributes | TimeInput,\n\t\t\t_startTime?: TimeInput,\n\t\t) => noopSpan,\n\t\taddLinks: (_links: Link[]) => noopSpan,\n\t\tsetStatus: (_status: SpanStatus) => noopSpan,\n\t\trecordException: () => {},\n\t\taddLink: () => noopSpan,\n\t\tupdateName: () => noopSpan,\n\t\tisRecording: () => false,\n\t}\n\n\treturn noopSpan\n}\n","import type { Observe } from '../api/observe'\nimport type { LDClient } from '../integrations/launchdarkly'\nimport type { ErrorMessageType } from '../client/types/shared-types'\nimport type { OTelMetric as Metric } from '../client/types/types'\nimport type {\n\tAttributes,\n\tAttributeValue,\n\tContext,\n\tSpan,\n\tSpanOptions,\n} from '@opentelemetry/api'\nimport type { LDPluginEnvironmentMetadata } from '../plugins/plugin'\nimport { BufferedClass, type BufferedLoadOptions } from './buffer'\nimport { getNoopSpan } from '../client/otel/utils'\nimport { ConsoleMethods } from '../client/types/client'\nimport { internalLogOnce } from './util'\n\n/**\n * Resolves the span callback from whichever argument position it was passed in,\n * matching the overloads `startSpan` and `startManualSpan` accept.\n */\nfunction resolveSpanCallback(\n\toptions: unknown,\n\tcontext: unknown,\n\tfn: unknown,\n): ((span: Span) => any) | undefined {\n\tif (typeof fn === 'function') {\n\t\treturn fn as (span: Span) => any\n\t}\n\tif (typeof context === 'function') {\n\t\treturn context as (span: Span) => any\n\t}\n\tif (typeof options === 'function') {\n\t\treturn options as (span: Span) => any\n\t}\n\treturn undefined\n}\n\n// Calls that only update SDK state used to tag telemetry. Buffered ones are\n// applied as soon as an SDK is attached, before it starts, so they reach\n// telemetry recorded during start-up (e.g. the document load span).\nconst ATTRIBUTE_METHODS = new Set(['setAttributes', 'removeAttributes'])\n\nclass _LDObserve extends BufferedClass<Observe> implements Observe {\n\t/**\n\t * Applies buffered `setAttributes`/`removeAttributes` calls to `sdk`\n\t * without attaching it. Call it before `sdk.start()` so attributes set\n\t * before init reach spans recorded synchronously during start (e.g. the\n\t * document load span). `load` also does this, so calling it is optional.\n\t */\n\tapplyBufferedAttributes(sdk: Observe) {\n\t\tconst attributeCalls = this._callBuffer.filter(({ method }) =>\n\t\t\tATTRIBUTE_METHODS.has(method),\n\t\t)\n\t\tif (!attributeCalls.length) {\n\t\t\treturn\n\t\t}\n\t\tthis._callBuffer = this._callBuffer.filter(\n\t\t\t({ method }) => !ATTRIBUTE_METHODS.has(method),\n\t\t)\n\t\tthis._sdk = sdk\n\t\tfor (const { method, args } of attributeCalls) {\n\t\t\tthis._callSdk(method, args)\n\t\t}\n\t}\n\n\tload(sdk: Observe, options?: BufferedLoadOptions) {\n\t\tthis.applyBufferedAttributes(sdk)\n\t\tsuper.load(sdk, options)\n\t}\n\n\tprotected async _startSdk() {\n\t\tawait this._sdk.start()\n\t}\n\n\t// Never buffered: with `manualStart`, `start()` may run before the plugin\n\t// has attached an SDK. It then stays pending and resolves once `load`\n\t// attaches and starts the SDK.\n\tasync start() {\n\t\treturn this._start()\n\t}\n\n\t// Never buffered, and never throws: before an SDK is attached it just\n\t// cancels a start that has not run yet.\n\tasync stop() {\n\t\tawait this._stop(() => this._sdk.stop())\n\t}\n\n\trecordGauge(metric: Metric) {\n\t\treturn this._bufferCall('recordGauge', [metric])\n\t}\n\n\trecordCount(metric: Metric) {\n\t\treturn this._bufferCall('recordCount', [metric])\n\t}\n\n\trecordIncr(metric: Omit<Metric, 'value'>) {\n\t\treturn this._bufferCall('recordIncr', [metric])\n\t}\n\n\trecordHistogram(metric: Metric) {\n\t\treturn this._bufferCall('recordHistogram', [metric])\n\t}\n\n\trecordUpDownCounter(metric: Metric) {\n\t\treturn this._bufferCall('recordUpDownCounter', [metric])\n\t}\n\n\t// The callback holds the caller's own work, so it must never be buffered:\n\t// deferring it would replay that work at an arbitrary later time, or drop it.\n\tstartSpan(\n\t\tname: string,\n\t\toptions: SpanOptions | ((span?: Span) => any),\n\t\tcontext?: Context | ((span?: Span) => any),\n\t\tfn?: (span?: Span) => any,\n\t) {\n\t\tif (!this._isReady) {\n\t\t\tthis._logNoopSpanWarning()\n\t\t\treturn resolveSpanCallback(options, context, fn)?.(getNoopSpan())\n\t\t}\n\t\treturn this._bufferCall('startSpan', [name, options, context, fn])\n\t}\n\n\tstartManualSpan(\n\t\tname: string,\n\t\toptions: SpanOptions | ((span: Span) => any),\n\t\tcontext?: Context | ((span: Span) => any),\n\t\tfn?: (span: Span) => any,\n\t) {\n\t\tif (!this._isReady) {\n\t\t\tthis._logNoopSpanWarning()\n\t\t\treturn resolveSpanCallback(options, context, fn)?.(getNoopSpan())\n\t\t}\n\t\treturn this._bufferCall('startManualSpan', [name, options, context, fn])\n\t}\n\n\tprivate _logNoopSpanWarning() {\n\t\tinternalLogOnce(\n\t\t\t'startSpan/startManualSpan called before start()',\n\t\t\t'span-before-start',\n\t\t\t'warn',\n\t\t\t'The span callback runs on a no-op span and the span is not recorded.',\n\t\t)\n\t}\n\n\tregister(\n\t\tclient: LDClient,\n\t\tenvironmentMetadata: LDPluginEnvironmentMetadata,\n\t) {\n\t\treturn this._bufferCall('register', [client, environmentMetadata])\n\t}\n\n\trecordLog(message: any, level: ConsoleMethods, metadata?: Attributes) {\n\t\treturn this._bufferCall('recordLog', [message, level, metadata])\n\t}\n\n\trecordError(\n\t\terror: Error,\n\t\tmessage?: string,\n\t\tpayload?: { [key: string]: string },\n\t\tsource?: string,\n\t\ttype?: ErrorMessageType,\n\t) {\n\t\treturn this._bufferCall('recordError', [\n\t\t\terror,\n\t\t\tmessage,\n\t\t\tpayload,\n\t\t\tsource,\n\t\t\ttype,\n\t\t])\n\t}\n\n\tsetLDContextKeyAttributes(contextKeys: Attributes) {\n\t\treturn this._bufferCall('setLDContextKeyAttributes', [contextKeys])\n\t}\n\n\t// Applied directly once an SDK is attached, even before it starts (see\n\t// ATTRIBUTE_METHODS).\n\tsetAttributes(\n\t\tattributes: Record<string, AttributeValue | null | undefined>,\n\t) {\n\t\tif (this._isLoaded) {\n\t\t\treturn this._callSdk('setAttributes', [attributes])\n\t\t}\n\t\treturn this._bufferCall('setAttributes', [attributes])\n\t}\n\n\tremoveAttributes(keys: string[]) {\n\t\tif (this._isLoaded) {\n\t\t\treturn this._callSdk('removeAttributes', [keys])\n\t\t}\n\t\treturn this._bufferCall('removeAttributes', [keys])\n\t}\n\n\tgetLDContextKeyAttributes(): Attributes | undefined {\n\t\t// A getter: read directly once attached rather than buffering.\n\t\treturn this._isLoaded\n\t\t\t? this._callSdk('getLDContextKeyAttributes', [])\n\t\t\t: undefined\n\t}\n}\n\ninterface GlobalThis {\n\tLDObserve?: _LDObserve\n}\ndeclare var globalThis: GlobalThis\n\nexport let LDObserve!: _LDObserve\nif (typeof globalThis !== 'undefined') {\n\tif (globalThis.LDObserve) {\n\t\tLDObserve = globalThis.LDObserve\n\t} else {\n\t\tLDObserve = new _LDObserve()\n\t\tglobalThis.LDObserve = LDObserve\n\t}\n} else {\n\tLDObserve = new _LDObserve()\n}\n"],"names":["getNoopSpan","noopSpan","_key","_value","_attributes","_name","_attributesOrStartTime","_startTime","_links","_status","resolveSpanCallback","options","context","fn","ATTRIBUTE_METHODS","_LDObserve","BufferedClass","sdk","attributeCalls","method","args","__async","metric","name","_a","internalLogOnce","client","environmentMetadata","message","level","metadata","error","payload","source","type","contextKeys","attributes","keys","LDObserve"],"mappings":";;;;;;;;;;;;;;;;;AASO,MAAMA,IAAc,MAAM;AAChC,QAAMC,IAAiB;AAAA,IACtB,KAAK,MAAM;AAAA,IAAC;AAAA,IACZ,aAAa,OAAO;AAAA,MACnB,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,YAAY;AAAA,IAAA;AAAA,IAEb,cAAc,CAACC,GAAcC,MAA2BF;AAAA,IACxD,eAAe,CAACG,MAA4BH;AAAA,IAC5C,UAAU,CACTI,GACAC,GACAC,MACIN;AAAA,IACL,UAAU,CAACO,MAAmBP;AAAA,IAC9B,WAAW,CAACQ,MAAwBR;AAAA,IACpC,iBAAiB,MAAM;AAAA,IAAC;AAAA,IACxB,SAAS,MAAMA;AAAA,IACf,YAAY,MAAMA;AAAA,IAClB,aAAa,MAAM;AAAA,EAAA;AAGpB,SAAOA;AACR;ACZA,SAASS,EACRC,GACAC,GACAC,GACoC;AACpC,MAAI,OAAOA,KAAO;AACjB,WAAOA;AAER,MAAI,OAAOD,KAAY;AACtB,WAAOA;AAER,MAAI,OAAOD,KAAY;AACtB,WAAOA;AAGT;AAKA,MAAMG,IAAoB,oBAAI,IAAI,CAAC,iBAAiB,kBAAkB,CAAC;AAEvE,MAAMC,UAAmBC,EAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOlE,wBAAwBC,GAAc;AACrC,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AoB,CAACA,CAAI,CAAC,IAEzC,KAAK,YAAY,oBAAoB,CAACA,CAAI,CAAC;AAAA,EACnD;AAAA,EAEA,4BAAoD;AAEnD,WAAO,KAAK,YACT,KAAK,SAAS,6BAA6B,CAAA,CAAE,IAC7C;AAAA,EACJ;AACD;AAOO,IAAIC;AACP,OAAO,cAAe,cACrB,WAAW,YACdA,IAAY,WAAW,aAEvBA,IAAY,IAAIvB,EAAA,GAChB,WAAW,YAAYuB,KAGxBA,IAAY,IAAIvB,EAAA;"}
@@ -226,6 +226,14 @@ declare interface LDClientMin {
226
226
  export declare let LDObserve: _LDObserve;
227
227
 
228
228
  declare class _LDObserve extends BufferedClass<Observe> implements Observe {
229
+ /**
230
+ * Applies buffered `setAttributes`/`removeAttributes` calls to `sdk`
231
+ * without attaching it. Call it before `sdk.start()` so attributes set
232
+ * before init reach spans recorded synchronously during start (e.g. the
233
+ * document load span). `load` also does this, so calling it is optional.
234
+ */
235
+ applyBufferedAttributes(sdk: Observe): void;
236
+ load(sdk: Observe, options?: BufferedLoadOptions): void;
229
237
  protected _startSdk(): Promise<void>;
230
238
  start(): Promise<void>;
231
239
  stop(): Promise<void>;
@@ -243,6 +251,8 @@ declare class _LDObserve extends BufferedClass<Observe> implements Observe {
243
251
  [key: string]: string;
244
252
  }, source?: string, type?: ErrorMessageType): any;
245
253
  setLDContextKeyAttributes(contextKeys: Attributes): any;
254
+ setAttributes(attributes: Record<string, AttributeValue | null | undefined>): any;
255
+ removeAttributes(keys: string[]): any;
246
256
  getLDContextKeyAttributes(): Attributes | undefined;
247
257
  }
248
258
 
@@ -412,6 +422,40 @@ declare interface Observe {
412
422
  * Useful when you don't want to emit a console log to the browser dev tools but still want to report a custom log.
413
423
  */
414
424
  recordLog: (message: any, level: ConsoleMethods, metadata?: Attributes) => void;
425
+ /**
426
+ * Adds attributes to all telemetry recorded from now on: every span
427
+ * (including automatically instrumented ones such as document load,
428
+ * fetch/XHR, clicks and page views), log, error and metric.
429
+ *
430
+ * Calling it again merges with the attributes already set; a `null` or
431
+ * `undefined` value removes that key. Attributes passed to an individual
432
+ * call (for example `recordLog` metadata or metric attributes) take
433
+ * precedence over these. Keys in namespaces the SDK sets itself
434
+ * (`highlight.*`, `launchdarkly.*`, `session.*`, `context.contextKeys.*`)
435
+ * are ignored.
436
+ *
437
+ * Attributes are held in memory for the current page load only: they are
438
+ * never persisted, and a full page load starts without them.
439
+ *
440
+ * Each attribute is also added to every metric, so a value with many
441
+ * distinct values (such as a user ID) creates as many metric series.
442
+ *
443
+ * @example
444
+ * ```typescript
445
+ * LDObserve.setAttributes({ utm_campaign: 'spring_promo', utm_source: 'email' })
446
+ * ```
447
+ */
448
+ setAttributes(attributes: Record<string, AttributeValue | null | undefined>): void;
449
+ /**
450
+ * Removes attributes previously added with `setAttributes`. Telemetry
451
+ * recorded afterwards no longer carries them.
452
+ *
453
+ * @example
454
+ * ```typescript
455
+ * LDObserve.removeAttributes(['utm_campaign'])
456
+ * ```
457
+ */
458
+ removeAttributes(keys: string[]): void;
415
459
  register(client: LDClientMin, environmentMetadata: LDPluginEnvironmentMetadata): void;
416
460
  getHooks?(metadata: LDPluginEnvironmentMetadata): Hook[];
417
461
  setLDContextKeyAttributes(contextKeys: Attributes): void;
package/dist/LDObserve.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./buffer-CwCRPuMA.js";
2
- import { L as m } from "./LDObserve-BQr7RYVC.js";
2
+ import { L as m } from "./LDObserve-o8Ro1UV8.js";
3
3
  export {
4
4
  m as LDObserve
5
5
  };