@lmnr-ai/lmnr 0.8.30 → 0.8.32
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/cli.cjs +20 -22
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +7 -9
- package/dist/cli.mjs.map +1 -1
- package/dist/{consts-ivIFfgfN.mjs → consts-3AfXaMBI.mjs} +1 -1
- package/dist/{consts-ivIFfgfN.mjs.map → consts-3AfXaMBI.mjs.map} +1 -1
- package/dist/{consts-Cx9iKRmq.cjs → consts-DV6_Ea-8.cjs} +1 -1
- package/dist/{consts-Cx9iKRmq.cjs.map → consts-DV6_Ea-8.cjs.map} +1 -1
- package/dist/{dist-Cyli7uVF.cjs → dist-CDaxruok.cjs} +580 -12
- package/dist/dist-CDaxruok.cjs.map +1 -0
- package/dist/{dist-DMgpr2Zn.mjs → dist-DwtZd9Jy.mjs} +337 -5
- package/dist/dist-DwtZd9Jy.mjs.map +1 -0
- package/dist/{evaluations-DLNweSzE.d.cts → evaluations-8E6Oxgoq.d.cts} +18 -5
- package/dist/{evaluations-fF1Y_olL.d.mts → evaluations-HtzF0xSN.d.mts} +18 -5
- package/dist/{file-utils-CHgYB_Ei.mjs → file-utils-CjQ2Zw9n.mjs} +3 -3
- package/dist/{file-utils-CHgYB_Ei.mjs.map → file-utils-CjQ2Zw9n.mjs.map} +1 -1
- package/dist/{file-utils-Cysp1Ym1.cjs → file-utils-DWqUwg2p.cjs} +12 -12
- package/dist/{file-utils-Cysp1Ym1.cjs.map → file-utils-DWqUwg2p.cjs.map} +1 -1
- package/dist/index.cjs +555 -502
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +108 -33
- package/dist/index.d.mts +108 -33
- package/dist/index.mjs +343 -290
- package/dist/index.mjs.map +1 -1
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.cjs +69 -69
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.cjs.map +1 -1
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.mjs +2 -2
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.mjs.map +1 -1
- package/package.json +7 -7
- package/dist/dist-Cyli7uVF.cjs.map +0 -1
- package/dist/dist-DMgpr2Zn.mjs.map +0 -1
- package/dist/utils-Bdv7YZH7.mjs +0 -337
- package/dist/utils-Bdv7YZH7.mjs.map +0 -1
- package/dist/utils-C_Pf3r64.cjs +0 -561
- package/dist/utils-C_Pf3r64.cjs.map +0 -1
- /package/dist/{chunk-hT5z_Zn9.mjs → rolldown-runtime-2rV9d50f.mjs} +0 -0
- /package/dist/{chunk-BN4qSVkS.cjs → rolldown-runtime-CVvi-lCc.cjs} +0 -0
|
@@ -1,17 +1,351 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-CVvi-lCc.cjs");
|
|
2
|
+
let _opentelemetry_api = require("@opentelemetry/api");
|
|
3
3
|
let dotenv = require("dotenv");
|
|
4
4
|
let path = require("path");
|
|
5
|
-
path =
|
|
5
|
+
let path$1 = require_rolldown_runtime.__toESM(path, 1);
|
|
6
|
+
path = require_rolldown_runtime.__toESM(path);
|
|
6
7
|
let pino = require("pino");
|
|
7
|
-
pino =
|
|
8
|
+
let pino$3 = require_rolldown_runtime.__toESM(pino, 1);
|
|
9
|
+
pino = require_rolldown_runtime.__toESM(pino);
|
|
8
10
|
let pino_pretty = require("pino-pretty");
|
|
11
|
+
let url = require("url");
|
|
9
12
|
let uuid = require("uuid");
|
|
13
|
+
//#region ../types/dist/index.mjs
|
|
14
|
+
/** Directory the debug-session file lives in, relative to the working dir. */
|
|
15
|
+
const DEBUG_SESSION_DIR = ".lmnr";
|
|
16
|
+
/** Filename of the debug-session file inside {@link DEBUG_SESSION_DIR}. */
|
|
17
|
+
const DEBUG_SESSION_FILE = "debug-session.json";
|
|
18
|
+
/**
|
|
19
|
+
* Tracing levels to conditionally disable tracing.
|
|
20
|
+
*
|
|
21
|
+
* OFF - No tracing is sent.
|
|
22
|
+
* META_ONLY - Only metadata is sent (e.g. tokens, costs, etc.).
|
|
23
|
+
* ALL - All data is sent.
|
|
24
|
+
*/
|
|
25
|
+
let TracingLevel = /* @__PURE__ */ function(TracingLevel) {
|
|
26
|
+
TracingLevel["OFF"] = "off";
|
|
27
|
+
TracingLevel["META_ONLY"] = "meta_only";
|
|
28
|
+
TracingLevel["ALL"] = "all";
|
|
29
|
+
return TracingLevel;
|
|
30
|
+
}({});
|
|
31
|
+
const errorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
32
|
+
//#endregion
|
|
10
33
|
//#region package.json
|
|
11
|
-
var version$1 = "0.8.
|
|
34
|
+
var version$1 = "0.8.32";
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/opentelemetry-lib/tracing/attributes.ts
|
|
37
|
+
const SPAN_INPUT = "lmnr.span.input";
|
|
38
|
+
const SPAN_OUTPUT = "lmnr.span.output";
|
|
39
|
+
const SPAN_TYPE = "lmnr.span.type";
|
|
40
|
+
const SPAN_PATH = "lmnr.span.path";
|
|
41
|
+
const SPAN_IDS_PATH = "lmnr.span.ids_path";
|
|
42
|
+
const PARENT_SPAN_PATH = "lmnr.span.parent_path";
|
|
43
|
+
const PARENT_SPAN_IDS_PATH = "lmnr.span.parent_ids_path";
|
|
44
|
+
const SPAN_INSTRUMENTATION_SOURCE = "lmnr.span.instrumentation_source";
|
|
45
|
+
const SPAN_SDK_VERSION = "lmnr.span.sdk_version";
|
|
46
|
+
const SPAN_LANGUAGE_VERSION = "lmnr.span.language_version";
|
|
47
|
+
const TRACE_HAS_BROWSER_SESSION = "lmnr.internal.has_browser_session";
|
|
48
|
+
const HUMAN_EVALUATOR_OPTIONS = "lmnr.span.human_evaluator_options";
|
|
49
|
+
const ASSOCIATION_PROPERTIES = "lmnr.association.properties";
|
|
50
|
+
const SESSION_ID = "lmnr.association.properties.session_id";
|
|
51
|
+
const USER_ID = "lmnr.association.properties.user_id";
|
|
52
|
+
const TRACE_TYPE = "lmnr.association.properties.trace_type";
|
|
53
|
+
const ASSOCIATION_PROPERTIES_OVERRIDES = { "span_type": SPAN_TYPE };
|
|
54
|
+
const LaminarAttributes = {
|
|
55
|
+
INPUT_TOKEN_COUNT: "gen_ai.usage.input_tokens",
|
|
56
|
+
OUTPUT_TOKEN_COUNT: "gen_ai.usage.output_tokens",
|
|
57
|
+
TOTAL_TOKEN_COUNT: "llm.usage.total_tokens",
|
|
58
|
+
PROVIDER: "gen_ai.system",
|
|
59
|
+
REQUEST_MODEL: "gen_ai.request.model",
|
|
60
|
+
RESPONSE_MODEL: "gen_ai.response.model",
|
|
61
|
+
INPUT_COST: "gen_ai.usage.input_cost",
|
|
62
|
+
OUTPUT_COST: "gen_ai.usage.output_cost",
|
|
63
|
+
TOTAL_COST: "gen_ai.usage.cost"
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/utils.ts
|
|
67
|
+
function initializeLogger$1(options) {
|
|
68
|
+
const colorize = options?.colorize ?? true;
|
|
69
|
+
const level = options?.level ?? process.env.LMNR_LOG_LEVEL?.toLowerCase()?.trim() ?? "info";
|
|
70
|
+
return (0, pino.default)({ level }, (0, pino_pretty.PinoPretty)({
|
|
71
|
+
colorize,
|
|
72
|
+
minimumLevel: level
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
const logger$5 = initializeLogger$1();
|
|
76
|
+
const isStringUUID$1 = (id) => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(id);
|
|
77
|
+
const NIL_UUID = "00000000-0000-0000-0000-000000000000";
|
|
78
|
+
const newUUID$1 = () => {
|
|
79
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
80
|
+
else return (0, uuid.v4)();
|
|
81
|
+
};
|
|
82
|
+
const normalizeOtelTraceId = (traceId) => {
|
|
83
|
+
let id = traceId.toLowerCase();
|
|
84
|
+
if (id.startsWith("0x")) id = id.slice(2);
|
|
85
|
+
return id.padStart(32, "0").slice(-32);
|
|
86
|
+
};
|
|
87
|
+
const normalizeOtelSpanId = (spanId) => {
|
|
88
|
+
let id = spanId.toLowerCase();
|
|
89
|
+
if (id.startsWith("0x")) id = id.slice(2);
|
|
90
|
+
return id.padStart(16, "0").slice(-16);
|
|
91
|
+
};
|
|
92
|
+
const otelSpanIdToUUID$1 = (spanId) => {
|
|
93
|
+
let id = spanId.toLowerCase();
|
|
94
|
+
if (id.startsWith("0x")) id = id.slice(2);
|
|
95
|
+
if (id.length !== 16) logger$5.warn(`Span ID ${spanId} is not 16 hex chars long. This is not a valid OpenTelemetry span ID.`);
|
|
96
|
+
if (!/^[0-9a-f]+$/.test(id)) {
|
|
97
|
+
logger$5.error(`Span ID ${spanId} is not a valid hex string. Generating a random UUID instead.`);
|
|
98
|
+
return newUUID$1();
|
|
99
|
+
}
|
|
100
|
+
return id.padStart(32, "0").replace(/^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/, "$1-$2-$3-$4-$5");
|
|
101
|
+
};
|
|
102
|
+
const otelTraceIdToUUID$1 = (traceId) => {
|
|
103
|
+
let id = traceId.toLowerCase();
|
|
104
|
+
if (id.startsWith("0x")) id = id.slice(2);
|
|
105
|
+
if (id.length !== 32) logger$5.warn(`Trace ID ${traceId} is not 32 hex chars long. This is not a valid OpenTelemetry trace ID.`);
|
|
106
|
+
if (!/^[0-9a-f]+$/.test(id)) {
|
|
107
|
+
logger$5.error(`Trace ID ${traceId} is not a valid hex string. Generating a random UUID instead.`);
|
|
108
|
+
return newUUID$1();
|
|
109
|
+
}
|
|
110
|
+
return id.replace(/^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/, "$1-$2-$3-$4-$5");
|
|
111
|
+
};
|
|
112
|
+
const uuidToOtelTraceId = (uuid$1) => uuid$1.replace(/-/g, "");
|
|
113
|
+
const uuidToOtelSpanId = (uuid$2) => uuid$2.replace(/-/g, "").slice(16);
|
|
114
|
+
/**
|
|
115
|
+
* This is a simple implementation of a semaphore to replicate
|
|
116
|
+
* the behavior of the `asyncio.Semaphore` in Python.
|
|
117
|
+
*/
|
|
118
|
+
var Semaphore = class {
|
|
119
|
+
constructor(value = 1) {
|
|
120
|
+
this._waiters = [];
|
|
121
|
+
if (value < 0) throw new Error("Semaphore value must be >= 0");
|
|
122
|
+
this._value = value;
|
|
123
|
+
this._waiters = [];
|
|
124
|
+
}
|
|
125
|
+
async acquire() {
|
|
126
|
+
if (this._value > 0) {
|
|
127
|
+
this._value--;
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
return new Promise((resolve) => {
|
|
131
|
+
this._waiters.push(resolve);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
release() {
|
|
135
|
+
if (this._waiters.length > 0) this._waiters.shift()?.();
|
|
136
|
+
else this._value++;
|
|
137
|
+
}
|
|
138
|
+
async using(fn) {
|
|
139
|
+
try {
|
|
140
|
+
await this.acquire();
|
|
141
|
+
return await fn();
|
|
142
|
+
} finally {
|
|
143
|
+
this.release();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const tryToOtelSpanContext = (spanContext) => {
|
|
148
|
+
if (typeof spanContext === "string") try {
|
|
149
|
+
return recordToOtelSpanContext(JSON.parse(spanContext));
|
|
150
|
+
} catch (e) {
|
|
151
|
+
throw new Error(`Failed to parse span context ${spanContext}. The string must be a json representation of a LaminarSpanContext.Error: ${errorMessage(e)}`);
|
|
152
|
+
}
|
|
153
|
+
else if (isRecord(spanContext)) return recordToOtelSpanContext(spanContext);
|
|
154
|
+
else if (typeof spanContext.traceId === "string" && typeof spanContext.spanId === "string" && spanContext.traceId.length === 32 && spanContext.spanId.length === 16) {
|
|
155
|
+
logger$5.warn("The span context is already an OpenTelemetry SpanContext. Returning it as is. Please use `LaminarSpanContext` objects instead.");
|
|
156
|
+
return spanContext;
|
|
157
|
+
} else throw new Error(`Invalid span context ${JSON.stringify(spanContext)}. Must be a LaminarSpanContext or its json representation.`);
|
|
158
|
+
};
|
|
159
|
+
const recordToOtelSpanContext = (record) => {
|
|
160
|
+
if (typeof record.spanId === "string" && typeof record.traceId === "string" || typeof record.span_id === "string" && typeof record.trace_id === "string") return {
|
|
161
|
+
spanId: uuidToOtelSpanId(record?.spanId ?? record?.["span_id"]),
|
|
162
|
+
traceId: uuidToOtelTraceId(record?.traceId ?? record?.["trace_id"]),
|
|
163
|
+
isRemote: record?.isRemote ?? record?.["is_remote"] ?? false,
|
|
164
|
+
traceFlags: record?.traceFlags ?? _opentelemetry_api.TraceFlags.SAMPLED
|
|
165
|
+
};
|
|
166
|
+
else throw new Error(`Invalid span context ${JSON.stringify(record)}. Must be a json representation of a LaminarSpanContext.`);
|
|
167
|
+
};
|
|
168
|
+
const isRecord = (value) => typeof value === "object" && !Array.isArray(value) && value !== null;
|
|
169
|
+
/**
|
|
170
|
+
* Deserialize a LaminarSpanContext from a string or record.
|
|
171
|
+
* Handles both camelCase and snake_case keys for cross-language compatibility.
|
|
172
|
+
*
|
|
173
|
+
* @param data - The data to deserialize (string or record)
|
|
174
|
+
* @returns The deserialized LaminarSpanContext
|
|
175
|
+
* @throws Error if the data is invalid
|
|
176
|
+
*/
|
|
177
|
+
const deserializeLaminarSpanContext = (data) => {
|
|
178
|
+
if (typeof data === "string") try {
|
|
179
|
+
return deserializeLaminarSpanContext(JSON.parse(data));
|
|
180
|
+
} catch (e) {
|
|
181
|
+
throw new Error(`Failed to parse LaminarSpanContext: ${errorMessage(e)}`);
|
|
182
|
+
}
|
|
183
|
+
if (!isRecord(data)) throw new Error("Invalid LaminarSpanContext: must be a string or object");
|
|
184
|
+
const traceId = data.traceId ?? data.trace_id;
|
|
185
|
+
const spanId = data.spanId ?? data.span_id;
|
|
186
|
+
const isRemote = data.isRemote ?? data.is_remote ?? false;
|
|
187
|
+
const spanPath = data.spanPath ?? data.span_path;
|
|
188
|
+
const spanIdsPath = data.spanIdsPath ?? data.span_ids_path;
|
|
189
|
+
const userId = data.userId ?? data.user_id;
|
|
190
|
+
const sessionId = data.sessionId ?? data.session_id;
|
|
191
|
+
const metadata = data.metadata;
|
|
192
|
+
const traceType = data.traceType ?? data.trace_type;
|
|
193
|
+
const tracingLevel = data.tracingLevel ?? data.tracing_level;
|
|
194
|
+
const debug = data.debug;
|
|
195
|
+
if (typeof traceId !== "string" || typeof spanId !== "string") throw new Error("Invalid LaminarSpanContext: traceId and spanId must be strings");
|
|
196
|
+
if (!isStringUUID$1(traceId) || !isStringUUID$1(spanId)) throw new Error("Invalid LaminarSpanContext: traceId and spanId must be valid UUIDs");
|
|
197
|
+
return {
|
|
198
|
+
traceId,
|
|
199
|
+
spanId,
|
|
200
|
+
isRemote: Boolean(isRemote),
|
|
201
|
+
spanPath: Array.isArray(spanPath) ? spanPath : void 0,
|
|
202
|
+
spanIdsPath: Array.isArray(spanIdsPath) ? spanIdsPath : void 0,
|
|
203
|
+
userId,
|
|
204
|
+
sessionId,
|
|
205
|
+
metadata,
|
|
206
|
+
traceType,
|
|
207
|
+
tracingLevel,
|
|
208
|
+
debug: isRecord(debug) ? deserializeDebugContext(debug) : void 0
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Normalize a value to a canonical lowercase UUID string, or undefined.
|
|
213
|
+
*
|
|
214
|
+
* The debug block's `sessionId` / `replayTraceId` are always full ids; a value
|
|
215
|
+
* that isn't UUID-shaped is dropped (treated as absent) rather than thrown, so
|
|
216
|
+
* a partially-broken block never breaks span-context parsing.
|
|
217
|
+
*/
|
|
218
|
+
const asString = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
|
|
219
|
+
/**
|
|
220
|
+
* Parse a debug block, accepting camelCase and snake_case. All ids are kept
|
|
221
|
+
* VERBATIM: the producer emits the run's exact session / replay-trace /
|
|
222
|
+
* cache-until strings (un-normalized — `LMNR_DEBUG_SESSION_ID` may be an
|
|
223
|
+
* arbitrary non-UUID value), so the consumer must round-trip them unchanged or
|
|
224
|
+
* a downstream run never joins the run. Keep line-comparable with the Python
|
|
225
|
+
* `DebugContext.deserialize`.
|
|
226
|
+
*/
|
|
227
|
+
const deserializeDebugContext = (data) => ({
|
|
228
|
+
enabled: data.enabled === true,
|
|
229
|
+
sessionId: asString(data.sessionId ?? data.session_id),
|
|
230
|
+
replayTraceId: asString(data.replayTraceId ?? data.replay_trace_id),
|
|
231
|
+
cacheUntil: asString(data.cacheUntil ?? data.cache_until)
|
|
232
|
+
});
|
|
233
|
+
const getDirname = () => {
|
|
234
|
+
if (typeof __dirname !== "undefined") return __dirname;
|
|
235
|
+
if (typeof require("url").pathToFileURL(__filename).href !== "undefined") return path.dirname((0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
236
|
+
return process.cwd();
|
|
237
|
+
};
|
|
238
|
+
const isOtelAttributeValueType = (value) => {
|
|
239
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return true;
|
|
240
|
+
if (Array.isArray(value)) {
|
|
241
|
+
const allStrings = value.every((value) => value == null || typeof value === "string");
|
|
242
|
+
const allNumbers = value.every((value) => value == null || typeof value === "number");
|
|
243
|
+
const allBooleans = value.every((value) => value == null || typeof value === "boolean");
|
|
244
|
+
return allStrings || allNumbers || allBooleans;
|
|
245
|
+
}
|
|
246
|
+
return false;
|
|
247
|
+
};
|
|
248
|
+
const metadataToAttributes = (metadata) => Object.fromEntries(Object.entries(metadata).map(([key, value]) => {
|
|
249
|
+
if (isOtelAttributeValueType(value)) return [`${ASSOCIATION_PROPERTIES}.metadata.${key}`, value];
|
|
250
|
+
else return [`${ASSOCIATION_PROPERTIES}.metadata.${key}`, JSON.stringify(value)];
|
|
251
|
+
}));
|
|
252
|
+
/**
|
|
253
|
+
* Get OTEL environment variable with priority order.
|
|
254
|
+
* Checks in order:
|
|
255
|
+
* 1. OTEL_EXPORTER_OTLP_TRACES_{varName}
|
|
256
|
+
* 2. OTEL_EXPORTER_OTLP_{varName}
|
|
257
|
+
* 3. OTEL_{varName}
|
|
258
|
+
*
|
|
259
|
+
* @param varName - The variable name (e.g., 'ENDPOINT', 'HEADERS', 'PROTOCOL')
|
|
260
|
+
* @returns The environment variable value or undefined if not found
|
|
261
|
+
*/
|
|
262
|
+
const getOtelEnvVar = (varName) => {
|
|
263
|
+
const candidates = [
|
|
264
|
+
`OTEL_EXPORTER_OTLP_TRACES_${varName}`,
|
|
265
|
+
`OTEL_EXPORTER_OTLP_${varName}`,
|
|
266
|
+
`OTEL_${varName}`
|
|
267
|
+
];
|
|
268
|
+
for (const candidate of candidates) {
|
|
269
|
+
const value = process?.env?.[candidate];
|
|
270
|
+
if (value) return value;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Check if OTEL configuration is available.
|
|
275
|
+
* @returns true if OTEL endpoint is configured
|
|
276
|
+
*/
|
|
277
|
+
const hasOtelConfig = () => !!getOtelEnvVar("ENDPOINT");
|
|
278
|
+
/**
|
|
279
|
+
* Parse OTEL headers string into a record object.
|
|
280
|
+
* Format: key1=value1,key2=value2
|
|
281
|
+
* Values are URL-decoded.
|
|
282
|
+
*
|
|
283
|
+
* @param headersStr - Headers string in OTEL format
|
|
284
|
+
* @returns Parsed headers object
|
|
285
|
+
*/
|
|
286
|
+
const parseOtelHeaders = (headersStr) => {
|
|
287
|
+
if (!headersStr) return {};
|
|
288
|
+
const headers = {};
|
|
289
|
+
for (const pair of headersStr.split(",")) {
|
|
290
|
+
const equalIndex = pair.indexOf("=");
|
|
291
|
+
if (equalIndex !== -1) {
|
|
292
|
+
const key = pair.substring(0, equalIndex).trim();
|
|
293
|
+
const value = pair.substring(equalIndex + 1).trim();
|
|
294
|
+
headers[key] = decodeURIComponent(value);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return headers;
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* Validate that either Laminar API key or OTEL configuration is present.
|
|
301
|
+
* Throws an error if neither is configured.
|
|
302
|
+
*
|
|
303
|
+
* @param apiKey - The Laminar API key (if provided)
|
|
304
|
+
* @throws Error if neither API key nor OTEL configuration is present
|
|
305
|
+
*/
|
|
306
|
+
const validateTracingConfig = (apiKey) => {
|
|
307
|
+
if (!apiKey && !hasOtelConfig()) throw new Error("Please initialize the Laminar object with your project API key or set the LMNR_PROJECT_API_KEY environment variable, or configure OTEL environment variables (OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, etc.)");
|
|
308
|
+
};
|
|
309
|
+
const loadEnv$1 = (options) => {
|
|
310
|
+
const nodeEnv = process.env.NODE_ENV || "development";
|
|
311
|
+
const envDir = process.cwd();
|
|
312
|
+
const envFiles = [
|
|
313
|
+
".env",
|
|
314
|
+
".env.local",
|
|
315
|
+
`.env.${nodeEnv}`,
|
|
316
|
+
`.env.${nodeEnv}.local`
|
|
317
|
+
];
|
|
318
|
+
const logLevel = process.env.LMNR_LOG_LEVEL ?? "info";
|
|
319
|
+
const verbose = ["debug", "trace"].includes(logLevel.trim().toLowerCase());
|
|
320
|
+
const quiet = options?.quiet ?? !verbose;
|
|
321
|
+
(0, dotenv.config)({
|
|
322
|
+
path: options?.paths ?? envFiles.map((envFile) => path.resolve(envDir, envFile)),
|
|
323
|
+
quiet
|
|
324
|
+
});
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Converts an API base URL to the frontend/web URL.
|
|
328
|
+
* - Converts https://api.lmnr.ai to https://www.laminar.sh
|
|
329
|
+
* - Removes trailing slashes
|
|
330
|
+
* - For localhost/127.0.0.1, ensures a port is specified (defaults to 5667)
|
|
331
|
+
*
|
|
332
|
+
* @param baseUrl - The API base URL (defaults to "https://api.lmnr.ai")
|
|
333
|
+
* @returns The frontend URL
|
|
334
|
+
*/
|
|
335
|
+
const getFrontendUrl = (baseUrl, frontendPort) => {
|
|
336
|
+
let url$1 = baseUrl ?? "https://api.lmnr.ai";
|
|
337
|
+
if (url$1 === "https://api.lmnr.ai") url$1 = "https://www.laminar.sh";
|
|
338
|
+
url$1 = url$1.replace(/\/$/, "");
|
|
339
|
+
if (/localhost|127\.0\.0\.1/.test(url$1)) {
|
|
340
|
+
const port = frontendPort ?? url$1.match(/:\d{1,5}$/g)?.[0]?.slice(1) ?? 5667;
|
|
341
|
+
if (/:(\d{1,5})$/.test(url$1)) url$1 = url$1.replace(/:\d{1,5}$/g, `:${port}`);
|
|
342
|
+
else url$1 = `${url$1}:${port}`;
|
|
343
|
+
}
|
|
344
|
+
return url$1;
|
|
345
|
+
};
|
|
12
346
|
//#endregion
|
|
13
347
|
//#region ../client/dist/index.mjs
|
|
14
|
-
var version = "0.8.
|
|
348
|
+
var version = "0.8.32";
|
|
15
349
|
function getLangVersion() {
|
|
16
350
|
if (typeof process !== "undefined" && process.versions && process.versions.node) return `node-${process.versions.node}`;
|
|
17
351
|
if (typeof navigator !== "undefined" && navigator.userAgent) return `browser-${navigator.userAgent}`;
|
|
@@ -96,7 +430,7 @@ var CliResource = class extends BaseResource {
|
|
|
96
430
|
function initializeLogger(options) {
|
|
97
431
|
const colorize = options?.colorize ?? true;
|
|
98
432
|
const level = options?.level ?? process.env.LMNR_LOG_LEVEL?.toLowerCase()?.trim() ?? "info";
|
|
99
|
-
return (0, pino.default)({ level }, (0, pino_pretty.PinoPretty)({
|
|
433
|
+
return (0, pino$3.default)({ level }, (0, pino_pretty.PinoPretty)({
|
|
100
434
|
colorize,
|
|
101
435
|
minimumLevel: level
|
|
102
436
|
}));
|
|
@@ -146,7 +480,7 @@ const loadEnv = (options) => {
|
|
|
146
480
|
const verbose = ["debug", "trace"].includes(logLevel.trim().toLowerCase());
|
|
147
481
|
const quiet = options?.quiet ?? !verbose;
|
|
148
482
|
(0, dotenv.config)({
|
|
149
|
-
path: options?.paths ?? envFiles.map((envFile) => path.resolve(envDir, envFile)),
|
|
483
|
+
path: options?.paths ?? envFiles.map((envFile) => path$1.resolve(envDir, envFile)),
|
|
150
484
|
quiet
|
|
151
485
|
});
|
|
152
486
|
};
|
|
@@ -531,7 +865,7 @@ var RolloutSessionsResource = class extends BaseResource {
|
|
|
531
865
|
try {
|
|
532
866
|
return (await response.json()).projectId ?? null;
|
|
533
867
|
} catch (e) {
|
|
534
|
-
logger$1.warn(`Failed to parse rollout register response: ${
|
|
868
|
+
logger$1.warn(`Failed to parse rollout register response: ${errorMessage(e)}`);
|
|
535
869
|
return null;
|
|
536
870
|
}
|
|
537
871
|
}
|
|
@@ -576,7 +910,7 @@ var RolloutSessionsResource = class extends BaseResource {
|
|
|
576
910
|
})
|
|
577
911
|
});
|
|
578
912
|
} catch (e) {
|
|
579
|
-
logger$1.warn(`Debug cache lookup failed, running live: ${
|
|
913
|
+
logger$1.warn(`Debug cache lookup failed, running live: ${errorMessage(e)}`);
|
|
580
914
|
return { kind: "live" };
|
|
581
915
|
}
|
|
582
916
|
if (!response.ok) {
|
|
@@ -587,7 +921,7 @@ var RolloutSessionsResource = class extends BaseResource {
|
|
|
587
921
|
try {
|
|
588
922
|
body = await response.json();
|
|
589
923
|
} catch (e) {
|
|
590
|
-
logger$1.warn(`Failed to parse debug cache response, running live: ${
|
|
924
|
+
logger$1.warn(`Failed to parse debug cache response, running live: ${errorMessage(e)}`);
|
|
591
925
|
return { kind: "live" };
|
|
592
926
|
}
|
|
593
927
|
switch (body.outcome) {
|
|
@@ -831,12 +1165,246 @@ var LaminarClient = class LaminarClient {
|
|
|
831
1165
|
}
|
|
832
1166
|
};
|
|
833
1167
|
//#endregion
|
|
1168
|
+
Object.defineProperty(exports, "ASSOCIATION_PROPERTIES", {
|
|
1169
|
+
enumerable: true,
|
|
1170
|
+
get: function() {
|
|
1171
|
+
return ASSOCIATION_PROPERTIES;
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
1174
|
+
Object.defineProperty(exports, "ASSOCIATION_PROPERTIES_OVERRIDES", {
|
|
1175
|
+
enumerable: true,
|
|
1176
|
+
get: function() {
|
|
1177
|
+
return ASSOCIATION_PROPERTIES_OVERRIDES;
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
Object.defineProperty(exports, "DEBUG_SESSION_DIR", {
|
|
1181
|
+
enumerable: true,
|
|
1182
|
+
get: function() {
|
|
1183
|
+
return DEBUG_SESSION_DIR;
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
Object.defineProperty(exports, "DEBUG_SESSION_FILE", {
|
|
1187
|
+
enumerable: true,
|
|
1188
|
+
get: function() {
|
|
1189
|
+
return DEBUG_SESSION_FILE;
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
Object.defineProperty(exports, "HUMAN_EVALUATOR_OPTIONS", {
|
|
1193
|
+
enumerable: true,
|
|
1194
|
+
get: function() {
|
|
1195
|
+
return HUMAN_EVALUATOR_OPTIONS;
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
Object.defineProperty(exports, "LaminarAttributes", {
|
|
1199
|
+
enumerable: true,
|
|
1200
|
+
get: function() {
|
|
1201
|
+
return LaminarAttributes;
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
834
1204
|
Object.defineProperty(exports, "LaminarClient", {
|
|
835
1205
|
enumerable: true,
|
|
836
1206
|
get: function() {
|
|
837
1207
|
return LaminarClient;
|
|
838
1208
|
}
|
|
839
1209
|
});
|
|
1210
|
+
Object.defineProperty(exports, "NIL_UUID", {
|
|
1211
|
+
enumerable: true,
|
|
1212
|
+
get: function() {
|
|
1213
|
+
return NIL_UUID;
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
Object.defineProperty(exports, "PARENT_SPAN_IDS_PATH", {
|
|
1217
|
+
enumerable: true,
|
|
1218
|
+
get: function() {
|
|
1219
|
+
return PARENT_SPAN_IDS_PATH;
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
Object.defineProperty(exports, "PARENT_SPAN_PATH", {
|
|
1223
|
+
enumerable: true,
|
|
1224
|
+
get: function() {
|
|
1225
|
+
return PARENT_SPAN_PATH;
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
Object.defineProperty(exports, "SESSION_ID", {
|
|
1229
|
+
enumerable: true,
|
|
1230
|
+
get: function() {
|
|
1231
|
+
return SESSION_ID;
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
Object.defineProperty(exports, "SPAN_IDS_PATH", {
|
|
1235
|
+
enumerable: true,
|
|
1236
|
+
get: function() {
|
|
1237
|
+
return SPAN_IDS_PATH;
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1240
|
+
Object.defineProperty(exports, "SPAN_INPUT", {
|
|
1241
|
+
enumerable: true,
|
|
1242
|
+
get: function() {
|
|
1243
|
+
return SPAN_INPUT;
|
|
1244
|
+
}
|
|
1245
|
+
});
|
|
1246
|
+
Object.defineProperty(exports, "SPAN_INSTRUMENTATION_SOURCE", {
|
|
1247
|
+
enumerable: true,
|
|
1248
|
+
get: function() {
|
|
1249
|
+
return SPAN_INSTRUMENTATION_SOURCE;
|
|
1250
|
+
}
|
|
1251
|
+
});
|
|
1252
|
+
Object.defineProperty(exports, "SPAN_LANGUAGE_VERSION", {
|
|
1253
|
+
enumerable: true,
|
|
1254
|
+
get: function() {
|
|
1255
|
+
return SPAN_LANGUAGE_VERSION;
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
Object.defineProperty(exports, "SPAN_OUTPUT", {
|
|
1259
|
+
enumerable: true,
|
|
1260
|
+
get: function() {
|
|
1261
|
+
return SPAN_OUTPUT;
|
|
1262
|
+
}
|
|
1263
|
+
});
|
|
1264
|
+
Object.defineProperty(exports, "SPAN_PATH", {
|
|
1265
|
+
enumerable: true,
|
|
1266
|
+
get: function() {
|
|
1267
|
+
return SPAN_PATH;
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
Object.defineProperty(exports, "SPAN_SDK_VERSION", {
|
|
1271
|
+
enumerable: true,
|
|
1272
|
+
get: function() {
|
|
1273
|
+
return SPAN_SDK_VERSION;
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
Object.defineProperty(exports, "SPAN_TYPE", {
|
|
1277
|
+
enumerable: true,
|
|
1278
|
+
get: function() {
|
|
1279
|
+
return SPAN_TYPE;
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
Object.defineProperty(exports, "Semaphore", {
|
|
1283
|
+
enumerable: true,
|
|
1284
|
+
get: function() {
|
|
1285
|
+
return Semaphore;
|
|
1286
|
+
}
|
|
1287
|
+
});
|
|
1288
|
+
Object.defineProperty(exports, "TRACE_HAS_BROWSER_SESSION", {
|
|
1289
|
+
enumerable: true,
|
|
1290
|
+
get: function() {
|
|
1291
|
+
return TRACE_HAS_BROWSER_SESSION;
|
|
1292
|
+
}
|
|
1293
|
+
});
|
|
1294
|
+
Object.defineProperty(exports, "TRACE_TYPE", {
|
|
1295
|
+
enumerable: true,
|
|
1296
|
+
get: function() {
|
|
1297
|
+
return TRACE_TYPE;
|
|
1298
|
+
}
|
|
1299
|
+
});
|
|
1300
|
+
Object.defineProperty(exports, "TracingLevel", {
|
|
1301
|
+
enumerable: true,
|
|
1302
|
+
get: function() {
|
|
1303
|
+
return TracingLevel;
|
|
1304
|
+
}
|
|
1305
|
+
});
|
|
1306
|
+
Object.defineProperty(exports, "USER_ID", {
|
|
1307
|
+
enumerable: true,
|
|
1308
|
+
get: function() {
|
|
1309
|
+
return USER_ID;
|
|
1310
|
+
}
|
|
1311
|
+
});
|
|
1312
|
+
Object.defineProperty(exports, "deserializeLaminarSpanContext", {
|
|
1313
|
+
enumerable: true,
|
|
1314
|
+
get: function() {
|
|
1315
|
+
return deserializeLaminarSpanContext;
|
|
1316
|
+
}
|
|
1317
|
+
});
|
|
1318
|
+
Object.defineProperty(exports, "errorMessage", {
|
|
1319
|
+
enumerable: true,
|
|
1320
|
+
get: function() {
|
|
1321
|
+
return errorMessage;
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
Object.defineProperty(exports, "getDirname", {
|
|
1325
|
+
enumerable: true,
|
|
1326
|
+
get: function() {
|
|
1327
|
+
return getDirname;
|
|
1328
|
+
}
|
|
1329
|
+
});
|
|
1330
|
+
Object.defineProperty(exports, "getFrontendUrl", {
|
|
1331
|
+
enumerable: true,
|
|
1332
|
+
get: function() {
|
|
1333
|
+
return getFrontendUrl;
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
Object.defineProperty(exports, "getOtelEnvVar", {
|
|
1337
|
+
enumerable: true,
|
|
1338
|
+
get: function() {
|
|
1339
|
+
return getOtelEnvVar;
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
Object.defineProperty(exports, "initializeLogger", {
|
|
1343
|
+
enumerable: true,
|
|
1344
|
+
get: function() {
|
|
1345
|
+
return initializeLogger$1;
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
Object.defineProperty(exports, "loadEnv", {
|
|
1349
|
+
enumerable: true,
|
|
1350
|
+
get: function() {
|
|
1351
|
+
return loadEnv$1;
|
|
1352
|
+
}
|
|
1353
|
+
});
|
|
1354
|
+
Object.defineProperty(exports, "metadataToAttributes", {
|
|
1355
|
+
enumerable: true,
|
|
1356
|
+
get: function() {
|
|
1357
|
+
return metadataToAttributes;
|
|
1358
|
+
}
|
|
1359
|
+
});
|
|
1360
|
+
Object.defineProperty(exports, "newUUID", {
|
|
1361
|
+
enumerable: true,
|
|
1362
|
+
get: function() {
|
|
1363
|
+
return newUUID$1;
|
|
1364
|
+
}
|
|
1365
|
+
});
|
|
1366
|
+
Object.defineProperty(exports, "normalizeOtelSpanId", {
|
|
1367
|
+
enumerable: true,
|
|
1368
|
+
get: function() {
|
|
1369
|
+
return normalizeOtelSpanId;
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
Object.defineProperty(exports, "normalizeOtelTraceId", {
|
|
1373
|
+
enumerable: true,
|
|
1374
|
+
get: function() {
|
|
1375
|
+
return normalizeOtelTraceId;
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
Object.defineProperty(exports, "otelSpanIdToUUID", {
|
|
1379
|
+
enumerable: true,
|
|
1380
|
+
get: function() {
|
|
1381
|
+
return otelSpanIdToUUID$1;
|
|
1382
|
+
}
|
|
1383
|
+
});
|
|
1384
|
+
Object.defineProperty(exports, "otelTraceIdToUUID", {
|
|
1385
|
+
enumerable: true,
|
|
1386
|
+
get: function() {
|
|
1387
|
+
return otelTraceIdToUUID$1;
|
|
1388
|
+
}
|
|
1389
|
+
});
|
|
1390
|
+
Object.defineProperty(exports, "parseOtelHeaders", {
|
|
1391
|
+
enumerable: true,
|
|
1392
|
+
get: function() {
|
|
1393
|
+
return parseOtelHeaders;
|
|
1394
|
+
}
|
|
1395
|
+
});
|
|
1396
|
+
Object.defineProperty(exports, "tryToOtelSpanContext", {
|
|
1397
|
+
enumerable: true,
|
|
1398
|
+
get: function() {
|
|
1399
|
+
return tryToOtelSpanContext;
|
|
1400
|
+
}
|
|
1401
|
+
});
|
|
1402
|
+
Object.defineProperty(exports, "validateTracingConfig", {
|
|
1403
|
+
enumerable: true,
|
|
1404
|
+
get: function() {
|
|
1405
|
+
return validateTracingConfig;
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
840
1408
|
Object.defineProperty(exports, "version", {
|
|
841
1409
|
enumerable: true,
|
|
842
1410
|
get: function() {
|
|
@@ -844,4 +1412,4 @@ Object.defineProperty(exports, "version", {
|
|
|
844
1412
|
}
|
|
845
1413
|
});
|
|
846
1414
|
|
|
847
|
-
//# sourceMappingURL=dist-
|
|
1415
|
+
//# sourceMappingURL=dist-CDaxruok.cjs.map
|