@morsehq-dev/sdk 0.4.1 → 0.5.0-rc.2
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/anthropic/index.cjs +12 -10
- package/dist/anthropic/index.js +5 -3
- package/dist/anthropic-agent-sdk/index.cjs +52 -34
- package/dist/anthropic-agent-sdk/index.cjs.map +1 -1
- package/dist/anthropic-agent-sdk/index.js +25 -7
- package/dist/anthropic-agent-sdk/index.js.map +1 -1
- package/dist/browser/anthropic/index.cjs +12 -10
- package/dist/browser/anthropic/index.js +5 -3
- package/dist/browser/anthropic-agent-sdk/index.cjs +52 -34
- package/dist/browser/anthropic-agent-sdk/index.cjs.map +1 -1
- package/dist/browser/anthropic-agent-sdk/index.js +25 -7
- package/dist/browser/anthropic-agent-sdk/index.js.map +1 -1
- package/dist/browser/{chunk-GWJYOQNC.js → chunk-3MTJGZGX.js} +10 -4
- package/dist/browser/chunk-3MTJGZGX.js.map +1 -0
- package/dist/browser/{chunk-EFUQVASI.cjs → chunk-63ZI6PGP.cjs} +17 -15
- package/dist/browser/chunk-63ZI6PGP.cjs.map +1 -0
- package/dist/browser/{chunk-DXWHT3HK.cjs → chunk-A5EYWAOT.cjs} +428 -63
- package/dist/browser/chunk-A5EYWAOT.cjs.map +1 -0
- package/dist/browser/{chunk-AYNX24P5.js → chunk-AM6LMQCT.js} +3 -3
- package/dist/browser/{chunk-AYNX24P5.js.map → chunk-AM6LMQCT.js.map} +1 -1
- package/dist/{chunk-SBGY5NS4.js → browser/chunk-FDE32B3R.js} +6 -4
- package/dist/browser/chunk-FDE32B3R.js.map +1 -0
- package/dist/browser/{chunk-DOLWR7LD.js → chunk-L6FWDEGJ.js} +4 -4
- package/dist/browser/{chunk-DOLWR7LD.js.map → chunk-L6FWDEGJ.js.map} +1 -1
- package/dist/browser/{chunk-QWRQJO57.js → chunk-MLDVXMQD.js} +3 -3
- package/dist/browser/{chunk-QWRQJO57.js.map → chunk-MLDVXMQD.js.map} +1 -1
- package/dist/{chunk-Y7SVGUKY.cjs → browser/chunk-N3PXJCOE.cjs} +7 -7
- package/dist/browser/{chunk-YNUZGKUA.cjs.map → chunk-N3PXJCOE.cjs.map} +1 -1
- package/dist/browser/chunk-NH54DAJP.js +118 -0
- package/dist/browser/chunk-NH54DAJP.js.map +1 -0
- package/dist/browser/chunk-NRYB5GJT.js +28 -0
- package/dist/browser/chunk-NRYB5GJT.js.map +1 -0
- package/dist/browser/{chunk-F3B4UR64.js → chunk-OOGAYEJF.js} +423 -61
- package/dist/browser/chunk-OOGAYEJF.js.map +1 -0
- package/dist/browser/{chunk-3643DC7K.cjs → chunk-RBNCTHK3.cjs} +5 -2
- package/dist/browser/{chunk-3643DC7K.cjs.map → chunk-RBNCTHK3.cjs.map} +1 -1
- package/dist/browser/chunk-SOJYLXCR.cjs +126 -0
- package/dist/browser/chunk-SOJYLXCR.cjs.map +1 -0
- package/dist/browser/{chunk-HGN7J3EU.cjs → chunk-T4NHSVXH.cjs} +12 -12
- package/dist/browser/{chunk-HGN7J3EU.cjs.map → chunk-T4NHSVXH.cjs.map} +1 -1
- package/dist/browser/chunk-YMEU6XQQ.cjs +31 -0
- package/dist/browser/chunk-YMEU6XQQ.cjs.map +1 -0
- package/dist/browser/{chunk-M2GZJ3RS.cjs → chunk-YR2FCEWM.cjs} +20 -14
- package/dist/browser/chunk-YR2FCEWM.cjs.map +1 -0
- package/dist/browser/index.cjs +112 -82
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +40 -10
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/integrations/pino.cjs +4 -4
- package/dist/browser/integrations/pino.js +3 -3
- package/dist/browser/langchain/index.cjs +19 -19
- package/dist/browser/langchain/index.js +3 -3
- package/dist/browser/langgraph/index.cjs +34 -26
- package/dist/browser/langgraph/index.cjs.map +1 -1
- package/dist/browser/langgraph/index.js +16 -8
- package/dist/browser/langgraph/index.js.map +1 -1
- package/dist/browser/openai/index.cjs +22 -8
- package/dist/browser/openai/index.cjs.map +1 -1
- package/dist/browser/openai/index.js +17 -3
- package/dist/browser/openai/index.js.map +1 -1
- package/dist/browser/openai-agents/index.cjs +42 -34
- package/dist/browser/openai-agents/index.cjs.map +1 -1
- package/dist/browser/openai-agents/index.js +13 -5
- package/dist/browser/openai-agents/index.js.map +1 -1
- package/dist/browser/vercel-ai/index.cjs +16 -16
- package/dist/browser/vercel-ai/index.js +4 -4
- package/dist/{chunk-LTKGLXAE.js → chunk-3IGQWLWE.js} +447 -76
- package/dist/chunk-3IGQWLWE.js.map +1 -0
- package/dist/{chunk-4R4SHGOK.js → chunk-4JPZV2VZ.js} +3 -3
- package/dist/{chunk-4R4SHGOK.js.map → chunk-4JPZV2VZ.js.map} +1 -1
- package/dist/chunk-6DZNK4VX.cjs +31 -0
- package/dist/chunk-6DZNK4VX.cjs.map +1 -0
- package/dist/{browser/chunk-F7BGQ26H.js → chunk-FCAPLB7A.js} +6 -4
- package/dist/chunk-FCAPLB7A.js.map +1 -0
- package/dist/{chunk-KJEO52QS.cjs → chunk-HICEJ4LV.cjs} +5 -2
- package/dist/{chunk-KJEO52QS.cjs.map → chunk-HICEJ4LV.cjs.map} +1 -1
- package/dist/chunk-S4WUABAU.js +28 -0
- package/dist/chunk-S4WUABAU.js.map +1 -0
- package/dist/{chunk-V5J6J4ZR.js → chunk-SHK2XEPB.js} +4 -4
- package/dist/{chunk-V5J6J4ZR.js.map → chunk-SHK2XEPB.js.map} +1 -1
- package/dist/{chunk-LQI63FHF.cjs → chunk-SNGYSP7Z.cjs} +20 -14
- package/dist/chunk-SNGYSP7Z.cjs.map +1 -0
- package/dist/chunk-VHF4GWJ4.cjs +126 -0
- package/dist/chunk-VHF4GWJ4.cjs.map +1 -0
- package/dist/{chunk-HNCWTENX.cjs → chunk-XCOZIFHC.cjs} +452 -78
- package/dist/chunk-XCOZIFHC.cjs.map +1 -0
- package/dist/chunk-XJUH6PR5.js +118 -0
- package/dist/chunk-XJUH6PR5.js.map +1 -0
- package/dist/{browser/chunk-YNUZGKUA.cjs → chunk-Y2QHMV6H.cjs} +7 -7
- package/dist/{chunk-Y7SVGUKY.cjs.map → chunk-Y2QHMV6H.cjs.map} +1 -1
- package/dist/{chunk-STK4KJQ6.js → chunk-YJYF4NSA.js} +10 -4
- package/dist/chunk-YJYF4NSA.js.map +1 -0
- package/dist/{chunk-5D6SBSEI.cjs → chunk-Z2IYSTRT.cjs} +17 -15
- package/dist/chunk-Z2IYSTRT.cjs.map +1 -0
- package/dist/{chunk-QXRJUPDP.cjs → chunk-ZIER4DGK.cjs} +12 -12
- package/dist/{chunk-QXRJUPDP.cjs.map → chunk-ZIER4DGK.cjs.map} +1 -1
- package/dist/{chunk-AEFUXEKV.js → chunk-ZWOSPXS4.js} +3 -3
- package/dist/{chunk-AEFUXEKV.js.map → chunk-ZWOSPXS4.js.map} +1 -1
- package/dist/index.cjs +119 -89
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +41 -11
- package/dist/index.js.map +1 -1
- package/dist/integrations/pino.cjs +4 -4
- package/dist/integrations/pino.js +3 -3
- package/dist/langchain/index.cjs +19 -19
- package/dist/langchain/index.d.cts +1 -1
- package/dist/langchain/index.d.ts +1 -1
- package/dist/langchain/index.js +3 -3
- package/dist/langgraph/index.cjs +34 -26
- package/dist/langgraph/index.cjs.map +1 -1
- package/dist/langgraph/index.d.cts +1 -1
- package/dist/langgraph/index.d.ts +1 -1
- package/dist/langgraph/index.js +16 -8
- package/dist/langgraph/index.js.map +1 -1
- package/dist/openai/index.cjs +22 -8
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.js +17 -3
- package/dist/openai/index.js.map +1 -1
- package/dist/openai-agents/index.cjs +42 -34
- package/dist/openai-agents/index.cjs.map +1 -1
- package/dist/openai-agents/index.js +13 -5
- package/dist/openai-agents/index.js.map +1 -1
- package/dist/{tracing-BYAqjT5Q.d.cts → tracing-CNlre8TK.d.cts} +1 -0
- package/dist/{tracing-rz9cWQ8d.d.ts → tracing-J8ZgxVzU.d.ts} +1 -0
- package/dist/vercel-ai/index.cjs +16 -16
- package/dist/vercel-ai/index.js +4 -4
- package/package.json +1 -9
- package/dist/browser/chunk-3BGG7GH3.cjs +0 -183
- package/dist/browser/chunk-3BGG7GH3.cjs.map +0 -1
- package/dist/browser/chunk-DXWHT3HK.cjs.map +0 -1
- package/dist/browser/chunk-EFUQVASI.cjs.map +0 -1
- package/dist/browser/chunk-F3B4UR64.js.map +0 -1
- package/dist/browser/chunk-F7BGQ26H.js.map +0 -1
- package/dist/browser/chunk-GWJYOQNC.js.map +0 -1
- package/dist/browser/chunk-M2GZJ3RS.cjs.map +0 -1
- package/dist/browser/chunk-YHV5GL32.js +0 -178
- package/dist/browser/chunk-YHV5GL32.js.map +0 -1
- package/dist/chunk-5D6SBSEI.cjs.map +0 -1
- package/dist/chunk-HNCWTENX.cjs.map +0 -1
- package/dist/chunk-LQI63FHF.cjs.map +0 -1
- package/dist/chunk-LTKGLXAE.js.map +0 -1
- package/dist/chunk-POCQNSVD.js +0 -178
- package/dist/chunk-POCQNSVD.js.map +0 -1
- package/dist/chunk-SBGY5NS4.js.map +0 -1
- package/dist/chunk-STK4KJQ6.js.map +0 -1
- package/dist/chunk-T2KW3P23.cjs +0 -183
- package/dist/chunk-T2KW3P23.cjs.map +0 -1
|
@@ -120,53 +120,6 @@ var init_env = __esm({
|
|
|
120
120
|
}
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
-
// src/_internal/otel-provider.browser.ts
|
|
124
|
-
function noteBrowserRuntime() {
|
|
125
|
-
if (warned) return;
|
|
126
|
-
warned = true;
|
|
127
|
-
try {
|
|
128
|
-
console.info(
|
|
129
|
-
"[morse] Browser build active: OpenTelemetry span export and database capture are Node-only, so traces are sent via Morse's JSON transport instead. Everything else \u2014 run()/span()/track() and W3C traceparent propagation \u2014 behaves identically. Server-side code (Next.js route handlers, RSC, Node services) automatically gets the full OTel pipeline."
|
|
130
|
-
);
|
|
131
|
-
} catch {
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
function getEngine() {
|
|
135
|
-
return engine;
|
|
136
|
-
}
|
|
137
|
-
function withOtelSpanContext(traceIdHex, spanIdHex, fn) {
|
|
138
|
-
return fn();
|
|
139
|
-
}
|
|
140
|
-
var warned, OtelEngine, engine;
|
|
141
|
-
var init_otel_provider_browser = __esm({
|
|
142
|
-
"src/_internal/otel-provider.browser.ts"() {
|
|
143
|
-
warned = false;
|
|
144
|
-
OtelEngine = class {
|
|
145
|
-
// Params are declared (not dropped) so this class stays signature-compatible
|
|
146
|
-
// with the real `OtelEngine` — the build swaps the modules, but anything
|
|
147
|
-
// type-checking against this one must see the same shape. `void x` marks the
|
|
148
|
-
// deliberate non-use for @typescript-eslint/no-unused-vars.
|
|
149
|
-
configure(opts) {
|
|
150
|
-
noteBrowserRuntime();
|
|
151
|
-
}
|
|
152
|
-
shutdown() {
|
|
153
|
-
}
|
|
154
|
-
resetForTesting() {
|
|
155
|
-
warned = false;
|
|
156
|
-
}
|
|
157
|
-
async flush() {
|
|
158
|
-
}
|
|
159
|
-
resolveSampled(traceIdHex) {
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
162
|
-
registerInstrumentations(instrumentations) {
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
engine = new OtelEngine();
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
|
|
170
123
|
// src/_internal/redaction.ts
|
|
171
124
|
function buildRedactionConfig(options) {
|
|
172
125
|
const opts = options ?? {};
|
|
@@ -355,6 +308,377 @@ var init_redaction = __esm({
|
|
|
355
308
|
}
|
|
356
309
|
});
|
|
357
310
|
|
|
311
|
+
// src/_internal/diagnostics.ts
|
|
312
|
+
function setRedactionConfig(config) {
|
|
313
|
+
activeRedactionConfig = config;
|
|
314
|
+
}
|
|
315
|
+
function setLevel(raw) {
|
|
316
|
+
if (!raw) return;
|
|
317
|
+
const value = String(raw).trim().toLowerCase();
|
|
318
|
+
if (!VALID_LEVELS.has(value)) return;
|
|
319
|
+
level = value;
|
|
320
|
+
}
|
|
321
|
+
function transmissionAllowed() {
|
|
322
|
+
if (isTelemetryDisabled() || isDisabled()) return false;
|
|
323
|
+
return level !== LEVEL_OFF;
|
|
324
|
+
}
|
|
325
|
+
function checkBucket(buckets, key, limit, windowMs) {
|
|
326
|
+
const now = Date.now();
|
|
327
|
+
const bucket = buckets.get(key) ?? [];
|
|
328
|
+
const cutoff = now - windowMs;
|
|
329
|
+
while (bucket.length > 0 && bucket[0] < cutoff) bucket.shift();
|
|
330
|
+
if (bucket.length >= limit) {
|
|
331
|
+
buckets.set(key, bucket);
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
bucket.push(now);
|
|
335
|
+
buckets.set(key, bucket);
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
function checkRateLimit(fingerprint) {
|
|
339
|
+
const limit = level === LEVEL_DEBUG ? RATE_LIMIT_PER_WINDOW_DEBUG : RATE_LIMIT_PER_WINDOW;
|
|
340
|
+
return checkBucket(rateBuckets, fingerprint, limit, RATE_WINDOW_MS);
|
|
341
|
+
}
|
|
342
|
+
function isMorseFrame(line) {
|
|
343
|
+
return MORSE_PATH_MARKERS.some((marker) => line.includes(marker));
|
|
344
|
+
}
|
|
345
|
+
function parseFrame(line) {
|
|
346
|
+
const withParens = /^\s*at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)\s*$/.exec(line);
|
|
347
|
+
if (withParens) {
|
|
348
|
+
return {
|
|
349
|
+
fn: withParens[1],
|
|
350
|
+
file: withParens[2],
|
|
351
|
+
lineNo: Number(withParens[3])
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
const bare = /^\s*at\s+(.+?):(\d+):(\d+)\s*$/.exec(line);
|
|
355
|
+
if (bare) return { file: bare[1], lineNo: Number(bare[2]) };
|
|
356
|
+
return {};
|
|
357
|
+
}
|
|
358
|
+
function buildScopedStack(error) {
|
|
359
|
+
const frames = [];
|
|
360
|
+
try {
|
|
361
|
+
const stack = error instanceof Error ? error.stack ?? "" : "";
|
|
362
|
+
if (!stack) return frames;
|
|
363
|
+
let elided = 0;
|
|
364
|
+
for (const raw of stack.split("\n")) {
|
|
365
|
+
if (!raw.trim().startsWith("at ")) continue;
|
|
366
|
+
if (isMorseFrame(raw)) {
|
|
367
|
+
if (elided > 0) {
|
|
368
|
+
frames.push({ elided });
|
|
369
|
+
elided = 0;
|
|
370
|
+
}
|
|
371
|
+
const { file, lineNo, fn } = parseFrame(raw);
|
|
372
|
+
const frame = {};
|
|
373
|
+
if (file) frame.file = file.split(/[\\/]/).slice(-3).join("/");
|
|
374
|
+
if (typeof lineNo === "number" && !Number.isNaN(lineNo)) frame.line = lineNo;
|
|
375
|
+
if (fn) frame.function = fn.slice(0, 255);
|
|
376
|
+
frames.push(frame);
|
|
377
|
+
} else {
|
|
378
|
+
elided += 1;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (elided > 0) frames.push({ elided });
|
|
382
|
+
} catch {
|
|
383
|
+
}
|
|
384
|
+
return frames.length > MAX_STACK_ENTRIES ? frames.slice(-MAX_STACK_ENTRIES) : frames;
|
|
385
|
+
}
|
|
386
|
+
function redactedMessage(error) {
|
|
387
|
+
let raw;
|
|
388
|
+
try {
|
|
389
|
+
raw = error instanceof Error ? error.message : String(error);
|
|
390
|
+
} catch {
|
|
391
|
+
return "";
|
|
392
|
+
}
|
|
393
|
+
try {
|
|
394
|
+
if (activeRedactionConfig) {
|
|
395
|
+
const out = redactValue(raw, activeRedactionConfig);
|
|
396
|
+
raw = typeof out === "string" ? out : String(out);
|
|
397
|
+
}
|
|
398
|
+
} catch {
|
|
399
|
+
return "<redaction unavailable>";
|
|
400
|
+
}
|
|
401
|
+
return raw.slice(0, MAX_MESSAGE_CHARS);
|
|
402
|
+
}
|
|
403
|
+
function scrubExtra(extra) {
|
|
404
|
+
const out = {};
|
|
405
|
+
if (!extra) return out;
|
|
406
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
407
|
+
if (ALLOWED_EXTRA_KEYS.has(key) && value != null) {
|
|
408
|
+
out[key] = String(value).slice(0, 255);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return out;
|
|
412
|
+
}
|
|
413
|
+
function recordDrop(reason, category, quantity = 1) {
|
|
414
|
+
try {
|
|
415
|
+
if (quantity <= 0) return;
|
|
416
|
+
const key = `${reason}:${category}`;
|
|
417
|
+
const existing = counters.get(key);
|
|
418
|
+
if (existing) existing.quantity += quantity;
|
|
419
|
+
else counters.set(key, { reason, category, quantity });
|
|
420
|
+
if (checkBucket(localLogBuckets, `drop:${key}`, LOCAL_LOG_LIMIT_PER_WINDOW, LOCAL_LOG_WINDOW_MS)) {
|
|
421
|
+
console.warn(`morse: dropped ${quantity} ${category} (${reason}) \u2014 telemetry is being lost`);
|
|
422
|
+
}
|
|
423
|
+
} catch {
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function drainCounters() {
|
|
427
|
+
if (counters.size === 0) return [];
|
|
428
|
+
const drained = [...counters.values()];
|
|
429
|
+
counters.clear();
|
|
430
|
+
return drained;
|
|
431
|
+
}
|
|
432
|
+
function report(error, options) {
|
|
433
|
+
if (reporting) return;
|
|
434
|
+
reporting = true;
|
|
435
|
+
try {
|
|
436
|
+
const errClass = error instanceof Error ? error.name : "Error";
|
|
437
|
+
const errMessage = error instanceof Error ? error.message : String(error);
|
|
438
|
+
if (checkBucket(
|
|
439
|
+
localLogBuckets,
|
|
440
|
+
options.fingerprint,
|
|
441
|
+
LOCAL_LOG_LIMIT_PER_WINDOW,
|
|
442
|
+
LOCAL_LOG_WINDOW_MS
|
|
443
|
+
)) {
|
|
444
|
+
const line = `morse internal error [${options.fingerprint}]: ${errClass}: ${errMessage}`;
|
|
445
|
+
if (isDebug()) console.error(line, error);
|
|
446
|
+
else console.warn(line);
|
|
447
|
+
}
|
|
448
|
+
if (!transmissionAllowed()) return;
|
|
449
|
+
if (!checkRateLimit(options.fingerprint)) return;
|
|
450
|
+
enqueue({
|
|
451
|
+
kind: "error",
|
|
452
|
+
fingerprint: options.fingerprint.slice(0, 255),
|
|
453
|
+
error_type: errClass.slice(0, 255),
|
|
454
|
+
message: redactedMessage(error),
|
|
455
|
+
stack: buildScopedStack(error),
|
|
456
|
+
sdk_language: "typescript",
|
|
457
|
+
sdk_version: sdkVersion(),
|
|
458
|
+
runtime_version: runtimeVersion(),
|
|
459
|
+
platform: platformLabel(),
|
|
460
|
+
extra: scrubExtra(options.extra)
|
|
461
|
+
});
|
|
462
|
+
} catch {
|
|
463
|
+
} finally {
|
|
464
|
+
reporting = false;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
function sdkVersion() {
|
|
468
|
+
return SDK_VERSION;
|
|
469
|
+
}
|
|
470
|
+
function runtimeVersion() {
|
|
471
|
+
try {
|
|
472
|
+
const proc = globalThis.process;
|
|
473
|
+
return proc?.version ? String(proc.version) : "";
|
|
474
|
+
} catch {
|
|
475
|
+
return "";
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
function platformLabel() {
|
|
479
|
+
try {
|
|
480
|
+
const proc = globalThis.process;
|
|
481
|
+
if (proc?.platform) return `${proc.platform}-${proc.arch ?? ""}`.slice(0, 128);
|
|
482
|
+
return "browser";
|
|
483
|
+
} catch {
|
|
484
|
+
return "";
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
function enqueue(event) {
|
|
488
|
+
pending.push(event);
|
|
489
|
+
while (pending.length > MAX_PENDING) pending.shift();
|
|
490
|
+
ensureTimer();
|
|
491
|
+
}
|
|
492
|
+
function ensureTimer() {
|
|
493
|
+
if (timer !== null) return;
|
|
494
|
+
try {
|
|
495
|
+
timer = setInterval(() => {
|
|
496
|
+
void flushOnce();
|
|
497
|
+
}, FLUSH_INTERVAL_MS);
|
|
498
|
+
timer?.unref?.();
|
|
499
|
+
} catch {
|
|
500
|
+
timer = null;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function breakerBlocks() {
|
|
504
|
+
return breakerOpenUntil > 0 && Date.now() < breakerOpenUntil;
|
|
505
|
+
}
|
|
506
|
+
function recordResult(ok) {
|
|
507
|
+
if (ok) {
|
|
508
|
+
consecutiveFailures = 0;
|
|
509
|
+
breakerOpenUntil = 0;
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
consecutiveFailures += 1;
|
|
513
|
+
if (consecutiveFailures >= BREAKER_THRESHOLD) {
|
|
514
|
+
breakerOpenUntil = Date.now() + BREAKER_COOLDOWN_MS;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
async function flushOnce() {
|
|
518
|
+
try {
|
|
519
|
+
const batch = pending.splice(0, MAX_BATCH_EVENTS);
|
|
520
|
+
const drained = drainCounters();
|
|
521
|
+
if (drained.length > 0) {
|
|
522
|
+
batch.push({
|
|
523
|
+
kind: "counters",
|
|
524
|
+
fingerprint: "morse.transport.delivery",
|
|
525
|
+
counters: drained,
|
|
526
|
+
sdk_language: "typescript",
|
|
527
|
+
sdk_version: sdkVersion()
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
if (batch.length === 0) return;
|
|
531
|
+
if (breakerBlocks() || !transmissionAllowed()) return;
|
|
532
|
+
const target = resolveTarget();
|
|
533
|
+
if (target === null) return;
|
|
534
|
+
let response;
|
|
535
|
+
try {
|
|
536
|
+
response = await fetch(target.url, {
|
|
537
|
+
method: "POST",
|
|
538
|
+
headers: {
|
|
539
|
+
Authorization: `Bearer ${target.apiKey}`,
|
|
540
|
+
"Content-Type": "application/json"
|
|
541
|
+
},
|
|
542
|
+
body: JSON.stringify({ events: batch })
|
|
543
|
+
});
|
|
544
|
+
} catch {
|
|
545
|
+
recordResult(false);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
setLevel(response.headers.get("X-Morse-Diagnostics"));
|
|
549
|
+
recordResult(response.ok);
|
|
550
|
+
} catch {
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function resolveTarget() {
|
|
554
|
+
try {
|
|
555
|
+
const apiKey = getApiKey();
|
|
556
|
+
if (!apiKey) return null;
|
|
557
|
+
const url = deriveDiagnosticsUrl(String(getEndpoint() ?? ""));
|
|
558
|
+
if (!url) return null;
|
|
559
|
+
return { apiKey: String(apiKey), url };
|
|
560
|
+
} catch {
|
|
561
|
+
return null;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
function deriveDiagnosticsUrl(tracesEndpoint) {
|
|
565
|
+
try {
|
|
566
|
+
const parsed = new URL(tracesEndpoint);
|
|
567
|
+
return `${parsed.protocol}//${parsed.host}${DIAGNOSTICS_PATH}`;
|
|
568
|
+
} catch {
|
|
569
|
+
return null;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
function _resetForTesting() {
|
|
573
|
+
rateBuckets.clear();
|
|
574
|
+
localLogBuckets.clear();
|
|
575
|
+
counters.clear();
|
|
576
|
+
pending = [];
|
|
577
|
+
if (timer !== null) {
|
|
578
|
+
clearInterval(timer);
|
|
579
|
+
timer = null;
|
|
580
|
+
}
|
|
581
|
+
consecutiveFailures = 0;
|
|
582
|
+
breakerOpenUntil = 0;
|
|
583
|
+
reporting = false;
|
|
584
|
+
level = LEVEL_ERROR;
|
|
585
|
+
activeRedactionConfig = null;
|
|
586
|
+
}
|
|
587
|
+
var SDK_VERSION, LEVEL_OFF, LEVEL_ERROR, LEVEL_DEBUG, VALID_LEVELS, level, RATE_WINDOW_MS, RATE_LIMIT_PER_WINDOW, RATE_LIMIT_PER_WINDOW_DEBUG, rateBuckets, LOCAL_LOG_WINDOW_MS, LOCAL_LOG_LIMIT_PER_WINDOW, localLogBuckets, MAX_STACK_ENTRIES, MAX_MESSAGE_CHARS, MAX_BATCH_EVENTS, ALLOWED_EXTRA_KEYS, DIAGNOSTICS_PATH, MAX_PENDING, FLUSH_INTERVAL_MS, BREAKER_THRESHOLD, BREAKER_COOLDOWN_MS; exports.REASON_QUEUE_FULL = void 0; exports.REASON_RETRY_EXHAUSTED = void 0; exports.REASON_QUOTA_REJECTED = void 0; exports.REASON_SHUTDOWN_DROP = void 0; var counters, activeRedactionConfig, pending, timer, consecutiveFailures, breakerOpenUntil, reporting, MORSE_PATH_MARKERS;
|
|
588
|
+
var init_diagnostics = __esm({
|
|
589
|
+
"src/_internal/diagnostics.ts"() {
|
|
590
|
+
init_env();
|
|
591
|
+
init_redaction();
|
|
592
|
+
SDK_VERSION = "0.5.0-rc.2" ;
|
|
593
|
+
LEVEL_OFF = "off";
|
|
594
|
+
LEVEL_ERROR = "error";
|
|
595
|
+
LEVEL_DEBUG = "debug";
|
|
596
|
+
VALID_LEVELS = /* @__PURE__ */ new Set([LEVEL_OFF, LEVEL_ERROR, LEVEL_DEBUG]);
|
|
597
|
+
level = LEVEL_ERROR;
|
|
598
|
+
RATE_WINDOW_MS = 6e4;
|
|
599
|
+
RATE_LIMIT_PER_WINDOW = 100;
|
|
600
|
+
RATE_LIMIT_PER_WINDOW_DEBUG = 1e3;
|
|
601
|
+
rateBuckets = /* @__PURE__ */ new Map();
|
|
602
|
+
LOCAL_LOG_WINDOW_MS = 6e4;
|
|
603
|
+
LOCAL_LOG_LIMIT_PER_WINDOW = 10;
|
|
604
|
+
localLogBuckets = /* @__PURE__ */ new Map();
|
|
605
|
+
MAX_STACK_ENTRIES = 64;
|
|
606
|
+
MAX_MESSAGE_CHARS = 4096;
|
|
607
|
+
MAX_BATCH_EVENTS = 32;
|
|
608
|
+
ALLOWED_EXTRA_KEYS = /* @__PURE__ */ new Set([
|
|
609
|
+
"adapter",
|
|
610
|
+
"module",
|
|
611
|
+
"function",
|
|
612
|
+
"operation",
|
|
613
|
+
"endpoint_host"
|
|
614
|
+
]);
|
|
615
|
+
DIAGNOSTICS_PATH = "/api/v1/diagnostics/sdk";
|
|
616
|
+
MAX_PENDING = 100;
|
|
617
|
+
FLUSH_INTERVAL_MS = 5e3;
|
|
618
|
+
BREAKER_THRESHOLD = 3;
|
|
619
|
+
BREAKER_COOLDOWN_MS = 3e5;
|
|
620
|
+
exports.REASON_QUEUE_FULL = "queue_full";
|
|
621
|
+
exports.REASON_RETRY_EXHAUSTED = "retry_exhausted";
|
|
622
|
+
exports.REASON_QUOTA_REJECTED = "quota_rejected";
|
|
623
|
+
exports.REASON_SHUTDOWN_DROP = "shutdown_drop";
|
|
624
|
+
counters = /* @__PURE__ */ new Map();
|
|
625
|
+
activeRedactionConfig = null;
|
|
626
|
+
pending = [];
|
|
627
|
+
timer = null;
|
|
628
|
+
consecutiveFailures = 0;
|
|
629
|
+
breakerOpenUntil = 0;
|
|
630
|
+
reporting = false;
|
|
631
|
+
MORSE_PATH_MARKERS = ["@morsehq/sdk", "morse-sdk", "/morse/", "morse_ai"];
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
// src/_internal/otel-provider.browser.ts
|
|
636
|
+
function noteBrowserRuntime() {
|
|
637
|
+
if (warned) return;
|
|
638
|
+
warned = true;
|
|
639
|
+
try {
|
|
640
|
+
console.info(
|
|
641
|
+
"[morse] Browser build active: OpenTelemetry span export and database capture are Node-only, so traces are sent via Morse's JSON transport instead. Everything else \u2014 run()/span()/track() and W3C traceparent propagation \u2014 behaves identically. Server-side code (Next.js route handlers, RSC, Node services) automatically gets the full OTel pipeline."
|
|
642
|
+
);
|
|
643
|
+
} catch {
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
function getEngine() {
|
|
647
|
+
return engine;
|
|
648
|
+
}
|
|
649
|
+
function withOtelSpanContext(traceIdHex, spanIdHex, fn) {
|
|
650
|
+
return fn();
|
|
651
|
+
}
|
|
652
|
+
var warned, OtelEngine, engine;
|
|
653
|
+
var init_otel_provider_browser = __esm({
|
|
654
|
+
"src/_internal/otel-provider.browser.ts"() {
|
|
655
|
+
warned = false;
|
|
656
|
+
OtelEngine = class {
|
|
657
|
+
// Params are declared (not dropped) so this class stays signature-compatible
|
|
658
|
+
// with the real `OtelEngine` — the build swaps the modules, but anything
|
|
659
|
+
// type-checking against this one must see the same shape. `void x` marks the
|
|
660
|
+
// deliberate non-use for @typescript-eslint/no-unused-vars.
|
|
661
|
+
configure(opts) {
|
|
662
|
+
noteBrowserRuntime();
|
|
663
|
+
}
|
|
664
|
+
shutdown() {
|
|
665
|
+
}
|
|
666
|
+
resetForTesting() {
|
|
667
|
+
warned = false;
|
|
668
|
+
}
|
|
669
|
+
async flush() {
|
|
670
|
+
}
|
|
671
|
+
resolveSampled(traceIdHex) {
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
registerInstrumentations(instrumentations) {
|
|
675
|
+
return null;
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
engine = new OtelEngine();
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
|
|
358
682
|
// src/_internal/spans.ts
|
|
359
683
|
function generateTraceId() {
|
|
360
684
|
return randomHex(32);
|
|
@@ -423,6 +747,17 @@ function tryLoadAls() {
|
|
|
423
747
|
als = null;
|
|
424
748
|
return als;
|
|
425
749
|
}
|
|
750
|
+
try {
|
|
751
|
+
const getBuiltin = process?.getBuiltinModule;
|
|
752
|
+
if (typeof getBuiltin === "function") {
|
|
753
|
+
const mod = getBuiltin("node:async_hooks");
|
|
754
|
+
if (mod?.AsyncLocalStorage) {
|
|
755
|
+
als = new mod.AsyncLocalStorage();
|
|
756
|
+
return als;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
} catch {
|
|
760
|
+
}
|
|
426
761
|
try {
|
|
427
762
|
const dynamicRequire = Function("m", "return require(m)");
|
|
428
763
|
const mod = dynamicRequire("node:async_hooks");
|
|
@@ -455,8 +790,9 @@ function setTransport(t) {
|
|
|
455
790
|
function getTransport() {
|
|
456
791
|
return transport;
|
|
457
792
|
}
|
|
458
|
-
function
|
|
793
|
+
function setRedactionConfig2(config) {
|
|
459
794
|
redactionConfig = config;
|
|
795
|
+
setRedactionConfig(config);
|
|
460
796
|
}
|
|
461
797
|
function getRedactionConfig() {
|
|
462
798
|
return redactionConfig;
|
|
@@ -545,8 +881,15 @@ function buildTraceDict(state, rootSpan) {
|
|
|
545
881
|
spans: spans.map((s) => redactSpanDict(s, config))
|
|
546
882
|
};
|
|
547
883
|
const effectiveSource = state.sourceOverride || _source;
|
|
884
|
+
const resource = {};
|
|
548
885
|
if (effectiveSource) {
|
|
549
|
-
|
|
886
|
+
resource["morse_ai.source"] = effectiveSource;
|
|
887
|
+
}
|
|
888
|
+
if (state.framework) {
|
|
889
|
+
resource["morse_ai.framework"] = state.framework;
|
|
890
|
+
}
|
|
891
|
+
if (Object.keys(resource).length > 0) {
|
|
892
|
+
out.resource = resource;
|
|
550
893
|
}
|
|
551
894
|
return out;
|
|
552
895
|
}
|
|
@@ -638,16 +981,37 @@ function errToString(e) {
|
|
|
638
981
|
if (e instanceof Error) return e.message;
|
|
639
982
|
return String(e);
|
|
640
983
|
}
|
|
984
|
+
function isThenable(v) {
|
|
985
|
+
return v !== null && (typeof v === "object" || typeof v === "function") && typeof v.then === "function";
|
|
986
|
+
}
|
|
641
987
|
function runSync(opts, fn) {
|
|
642
988
|
const { state, rootSpan, startMono } = startTrace(opts);
|
|
643
989
|
const handle = buildRunHandle(state);
|
|
644
990
|
const store = tryLoadAls();
|
|
645
991
|
const runFn = () => withDbCaptureContext(state.traceId, rootSpan.span_id, () => fn(handle));
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
const result = store.run(state, runFn);
|
|
992
|
+
const settle = (result, onDone) => {
|
|
993
|
+
if (!isThenable(result)) {
|
|
649
994
|
endTrace(state, rootSpan, startMono, void 0);
|
|
995
|
+
onDone();
|
|
650
996
|
return result;
|
|
997
|
+
}
|
|
998
|
+
return result.then(
|
|
999
|
+
(value) => {
|
|
1000
|
+
endTrace(state, rootSpan, startMono, void 0);
|
|
1001
|
+
onDone();
|
|
1002
|
+
return value;
|
|
1003
|
+
},
|
|
1004
|
+
(err) => {
|
|
1005
|
+
endTrace(state, rootSpan, startMono, err);
|
|
1006
|
+
onDone();
|
|
1007
|
+
throw err;
|
|
1008
|
+
}
|
|
1009
|
+
);
|
|
1010
|
+
};
|
|
1011
|
+
if (store) {
|
|
1012
|
+
try {
|
|
1013
|
+
return settle(store.run(state, runFn), () => {
|
|
1014
|
+
});
|
|
651
1015
|
} catch (err) {
|
|
652
1016
|
endTrace(state, rootSpan, startMono, err);
|
|
653
1017
|
throw err;
|
|
@@ -655,14 +1019,11 @@ function runSync(opts, fn) {
|
|
|
655
1019
|
} else {
|
|
656
1020
|
const reset = setActiveTraceState(state);
|
|
657
1021
|
try {
|
|
658
|
-
|
|
659
|
-
endTrace(state, rootSpan, startMono, void 0);
|
|
660
|
-
return result;
|
|
1022
|
+
return settle(runFn(), reset);
|
|
661
1023
|
} catch (err) {
|
|
662
1024
|
endTrace(state, rootSpan, startMono, err);
|
|
663
|
-
throw err;
|
|
664
|
-
} finally {
|
|
665
1025
|
reset();
|
|
1026
|
+
throw err;
|
|
666
1027
|
}
|
|
667
1028
|
}
|
|
668
1029
|
}
|
|
@@ -763,7 +1124,7 @@ async function spanAsync(opts, fn) {
|
|
|
763
1124
|
throw err;
|
|
764
1125
|
}
|
|
765
1126
|
}
|
|
766
|
-
function
|
|
1127
|
+
function _resetForTesting2() {
|
|
767
1128
|
browserState = null;
|
|
768
1129
|
lastTrace = null;
|
|
769
1130
|
redactionConfig = buildRedactionConfig();
|
|
@@ -773,6 +1134,7 @@ var init_tracing = __esm({
|
|
|
773
1134
|
"src/_internal/tracing.ts"() {
|
|
774
1135
|
init_env();
|
|
775
1136
|
init_otel_provider_browser();
|
|
1137
|
+
init_diagnostics();
|
|
776
1138
|
init_redaction();
|
|
777
1139
|
init_spans();
|
|
778
1140
|
als = null;
|
|
@@ -891,6 +1253,7 @@ var init_propagation = __esm({
|
|
|
891
1253
|
});
|
|
892
1254
|
|
|
893
1255
|
exports._resetForTesting = _resetForTesting;
|
|
1256
|
+
exports._resetForTesting2 = _resetForTesting2;
|
|
894
1257
|
exports.buildRedactionConfig = buildRedactionConfig;
|
|
895
1258
|
exports.buildTraceEntry = buildTraceEntry;
|
|
896
1259
|
exports.extractTraceparent = extractTraceparent;
|
|
@@ -910,6 +1273,7 @@ exports.getMaxQueueSize = getMaxQueueSize;
|
|
|
910
1273
|
exports.getRedactionConfig = getRedactionConfig;
|
|
911
1274
|
exports.getSampleRate = getSampleRate;
|
|
912
1275
|
exports.getTransport = getTransport;
|
|
1276
|
+
exports.init_diagnostics = init_diagnostics;
|
|
913
1277
|
exports.init_env = init_env;
|
|
914
1278
|
exports.init_otel_provider_browser = init_otel_provider_browser;
|
|
915
1279
|
exports.init_propagation = init_propagation;
|
|
@@ -918,21 +1282,22 @@ exports.init_spans = init_spans;
|
|
|
918
1282
|
exports.init_tracing = init_tracing;
|
|
919
1283
|
exports.injectIntoRequestInit = injectIntoRequestInit;
|
|
920
1284
|
exports.injectTraceparent = injectTraceparent;
|
|
921
|
-
exports.isDebug = isDebug;
|
|
922
1285
|
exports.isDisabled = isDisabled;
|
|
923
|
-
exports.isTelemetryDisabled = isTelemetryDisabled;
|
|
924
1286
|
exports.isValidInternalSource = isValidInternalSource;
|
|
925
1287
|
exports.nowIso = nowIso;
|
|
1288
|
+
exports.recordDrop = recordDrop;
|
|
926
1289
|
exports.redactValue = redactValue;
|
|
1290
|
+
exports.report = report;
|
|
927
1291
|
exports.runAsync = runAsync;
|
|
928
1292
|
exports.runSync = runSync;
|
|
929
1293
|
exports.sendTrace = sendTrace;
|
|
930
1294
|
exports.setContext = setContext;
|
|
931
|
-
exports.
|
|
1295
|
+
exports.setLevel = setLevel;
|
|
1296
|
+
exports.setRedactionConfig = setRedactionConfig2;
|
|
932
1297
|
exports.setSource = setSource;
|
|
933
1298
|
exports.setTransport = setTransport;
|
|
934
1299
|
exports.spanAsync = spanAsync;
|
|
935
1300
|
exports.spanSync = spanSync;
|
|
936
1301
|
exports.startSpan = startSpan;
|
|
937
|
-
//# sourceMappingURL=chunk-
|
|
938
|
-
//# sourceMappingURL=chunk-
|
|
1302
|
+
//# sourceMappingURL=chunk-A5EYWAOT.cjs.map
|
|
1303
|
+
//# sourceMappingURL=chunk-A5EYWAOT.cjs.map
|