@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/record.d.ts CHANGED
@@ -77,10 +77,26 @@ declare type attributeMutation = {
77
77
  };
78
78
  };
79
79
 
80
+ /**
81
+ * Attributes is a map from string to attribute values.
82
+ *
83
+ * Note: only the own enumerable keys are counted as valid attribute keys.
84
+ */
85
+ declare interface Attributes {
86
+ [attributeKey: string]: AttributeValue | undefined;
87
+ }
88
+
80
89
  declare type attributes = cssTextKeyAttr & {
81
90
  [key: string]: string | number | true | null;
82
91
  };
83
92
 
93
+ /**
94
+ * Attribute values may be any non-nullish primitive value except an object.
95
+ *
96
+ * null or undefined attribute values are invalid and will result in undefined behavior.
97
+ */
98
+ declare type AttributeValue = string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>;
99
+
84
100
  declare type CanvasArg = SerializedCanvasArg | string | number | boolean | null | CanvasArg[];
85
101
 
86
102
  declare enum CanvasContext {
@@ -318,6 +334,34 @@ declare type Exact<T extends {
318
334
  [K in keyof T]: T[K];
319
335
  };
320
336
 
337
+ /**
338
+ * Defines Exception.
339
+ *
340
+ * string or an object with one of (message or name or code) and optional stack
341
+ */
342
+ declare type Exception = ExceptionWithCode | ExceptionWithMessage | ExceptionWithName | string;
343
+
344
+ declare interface ExceptionWithCode {
345
+ code: string | number;
346
+ name?: string;
347
+ message?: string;
348
+ stack?: string;
349
+ }
350
+
351
+ declare interface ExceptionWithMessage {
352
+ code?: string | number;
353
+ message: string;
354
+ name?: string;
355
+ stack?: string;
356
+ }
357
+
358
+ declare interface ExceptionWithName {
359
+ code?: string | number;
360
+ message?: string;
361
+ name: string;
362
+ stack?: string;
363
+ }
364
+
321
365
  declare type FeedbackMessage = {
322
366
  type: MessageType.Feedback;
323
367
  verbatim: string;
@@ -622,6 +666,33 @@ declare type Hook = Omit<Hook_2, 'afterEvaluation'> & {
622
666
  }): EvaluationSeriesData;
623
667
  };
624
668
 
