@launchdarkly/o11y 1.3.0 → 1.3.1

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.
@@ -0,0 +1,124 @@
1
+ var f = Object.defineProperty;
2
+ var g = (s, e, t) => e in s ? f(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var r = (s, e, t) => g(s, typeof e != "symbol" ? e + "" : e, t);
4
+ const c = {}, p = [
5
+ "debug",
6
+ "log",
7
+ "info",
8
+ "warn",
9
+ "error"
10
+ ], l = Symbol.for("@launchdarkly/o11y.sdkLogger"), h = (() => {
11
+ try {
12
+ return (c == null ? void 0 : c.DEBUG) === "true";
13
+ } catch (s) {
14
+ return !1;
15
+ }
16
+ })(), a = (() => {
17
+ var t;
18
+ const s = globalThis, e = (t = s[l]) != null ? t : s[l] = {
19
+ debugEnabled: !1,
20
+ suppressDepth: 0
21
+ };
22
+ return h && (e.debugEnabled = !0), e;
23
+ })(), x = (s) => {
24
+ a.debugEnabled = s;
25
+ }, b = () => a.debugEnabled, E = () => a.suppressDepth > 0, i = (s) => {
26
+ a.suppressDepth++;
27
+ try {
28
+ return s();
29
+ } finally {
30
+ a.suppressDepth--;
31
+ }
32
+ }, y = (s) => p.includes(s) ? s : "log", _ = (s, ...e) => {
33
+ a.debugEnabled && i(() => {
34
+ var t;
35
+ try {
36
+ ((t = console[y(s)]) != null ? t : console.log).apply(console, e);
37
+ } catch (o) {
38
+ }
39
+ });
40
+ }, d = /* @__PURE__ */ Object.create(null), n = (s, e, ...t) => {
41
+ const o = `[@launchdarkly plugins]: (${s}): `;
42
+ _(e, o, ...t);
43
+ }, D = (s, e, t, ...o) => {
44
+ d[`${s}-${e}`] || (d[`${s}-${e}`] = !0, n(s, t, ...o));
45
+ };
46
+ class L {
47
+ constructor(e, t) {
48
+ r(this, "debug");
49
+ r(this, "name");
50
+ this.debug = e, this.name = t;
51
+ }
52
+ prefix() {
53
+ let e = `[${Date.now()}]`;
54
+ return this.name && (e += ` - ${this.name}`), e;
55
+ }
56
+ log(...e) {
57
+ this.debug && i(
58
+ () => console.log.apply(console, [this.prefix(), ...e])
59
+ );
60
+ }
61
+ warn(...e) {
62
+ (this.debug || b()) && i(
63
+ () => console.warn.apply(console, [this.prefix(), ...e])
64
+ );
65
+ }
66
+ }
67
+ class $ {
68
+ constructor() {
69
+ r(this, "_sdk");
70
+ r(this, "_isLoaded", !1);
71
+ r(this, "_callBuffer", []);
72
+ r(this, "_capacity", 1e5);
73
+ r(this, "_droppedEvents", 0);
74
+ r(this, "_exceededCapacity", !1);
75
+ r(this, "_logger", new L());
76
+ }
77
+ _bufferCall(e, t) {
78
+ if (this._isLoaded)
79
+ try {
80
+ return this._sdk[e](...t);
81
+ } catch (o) {
82
+ n(
83
+ `Error executing buffered call to ${e}:`,
84
+ "error",
85
+ o
86
+ );
87
+ }
88
+ else {
89
+ this._enqueue({ method: e, args: t });
90
+ return;
91
+ }
92
+ }
93
+ _enqueue(e) {
94
+ this._callBuffer.length < this._capacity ? (this._callBuffer.push(e), this._exceededCapacity = !1) : (this._exceededCapacity || (this._exceededCapacity = !0, n(
95
+ "Exceeded event queue capacity. Increase capacity to avoid dropping events.",
96
+ "warn"
97
+ )), this._droppedEvents += 1);
98
+ }
99
+ load(e) {
100
+ this._sdk = e, this._isLoaded = !0;
101
+ for (const { method: t, args: o } of this._callBuffer)
102
+ try {
103
+ this._sdk[t](...o);
104
+ } catch (u) {
105
+ n(
106
+ `Error executing buffered call to ${t}:`,
107
+ "error",
108
+ u
109
+ );
110
+ }
111
+ this._callBuffer = [];
112
+ }
113
+ }
114
+ export {
115
+ $ as B,
116
+ L,
117
+ _ as a,
118
+ E as b,
119
+ b as c,
120
+ D as d,
121
+ n as i,
122
+ x as s
123
+ };
124
+ //# sourceMappingURL=buffer-BjzLorpP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffer-BjzLorpP.js","sources":["../src/client/utils/sdkLogger.ts","../src/sdk/util.ts","../src/client/logger.ts","../src/sdk/buffer.ts"],"sourcesContent":["/**\n * SDK-internal diagnostics.\n *\n * Everything the SDK says about itself (exporter failures, init warnings,\n * internal catch blocks) goes through here rather than straight to `console`:\n *\n * 1. It only reaches the developer console when the SDK is in debug mode\n * (`debug: true` or a `DebugOptions` object in the plugin options, or a\n * `DEBUG=true` build). A production page is not filled with\n * `[@launchdarkly/observability]` lines the app owner cannot act on.\n * 2. While it is being written, the console recorder is told to stand down\n * (see `isSdkConsoleOutput`), so the line is never captured and shipped\n * back as one of the customer's own log records. Before this, a failing\n * OTLP export surfaced as error-level `launchdarkly.js.log` rows in the\n * customer's own project.\n */\n\nexport type SdkLogLevel = 'debug' | 'log' | 'info' | 'warn' | 'error'\n\nconst SDK_LOG_LEVELS: readonly SdkLogLevel[] = [\n\t'debug',\n\t'log',\n\t'info',\n\t'warn',\n\t'error',\n]\n\ntype SdkLoggerState = { debugEnabled: boolean; suppressDepth: number }\n\n/**\n * `@launchdarkly/observability` and `@launchdarkly/session-replay` each bundle\n * their own copy of this module, and the console recorder lives in only one\n * of them. A module-level counter would therefore not be seen across copies:\n * session replay's diagnostics would be recorded by the observability\n * plugin's console recorder (and the bundler drops the counter entirely in a\n * copy that never reads it). Keep the state on the global object under a\n * registry symbol so every copy on the page shares it.\n */\nconst SDK_LOGGER_STATE_KEY = Symbol.for('@launchdarkly/o11y.sdkLogger')\n\nconst buildDebugEnabled = (() => {\n\ttry {\n\t\treturn import.meta.env?.DEBUG === 'true'\n\t} catch {\n\t\treturn false\n\t}\n})()\n\nconst state: SdkLoggerState = (() => {\n\tconst holder = globalThis as unknown as Record<symbol, SdkLoggerState>\n\tconst shared = (holder[SDK_LOGGER_STATE_KEY] ??= {\n\t\tdebugEnabled: false,\n\t\tsuppressDepth: 0,\n\t})\n\tif (buildDebugEnabled) {\n\t\tshared.debugEnabled = true\n\t}\n\treturn shared\n})()\n\n/**\n * Turns SDK-internal console diagnostics on or off. Called by the SDK entry\n * points when the `debug` option is set; tests may call it directly.\n */\nexport const setSdkDebugLogging = (enabled: boolean) => {\n\tstate.debugEnabled = enabled\n}\n\nexport const isSdkDebugLogging = () => state.debugEnabled\n\n/**\n * True while the SDK itself is writing to the console. The console recorder\n * checks this and skips the call so SDK diagnostics never become customer\n * log records, in any mode.\n */\nexport const isSdkConsoleOutput = () => state.suppressDepth > 0\n\n/**\n * Runs `fn` with console recording suspended. Console patches are\n * synchronous, so a depth counter is enough to scope the suspension.\n */\nexport const withoutConsoleRecording = <T>(fn: () => T): T => {\n\tstate.suppressDepth++\n\ttry {\n\t\treturn fn()\n\t} finally {\n\t\tstate.suppressDepth--\n\t}\n}\n\nconst toSdkLogLevel = (level: string): SdkLogLevel =>\n\t(SDK_LOG_LEVELS as readonly string[]).includes(level)\n\t\t? (level as SdkLogLevel)\n\t\t: 'log'\n\n/**\n * Writes an SDK-internal diagnostic to the console, but only in debug mode,\n * and never into the console recorder.\n */\nexport const sdkLog = (level: SdkLogLevel | string, ...args: unknown[]) => {\n\tif (!state.debugEnabled) {\n\t\treturn\n\t}\n\twithoutConsoleRecording(() => {\n\t\ttry {\n\t\t\tconst method = console[toSdkLogLevel(level)] ?? console.log\n\t\t\tmethod.apply(console, args)\n\t\t} catch {\n\t\t\t// a broken console must never break the SDK\n\t\t}\n\t})\n}\n","import { sdkLog } from '../client/utils/sdkLogger'\n\n// Object for tracking previously logged messages.\nconst loggedIds = Object.create(null)\n\n/**\n * SDK-internal diagnostic. Reaches the developer console only in debug mode\n * and is never recorded as one of the customer's log records (it used to be\n * both printed unconditionally and shipped as a `warn` log into the\n * customer's project).\n */\nexport const internalLog = (\n\tcontext: string,\n\tlevel: keyof Console,\n\t...msg: any\n) => {\n\tconst prefix = `[@launchdarkly plugins]: (${context}): `\n\tsdkLog(level as string, prefix, ...msg)\n}\n\n/**\n * Utility to help avoid logging the same message multiple times.\n *\n * This is helpful to prevent spamming the logs with sticky error conditions.\n * For example if local storage cannot be written to, then each attempt to\n * write would fail, and logging each time would spam the logs.\n *\n * @param logOnceId - A message with this ID will only be logged one time for the given context.\n * @param context - The context of the message.\n * @param level - The level of the message.\n * @param msg - The message to log.\n */\nexport const internalLogOnce = (\n\tcontext: string,\n\tlogOnceId: string,\n\tlevel: keyof Console,\n\t...msg: any\n) => {\n\tif (loggedIds[`${context}-${logOnceId}`]) {\n\t\treturn\n\t}\n\tloggedIds[`${context}-${logOnceId}`] = true\n\tinternalLog(context, level, ...msg)\n}\n","import { isSdkDebugLogging, withoutConsoleRecording } from './utils/sdkLogger'\n\n/**\n * Per-component debug logger. Like `sdkLog`, its output is SDK-internal: it\n * is written only in debug mode and never captured by the console recorder.\n */\nexport class Logger {\n\tdebug: boolean | undefined\n\tname: string | undefined\n\n\tconstructor(debug?: boolean, name?: string) {\n\t\tthis.debug = debug\n\t\tthis.name = name\n\t}\n\n\tprivate prefix() {\n\t\tlet prefix = `[${Date.now()}]`\n\t\tif (this.name) {\n\t\t\tprefix += ` - ${this.name}`\n\t\t}\n\t\treturn prefix\n\t}\n\n\tlog(...data: any[]) {\n\t\tif (this.debug) {\n\t\t\twithoutConsoleRecording(() =>\n\t\t\t\tconsole.log.apply(console, [this.prefix(), ...data]),\n\t\t\t)\n\t\t}\n\t}\n\n\twarn(...data: any[]) {\n\t\tif (this.debug || isSdkDebugLogging()) {\n\t\t\twithoutConsoleRecording(() =>\n\t\t\t\tconsole.warn.apply(console, [this.prefix(), ...data]),\n\t\t\t)\n\t\t}\n\t}\n}\n","import { Logger } from '../client/logger'\nimport { internalLog } from './util'\n\ntype Event = { method: string; args: any[] }\n\nexport class BufferedClass<T extends object> {\n\tprotected _sdk!: T\n\tprotected _isLoaded = false\n\tprotected _callBuffer: Array<Event> = []\n\tprotected _capacity: number = 100_000\n\tprotected _droppedEvents: number = 0\n\tprotected _exceededCapacity: boolean = false\n\tprotected _logger = new Logger()\n\n\tprotected _bufferCall(method: string, args: any[]) {\n\t\tif (this._isLoaded) {\n\t\t\t// If already loaded, execute the method directly\n\t\t\ttry {\n\t\t\t\treturn (this._sdk as any)[method](...args)\n\t\t\t} catch (error) {\n\t\t\t\tinternalLog(\n\t\t\t\t\t`Error executing buffered call to ${method}:`,\n\t\t\t\t\t'error',\n\t\t\t\t\terror,\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\t// Otherwise buffer the call\n\t\t\tthis._enqueue({ method, args })\n\t\t\treturn undefined\n\t\t}\n\t}\n\n\tprotected _enqueue(event: Event) {\n\t\tif (this._callBuffer.length < this._capacity) {\n\t\t\tthis._callBuffer.push(event)\n\t\t\tthis._exceededCapacity = false\n\t\t} else {\n\t\t\tif (!this._exceededCapacity) {\n\t\t\t\tthis._exceededCapacity = true\n\t\t\t\tinternalLog(\n\t\t\t\t\t'Exceeded event queue capacity. Increase capacity to avoid dropping events.',\n\t\t\t\t\t'warn',\n\t\t\t\t)\n\t\t\t}\n\t\t\tthis._droppedEvents += 1\n\t\t}\n\t}\n\n\tload(sdk: T) {\n\t\tthis._sdk = sdk\n\t\tthis._isLoaded = true\n\n\t\t// Process buffered calls\n\t\tfor (const { method, args } of this._callBuffer) {\n\t\t\ttry {\n\t\t\t\t;(this._sdk as any)[method](...args)\n\t\t\t} catch (error) {\n\t\t\t\tinternalLog(\n\t\t\t\t\t`Error executing buffered call to ${method}:`,\n\t\t\t\t\t'error',\n\t\t\t\t\terror,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\t// Clear the buffer\n\t\tthis._callBuffer = []\n\t}\n}\n"],"names":["SDK_LOG_LEVELS","SDK_LOGGER_STATE_KEY","buildDebugEnabled","__vite_import_meta_env__","e","state","holder","shared","_a","setSdkDebugLogging","enabled","isSdkDebugLogging","isSdkConsoleOutput","withoutConsoleRecording","fn","toSdkLogLevel","level","sdkLog","args","loggedIds","internalLog","context","msg","prefix","internalLogOnce","logOnceId","Logger","debug","name","__publicField","data","BufferedClass","method","error","event","sdk"],"mappings":";;;cAmBMA,IAAyC;AAAA,EAC9C;AAAA,EACA;AAAA,E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