669
+ /**
670
+ * Defines High-Resolution Time.
671
+ *
672
+ * The first number, HrTime[0], is UNIX Epoch time in seconds since 00:00:00 UTC on 1 January 1970.
673
+ * The second number, HrTime[1], represents the partial second elapsed since Unix Epoch time represented by first number in nanoseconds.
674
+ * For example, 2021-01-01T12:30:10.150Z in UNIX Epoch time in milliseconds is represented as 1609504210150.
675
+ * The first number is calculated by converting and truncating the Epoch time in milliseconds to seconds:
676
+ * HrTime[0] = Math.trunc(1609504210150 / 1000) = 1609504210.
677
+ * The second number is calculated by converting the digits after the decimal point of the subtraction, (1609504210150 / 1000) - HrTime[0], to nanoseconds:
678
+ * HrTime[1] = Number((1609504210.150 - HrTime[0]).toFixed(9)) * 1e9 = 150000000.
679
+ * This is represented in HrTime format as [1609504210, 150000000].
680
+ */
681
+ declare type HrTime = [number, number];
682
+
683
+ /**
684
+ * Describes the request behind an auto-instrumented browser `fetch` or
685
+ * `XMLHttpRequest` span.
686
+ */
687
+ declare type HttpSpanRequest = {
688
+ /** Which instrumentation created the span. */
689
+ type: 'fetch' | 'xhr';
690
+ /** Upper-cased HTTP method, e.g. `GET`. */
691
+ method: string;
692
+ /** The concrete request URL, e.g. `https://app.example.com/api/users/42`. */
693
+ url: string;
694
+ };
695
+
625
696
  declare type IdentifyMessage = {
626
697
  type: MessageType.Identify;
627
698
  userIdentifier: string;
@@ -705,6 +776,30 @@ declare interface LDPlugin {
705
776
  getHooks?(metadata: LDPluginEnvironmentMetadata): Hook[];
706
777
  }
707
778
 
779
+ /**
780
+ * A pointer from the current {@link Span} to another span in the same trace or
781
+ * in a different trace.
782
+ * Few examples of Link usage.
783
+ * 1. Batch Processing: A batch of elements may contain elements associated
784
+ * with one or more traces/spans. Since there can only be one parent
785
+ * SpanContext, Link is used to keep reference to SpanContext of all
786
+ * elements in the batch.
787
+ * 2. Public Endpoint: A SpanContext in incoming client request on a public
788
+ * endpoint is untrusted from service provider perspective. In such case it
789
+ * is advisable to start a new trace with appropriate sampling decision.
790
+ * However, it is desirable to associate incoming SpanContext to new trace
791
+ * initiated on service provider side so two traces (from Client and from
792
+ * Service Provider) can be correlated.
793
+ */
794
+ declare interface Link {
795
+ /** The {@link SpanContext} of a linked span. */
796
+ context: SpanContext;
797
+ /** A set of {@link SpanAttributes} on the link. */
798
+ attributes?: SpanAttributes;
799
+ /** Count of attributes of the link that were dropped due to collection limits */
800
+ droppedAttributesCount?: number;
801
+ }
802
+
708
803
  declare type listenerHandler = () => void;
709
804
 
710
805
  declare type loadedEvent = {
@@ -1094,6 +1189,55 @@ declare type ObserveOptions = CommonOptions & {
1094
1189
  * @default 2000
1095
1190
  */
1096
1191
  flagExposureDedupeMaxSize?: number;
1192
+ /**
1193
+ * Query parameters to read from the page URL and add as attributes to all
1194
+ * telemetry, as if passed to `LDObserve.setAttributes`.
1195
+ *
1196
+ * When the SDK initializes, each listed parameter present in
1197
+ * `location.search` becomes an attribute named after the parameter (e.g.
1198
+ * `utm_campaign`) on every span (including document load, page view and
1199
+ * fetch/XHR spans), log, error and metric for the rest of the page load,
1200
+ * including after SPA navigation drops it from the URL.
1201
+ *
1202
+ * Last touch: when an SPA navigation lands on a URL with any listed
1203
+ * parameter, the captured values are replaced by that URL's values, and
1204
+ * previously captured keys missing from it are removed, so the set always
1205
+ * reflects one landing. A navigation without listed parameters keeps the
1206
+ * current values. Spans already started keep the values they had.
1207
+ *
1208
+ * Values are kept in memory only; nothing is written to storage or
1209
+ * cookies, so a later full page load captures again from its own URL.
1210
+ *
1211
+ * Only the listed keys are captured, so other query parameters (which may
1212
+ * hold personal data such as emails or tokens) are never recorded this
1213
+ * way. The default list contains UTM parameters only. A name ending in `*`
1214
+ * matches every parameter with that prefix (e.g. `'utm_*'`).
1215
+ *
1216
+ * Keys set with `setAttributes` win: capture never replaces or removes a
1217
+ * key the app set itself. `removeAttributes` removes a captured value
1218
+ * (a later landing with that parameter captures it again). Keys in the
1219
+ * namespaces the SDK sets itself (`highlight.*`, `launchdarkly.*`,
1220
+ * `session.*`, `context.contextKeys.*`) are ignored.
1221
+ *
1222
+ * A custom list replaces the default. Set to `false` or `[]` to turn
1223
+ * capture off.
1224
+ * @default ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']
1225
+ * @example captureQueryParams: ['utm_source', 'utm_campaign', 'gclid']
1226
+ */
1227
+ captureQueryParams?: string[] | false;
1228
+ /**
1229
+ * Specifies whether to record the page that linked to this one. When the
1230
+ * SDK initializes and `document.referrer` is a different origin, it is
1231
+ * added as the `landing.referrer` attribute to all telemetry for the rest
1232
+ * of the page load, as if passed to `LDObserve.setAttributes`.
1233
+ *
1234
+ * Only the origin and path are kept: the query string, fragment and any
1235
+ * credentials are stripped so tokens or personal data in the referrer URL
1236
+ * are not recorded. An empty or same-origin referrer sets nothing, and
1237
+ * the value is not updated on SPA navigation.
1238
+ * @default true
1239
+ */
1240
+ captureReferrer?: boolean;
1097
1241
  };
1098
1242
 
1099
1243
  declare type OtelInstrumentatonOptions = {
@@ -1105,6 +1249,32 @@ declare type OtelInstrumentatonOptions = {
1105
1249
 
1106
1250
  declare type OtelOptions = {
1107
1251
  instrumentations?: OtelInstrumentatonOptions;
1252
+ /**
1253
+ * Called for each auto-instrumented `fetch` and `XMLHttpRequest` span just
1254
+ * before it ends, so the response and error status are already on it.
1255
+ * Use it to rename the span or add attributes, for example to give it a
1256
+ * route template:
1257
+ *
1258
+ * ```ts
1259
+ * onHttpRequestSpan: (span, { method, url }) => {
1260
+ * const route = matchRoute(url) // '/api/users/{userId}'
1261
+ * if (!route) return
1262
+ * span.updateName(`${method} ${route}`)
1263
+ * span.setAttributes({
1264
+ * 'http.route': route,
1265
+ * 'url.template': route,
1266
+ * 'launchdarkly.operation.name': route,
1267
+ * })
1268
+ * }
1269
+ * ```
1270
+ *
1271
+ * The span's trace and span ids are fixed when the request starts, so
1272
+ * renaming does not affect the `traceparent` sent to your backend.
1273
+ * Errors thrown by the callback are swallowed. Requires
1274
+ * `networkRecording` to be enabled, as the instrumentations are not
1275
+ * installed otherwise.
1276
+ */
1277
+ onHttpRequestSpan?: (span: Span, request: HttpSpanRequest) => void;
1108
1278
  };
1109
1279
 
1110
1280
  declare class Plugin_2<T extends RecordOptions | ObserveOptions> {
@@ -1408,6 +1578,7 @@ declare class RecordSDK implements Record_3 {
1408
1578
  _isCrossOriginIframe: boolean;
1409
1579
  _eventBytesSinceSnapshot: number;
1410
1580
  _lastSnapshotTime: number;
1581
+ _snapshotPayloadIds: Set<number>;
1411
1582
  _lastVisibilityChangeTime: number;
1412
1583
  pushPayloadTimerId: ReturnType<typeof setTimeout> | undefined;
1413
1584
  hasSessionUnloaded: boolean;
@@ -1682,6 +1853,208 @@ declare type SessionShortcutOptions = false | string;
1682
1853
 
1683
1854
  declare type Source = 'segment' | 'LaunchDarkly' | undefined;
1684
1855
 
1856
+ /**
1857
+ * An interface that represents a span. A span represents a single operation
1858
+ * within a trace. Examples of span might include remote procedure calls or a
1859
+ * in-process function calls to sub-components. A Trace has a single, top-level
1860
+ * "root" Span that in turn may have zero or more child Spans, which in turn
1861
+ * may have children.
1862
+ *
1863
+ * Spans are created by the {@link Tracer.startSpan} method.
1864
+ */
1865
+ declare interface Span {
1866
+ /**
1867
+ * Returns the {@link SpanContext} object associated with this Span.
1868
+ *
1869
+ * Get an immutable, serializable identifier for this span that can be used
1870
+ * to create new child spans. Returned SpanContext is usable even after the
1871
+ * span ends.
1872
+ *
1873
+ * @returns the SpanContext object associated with this Span.
1874
+ */
1875
+ spanContext(): SpanContext;
1876
+ /**
1877
+ * Sets an attribute to the span.
1878
+ *
1879
+ * Sets a single Attribute with the key and value passed as arguments.
1880
+ *
1881
+ * @param key the key for this attribute.
1882
+ * @param value the value for this attribute. Setting a value null or
1883
+ * undefined is invalid and will result in undefined behavior.
1884
+ */
1885
+ setAttribute(key: string, value: SpanAttributeValue): this;
1886
+ /**
1887
+ * Sets attributes to the span.
1888
+ *
1889
+ * @param attributes the attributes that will be added.
1890
+ * null or undefined attribute values
1891
+ * are invalid and will result in undefined behavior.
1892
+ */
1893
+ setAttributes(attributes: SpanAttributes): this;
1894
+ /**
1895
+ * Adds an event to the Span.
1896
+ *
1897
+ * @param name the name of the event.
1898
+ * @param [attributesOrStartTime] the attributes that will be added; these are
1899
+ * associated with this event. Can be also a start time
1900
+ * if type is {@type TimeInput} and 3rd param is undefined
1901
+ * @param [startTime] start time of the event.
1902
+ */
1903
+ addEvent(name: string, attributesOrStartTime?: SpanAttributes | TimeInput, startTime?: TimeInput): this;
1904
+ /**
1905
+ * Adds a single link to the span.
1906
+ *
1907
+ * Links added after the creation will not affect the sampling decision.
1908
+ * It is preferred span links be added at span creation.
1909
+ *
1910
+ * @param link the link to add.
1911
+ */
1912
+ addLink(link: Link): this;
1913
+ /**
1914
+ * Adds multiple links to the span.
1915
+ *
1916
+ * Links added after the creation will not affect the sampling decision.
1917
+ * It is preferred span links be added at span creation.
1918
+ *
1919
+ * @param links the links to add.
1920
+ */
1921
+ addLinks(links: Link[]): this;
1922
+ /**
1923
+ * Sets a status to the span. If used, this will override the default Span
1924
+ * status. Default is {@link SpanStatusCode.UNSET}. SetStatus overrides the value
1925
+ * of previous calls to SetStatus on the Span.
1926
+ *
1927
+ * @param status the SpanStatus to set.
1928
+ */
1929
+ setStatus(status: SpanStatus): this;
1930
+ /**
1931
+ * Updates the Span name.
1932
+ *
1933
+ * This will override the name provided via {@link Tracer.startSpan}.
1934
+ *
1935
+ * Upon this update, any sampling behavior based on Span name will depend on
1936
+ * the implementation.
1937
+ *
1938
+ * @param name the Span name.
1939
+ */
1940
+ updateName(name: string): this;
1941
+ /**
1942
+ * Marks the end of Span execution.
1943
+ *
1944
+ * Call to End of a Span MUST not have any effects on child spans. Those may
1945
+ * still be running and can be ended later.
1946
+ *
1947
+ * Do not return `this`. The Span generally should not be used after it
1948
+ * is ended so chaining is not desired in this context.
1949
+ *
1950
+ * @param [endTime] the time to set as Span's end time. If not provided,
1951
+ * use the current time as the span's end time.
1952
+ */
1953
+ end(endTime?: TimeInput): void;
1954
+ /**
1955
+ * Returns the flag whether this span will be recorded.
1956
+ *
1957
+ * @returns true if this Span is active and recording information like events
1958
+ * with the `AddEvent` operation and attributes using `setAttributes`.
1959
+ */
1960
+ isRecording(): boolean;
1961
+ /**
1962
+ * Sets exception as a span event
1963
+ * @param exception the exception the only accepted values are string or Error
1964
+ * @param [time] the time to set as Span's event time. If not provided,
1965
+ * use the current time.
1966
+ */
1967
+ recordException(exception: Exception, time?: TimeInput): void;
1968
+ }
1969
+
1970
+ /**
1971
+ * @deprecated please use {@link Attributes}
1972
+ */
1973
+ declare type SpanAttributes = Attributes;
1974
+
1975
+ /**
1976
+ * @deprecated please use {@link AttributeValue}
1977
+ */
1978
+ declare type SpanAttributeValue = AttributeValue;
1979
+
1980
+ /**
1981
+ * A SpanContext represents the portion of a {@link Span} which must be
1982
+ * serialized and propagated along side of a {@link Baggage}.
1983
+ */
1984
+ declare interface SpanContext {
1985
+ /**
1986
+ * The ID of the trace that this span belongs to. It is worldwide unique
1987
+ * with practically sufficient probability by being made as 16 randomly
1988
+ * generated bytes, encoded as a 32 lowercase hex characters corresponding to
1989
+ * 128 bits.
1990
+ */
1991
+ traceId: string;
1992
+ /**
1993
+ * The ID of the Span. It is globally unique with practically sufficient
1994
+ * probability by being made as 8 randomly generated bytes, encoded as a 16
1995
+ * lowercase hex characters corresponding to 64 bits.
1996
+ */
1997
+ spanId: string;
1998
+ /**
1999
+ * Only true if the SpanContext was propagated from a remote parent.
2000
+ */
2001
+ isRemote?: boolean;
2002
+ /**
2003
+ * Trace flags to propagate.
2004
+ *
2005
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
2006
+ * sampled or not. When set, the least significant bit documents that the
2007
+ * caller may have recorded trace data. A caller who does not record trace
2008
+ * data out-of-band leaves this flag unset.
2009
+ *
2010
+ * see {@link TraceFlags} for valid flag values.
2011
+ */
2012
+ traceFlags: number;
2013
+ /**
2014
+ * Tracing-system-specific info to propagate.
2015
+ *
2016
+ * The tracestate field value is a `list` as defined below. The `list` is a
2017
+ * series of `list-members` separated by commas `,`, and a list-member is a
2018
+ * key/value pair separated by an equals sign `=`. Spaces and horizontal tabs
2019
+ * surrounding `list-members` are ignored. There can be a maximum of 32
2020
+ * `list-members` in a `list`.
2021
+ * More Info: https://www.w3.org/TR/trace-context/#tracestate-field
2022
+ *
2023
+ * Examples:
2024
+ * Single tracing system (generic format):
2025
+ * tracestate: rojo=00f067aa0ba902b7
2026
+ * Multiple tracing systems (with different formatting):
2027
+ * tracestate: rojo=00f067aa0ba902b7,congo=t61rcWkgMzE
2028
+ */
2029
+ traceState?: TraceState;
2030
+ }
2031
+
2032
+ declare interface SpanStatus {
2033
+ /** The status code of this message. */
2034
+ code: SpanStatusCode;
2035
+ /** A developer-facing error message. */
2036
+ message?: string;
2037
+ }
2038
+
2039
+ /**
2040
+ * An enumeration of status codes.
2041
+ */
2042
+ declare enum SpanStatusCode {
2043
+ /**
2044
+ * The default status.
2045
+ */
2046
+ UNSET = 0,
2047
+ /**
2048
+ * The operation has been validated by an Application developer or
2049
+ * Operator to have completed successfully.
2050
+ */
2051
+ OK = 1,
2052
+ /**
2053
+ * The operation contains an error.
2054
+ */
2055
+ ERROR = 2
2056
+ }
2057
+
1685
2058
  declare interface StartOptions {
1686
2059
  /**
1687
2060
  * Specifies whether console warn messages should not be created.
@@ -1768,6 +2141,51 @@ declare type textNode = {
1768
2141
  isStyle?: true;
1769
2142
  };
1770
2143
 
2144
+ /**
2145
+ * Defines TimeInput.
2146
+ *
2147
+ * hrtime, epoch milliseconds, performance.now() or Date
2148
+ */
2149
+ declare type TimeInput = HrTime | number | Date;
2150
+
2151
+ declare interface TraceState {
2152
+ /**
2153
+ * Create a new TraceState which inherits from this TraceState and has the
2154
+ * given key set.
2155
+ * The new entry will always be added in the front of the list of states.
2156
+ *
2157
+ * @param key key of the TraceState entry.
2158
+ * @param value value of the TraceState entry.
2159
+ */
2160
+ set(key: string, value: string): TraceState;
2161
+ /**
2162
+ * Return a new TraceState which inherits from this TraceState but does not
2163
+ * contain the given key.
2164
+ *
2165
+ * @param key the key for the TraceState entry to be removed.
2166
+ */
2167
+ unset(key: string): TraceState;
2168
+ /**
2169
+ * Returns the value to which the specified key is mapped, or `undefined` if
2170
+ * this map contains no mapping for the key.
2171
+ *
2172
+ * @param key with which the specified value is to be associated.
2173
+ * @returns the value to which the specified key is mapped, or `undefined` if
2174
+ * this map contains no mapping for the key.
2175
+ */
2176
+ get(key: string): string | undefined;
2177
+ /**
2178
+ * Serializes the TraceState to a `list` as defined below. The `list` is a
2179
+ * series of `list-members` separated by commas `,`, and a list-member is a
2180
+ * key/value pair separated by an equals sign `=`. Spaces and horizontal tabs
2181
+ * surrounding `list-members` are ignored. There can be a maximum of 32
2182
+ * `list-members` in a `list`.
2183
+ *
2184
+ * @returns the serialized string.
2185
+ */
2186
+ serialize(): string;
2187
+ }
2188
+
1771
2189
  declare type viewportResizeData = {
1772
2190
  source: IncrementalSource.ViewportResize;
1773
2191
  } & viewportResizeDimension;
package/dist/record.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./common-D8kkCWo3.js";
2
- import { R as i } from "./record-DG2IcHxO.js";
1
+ import "./common-C6gSg2Rq.js";
2
+ import { R as i } from "./record-BpTfYU5r.js";
3
3
  import "./LDRecord.js";
4
4
  import "./buffer-CwCRPuMA.js";
5
5
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@launchdarkly/o11y",
3
- "version": "1.4.1",
3
+ "version": "1.6.0",
4
4
  "description": "Shared browser foundation for @launchdarkly/observability and @launchdarkly/session-replay. Capture frontend metrics, errors, logs, traces, and session replays.",
5
5
  "keywords": [
6
6
  "launchdarkly",
@@ -1,130 +0,0 @@
1
- var i = (e, r, t) => new Promise((a, s) => {
2
- var n = (o) => {
3
- try {
4
- l(t.next(o));
5
- } catch (d) {
6
- s(d);
7
- }
8
- }, b = (o) => {
9
- try {
10
- l(t.throw(o));
11
- } catch (d) {
12
- s(d);
13
- }
14
- }, l = (o) => o.done ? a(o.value) : Promise.resolve(o.value).then(n, b);
15
- l((t = t.apply(e, r)).next());
16
- });
17
- import { B as _, d as h } from "./buffer-CwCRPuMA.js";
18
- const f = () => {
19
- const e = {
20
- end: () => {
21
- },
22
- spanContext: () => ({
23
- traceId: "",
24
- spanId: "",
25
- traceFlags: 0
26
- }),
27
- setAttribute: (r, t) => e,
28
- setAttributes: (r) => e,
29
- addEvent: (r, t, a) => e,
30
- addLinks: (r) => e,
31
- setStatus: (r) => e,
32
- recordException: () => {
33
- },
34
- addLink: () => e,
35
- updateName: () => e,
36
- isRecording: () => !1
37
- };
38
- return e;
39
- };
40
- function c(e, r, t) {
41
- if (typeof t == "function")
42
- return t;
43
- if (typeof r == "function")
44
- return r;
45
- if (typeof e == "function")
46
- return e;
47
- }
48
- class p extends _ {
49
- _startSdk() {
50
- return i(this, null, function* () {
51
- yield this._sdk.start();
52
- });
53
- }
54
- // Never buffered: with `manualStart`, `start()` may run before the plugin
55
- // has attached an SDK. It then stays pending and resolves once `load`
56
- // attaches and starts the SDK.
57
- start() {
58
- return i(this, null, function* () {
59
- return this._start();
60
- });
61
- }
62
- // Never buffered, and never throws: before an SDK is attached it just
63
- // cancels a start that has not run yet.
64
- stop() {
65
- return i(this, null, function* () {
66
- yield this._stop(() => this._sdk.stop());
67
- });
68
- }
69
- recordGauge(r) {
70
- return this._bufferCall("recordGauge", [r]);
71
- }
72
- recordCount(r) {
73
- return this._bufferCall("recordCount", [r]);
74
- }
75
- recordIncr(r) {
76
- return this._bufferCall("recordIncr", [r]);
77
- }
78
- recordHistogram(r) {
79
- return this._bufferCall("recordHistogram", [r]);
80
- }
81
- recordUpDownCounter(r) {
82
- return this._bufferCall("recordUpDownCounter", [r]);
83
- }
84
- // The callback holds the caller's own work, so it must never be buffered:
85
- // deferring it would replay that work at an arbitrary later time, or drop it.
86
- startSpan(r, t, a, s) {
87
- var n;
88
- return this._isReady ? this._bufferCall("startSpan", [r, t, a, s]) : (this._logNoopSpanWarning(), (n = c(t, a, s)) == null ? void 0 : n(f()));
89
- }
90
- startManualSpan(r, t, a, s) {
91
- var n;
92
- return this._isReady ? this._bufferCall("startManualSpan", [r, t, a, s]) : (this._logNoopSpanWarning(), (n = c(t, a, s)) == null ? void 0 : n(f()));
93
- }
94
- _logNoopSpanWarning() {
95
- h(
96
- "startSpan/startManualSpan called before start()",
97
- "span-before-start",
98
- "warn",
99
- "The span callback runs on a no-op span and the span is not recorded."
100
- );
101
- }
102
- register(r, t) {
103
- return this._bufferCall("register", [r, t]);
104
- }
105
- recordLog(r, t, a) {
106
- return this._bufferCall("recordLog", [r, t, a]);
107
- }
108
- recordError(r, t, a, s, n) {
109
- return this._bufferCall("recordError", [
110
- r,
111
- t,
112
- a,
113
- s,
114
- n
115
- ]);
116
- }
117
- setLDContextKeyAttributes(r) {
118
- return this._bufferCall("setLDContextKeyAttributes", [r]);
119
- }
120
- getLDContextKeyAttributes() {
121
- return this._isLoaded ? this._callSdk("getLDContextKeyAttributes", []) : void 0;
122
- }
123
- }
124
- let u;
125
- typeof globalThis != "undefined" ? globalThis.LDObserve ? u = globalThis.LDObserve : (u = new p(), globalThis.LDObserve = u) : u = new p();
126
- export {
127
- u as L,
128
- f as g
129
- };
130
- //# sourceMappingURL=LDObserve-BQr7RYVC.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LDObserve-BQr7RYVC.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 { Attributes, Context, Span, SpanOptions } from '@opentelemetry/api'\nimport type { LDPluginEnvironmentMetadata } from '../plugins/plugin'\nimport { BufferedClass } 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\nclass _LDObserve extends BufferedClass<Observe> implements Observe {\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\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","_LDObserve","BufferedClass","__async","metric","name","_a","internalLogOnce","client","environmentMetadata","message","level","metadata","error","payload","source","type","contextKeys","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,IAC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