neatlogs 1.1.1 → 1.1.4
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/README.md +2 -2
- package/dist/anthropic.cjs +68 -2
- package/dist/anthropic.cjs.map +1 -1
- package/dist/anthropic.mjs +68 -2
- package/dist/anthropic.mjs.map +1 -1
- package/dist/azure-openai.cjs +68 -2
- package/dist/azure-openai.cjs.map +1 -1
- package/dist/azure-openai.mjs +68 -2
- package/dist/azure-openai.mjs.map +1 -1
- package/dist/bedrock.cjs +68 -2
- package/dist/bedrock.cjs.map +1 -1
- package/dist/bedrock.mjs +68 -2
- package/dist/bedrock.mjs.map +1 -1
- package/dist/browser.cjs +22 -12
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +29 -11
- package/dist/browser.mjs +22 -12
- package/dist/browser.mjs.map +1 -1
- package/dist/index.cjs +260 -414
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +38 -19
- package/dist/index.mjs +259 -414
- package/dist/index.mjs.map +1 -1
- package/dist/langchain.cjs +68 -2
- package/dist/langchain.cjs.map +1 -1
- package/dist/langchain.mjs +68 -2
- package/dist/langchain.mjs.map +1 -1
- package/dist/openai.cjs +68 -2
- package/dist/openai.cjs.map +1 -1
- package/dist/openai.mjs +68 -2
- package/dist/openai.mjs.map +1 -1
- package/dist/opencode-plugin.cjs +2 -2
- package/dist/opencode-plugin.cjs.map +1 -1
- package/dist/opencode-plugin.d.ts +1 -1
- package/dist/opencode-plugin.mjs +2 -2
- package/dist/opencode-plugin.mjs.map +1 -1
- package/dist/openrouter-agent.cjs +68 -2
- package/dist/openrouter-agent.cjs.map +1 -1
- package/dist/openrouter-agent.mjs +68 -2
- package/dist/openrouter-agent.mjs.map +1 -1
- package/dist/vertex-ai.cjs +68 -2
- package/dist/vertex-ai.cjs.map +1 -1
- package/dist/vertex-ai.mjs +68 -2
- package/dist/vertex-ai.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -49,6 +49,7 @@ __export(index_exports, {
|
|
|
49
49
|
getMastraObservability: () => getMastraObservability,
|
|
50
50
|
getPrompt: () => getPrompt,
|
|
51
51
|
getSessionConfig: () => getSessionConfig,
|
|
52
|
+
identify: () => identify,
|
|
52
53
|
init: () => init,
|
|
53
54
|
isDebugEnabled: () => isDebugEnabled,
|
|
54
55
|
langchainHandler: () => langchainHandler,
|
|
@@ -84,8 +85,7 @@ __export(index_exports, {
|
|
|
84
85
|
module.exports = __toCommonJS(index_exports);
|
|
85
86
|
|
|
86
87
|
// src/init.ts
|
|
87
|
-
var
|
|
88
|
-
var path3 = __toESM(require("path"));
|
|
88
|
+
var path2 = __toESM(require("path"));
|
|
89
89
|
var import_api8 = require("@opentelemetry/api");
|
|
90
90
|
var import_api_logs = require("@opentelemetry/api-logs");
|
|
91
91
|
var import_resources = require("@opentelemetry/resources");
|
|
@@ -2217,9 +2217,84 @@ function applyMask(spanData, globalMask) {
|
|
|
2217
2217
|
}
|
|
2218
2218
|
}
|
|
2219
2219
|
|
|
2220
|
-
// src/
|
|
2220
|
+
// src/core/identity.ts
|
|
2221
2221
|
var import_node_async_hooks = require("async_hooks");
|
|
2222
|
-
var
|
|
2222
|
+
var _GLOBAL_KEY = /* @__PURE__ */ Symbol.for("neatlogs.identity.storage");
|
|
2223
|
+
var _g = globalThis;
|
|
2224
|
+
var _storage = _g[_GLOBAL_KEY] ?? (_g[_GLOBAL_KEY] = new import_node_async_hooks.AsyncLocalStorage());
|
|
2225
|
+
function currentSessionId() {
|
|
2226
|
+
return _storage.getStore()?.sessionId;
|
|
2227
|
+
}
|
|
2228
|
+
function currentEndUserId() {
|
|
2229
|
+
return _storage.getStore()?.endUserId;
|
|
2230
|
+
}
|
|
2231
|
+
function currentEndUserMetadata() {
|
|
2232
|
+
return _storage.getStore()?.endUserMetadata;
|
|
2233
|
+
}
|
|
2234
|
+
function identify(opts, fn) {
|
|
2235
|
+
const prev = _storage.getStore();
|
|
2236
|
+
const next = { ...prev ?? {} };
|
|
2237
|
+
if (opts.sessionId !== void 0) next.sessionId = opts.sessionId;
|
|
2238
|
+
if (opts.endUserId !== void 0) next.endUserId = opts.endUserId;
|
|
2239
|
+
if (opts.endUserMetadata !== void 0) next.endUserMetadata = opts.endUserMetadata;
|
|
2240
|
+
return _storage.run(next, fn);
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2243
|
+
// src/core/session.ts
|
|
2244
|
+
var logger4 = getLogger();
|
|
2245
|
+
var SESSION_ID_KEY = "neatlogs.session.id";
|
|
2246
|
+
function applySessionAttributes(span2, sessionId, isRoot = true) {
|
|
2247
|
+
const resolved = isRoot ? sessionId ?? currentSessionId() : sessionId;
|
|
2248
|
+
if (!resolved) return;
|
|
2249
|
+
if (!isRoot) {
|
|
2250
|
+
logger4.debug(
|
|
2251
|
+
"[session] Ignoring sessionId on a non-root span \u2014 declare it on the trace root (top-level trace()/span()) or identify()."
|
|
2252
|
+
);
|
|
2253
|
+
return;
|
|
2254
|
+
}
|
|
2255
|
+
span2.setAttribute(SESSION_ID_KEY, String(resolved));
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
// src/core/end-user.ts
|
|
2259
|
+
var import_api = require("@opentelemetry/api");
|
|
2260
|
+
var logger5 = getLogger();
|
|
2261
|
+
var END_USER_ID_KEY = "neatlogs.end_user.id";
|
|
2262
|
+
var END_USER_METADATA_KEY = "neatlogs.end_user.metadata";
|
|
2263
|
+
function normalizeEndUserMetadata(metadata) {
|
|
2264
|
+
if (metadata === void 0 || metadata === null) return void 0;
|
|
2265
|
+
if (typeof metadata === "string") return metadata || void 0;
|
|
2266
|
+
try {
|
|
2267
|
+
return JSON.stringify(metadata);
|
|
2268
|
+
} catch {
|
|
2269
|
+
return JSON.stringify(String(metadata));
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
function isRootSpan() {
|
|
2273
|
+
const current = import_api.trace.getSpan(import_api.context.active());
|
|
2274
|
+
return !(current && current.isRecording());
|
|
2275
|
+
}
|
|
2276
|
+
function applyEndUserAttributes(span2, endUserId, endUserMetadata, isRoot = true) {
|
|
2277
|
+
const resolvedId = isRoot ? endUserId ?? currentEndUserId() : endUserId;
|
|
2278
|
+
const resolvedMeta = isRoot ? endUserMetadata ?? currentEndUserMetadata() : endUserMetadata;
|
|
2279
|
+
if (!resolvedId && !resolvedMeta) return;
|
|
2280
|
+
if (!isRoot) {
|
|
2281
|
+
logger5.debug(
|
|
2282
|
+
"[end_user] Ignoring endUserId/endUserMetadata on a non-root span \u2014 declare it on the trace root (top-level trace()/span()) or identify()."
|
|
2283
|
+
);
|
|
2284
|
+
return;
|
|
2285
|
+
}
|
|
2286
|
+
if (resolvedId) {
|
|
2287
|
+
span2.setAttribute(END_USER_ID_KEY, String(resolvedId));
|
|
2288
|
+
}
|
|
2289
|
+
const metaJson = normalizeEndUserMetadata(resolvedMeta);
|
|
2290
|
+
if (metaJson) {
|
|
2291
|
+
span2.setAttribute(END_USER_METADATA_KEY, metaJson);
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
// src/prompt/template.ts
|
|
2296
|
+
var import_node_async_hooks2 = require("async_hooks");
|
|
2297
|
+
var _promptStorage = new import_node_async_hooks2.AsyncLocalStorage();
|
|
2223
2298
|
var PromptContext = class {
|
|
2224
2299
|
/**
|
|
2225
2300
|
* Store system prompt template and variables in context.
|
|
@@ -2246,7 +2321,7 @@ var PromptContext = class {
|
|
|
2246
2321
|
_promptStorage.enterWith(void 0);
|
|
2247
2322
|
}
|
|
2248
2323
|
};
|
|
2249
|
-
var _userPromptStorage = new
|
|
2324
|
+
var _userPromptStorage = new import_node_async_hooks2.AsyncLocalStorage();
|
|
2250
2325
|
var UserPromptContext = class {
|
|
2251
2326
|
/**
|
|
2252
2327
|
* Store user prompt template and variables in context.
|
|
@@ -2372,44 +2447,9 @@ var UserPromptTemplate = class extends BasePromptTemplate {
|
|
|
2372
2447
|
// src/core/context.ts
|
|
2373
2448
|
var import_api3 = require("@opentelemetry/api");
|
|
2374
2449
|
|
|
2375
|
-
// src/core/end-user.ts
|
|
2376
|
-
var import_api = require("@opentelemetry/api");
|
|
2377
|
-
var logger4 = getLogger();
|
|
2378
|
-
var END_USER_ID_KEY = "neatlogs.end_user.id";
|
|
2379
|
-
var END_USER_METADATA_KEY = "neatlogs.end_user.metadata";
|
|
2380
|
-
function normalizeEndUserMetadata(metadata) {
|
|
2381
|
-
if (metadata === void 0 || metadata === null) return void 0;
|
|
2382
|
-
if (typeof metadata === "string") return metadata || void 0;
|
|
2383
|
-
try {
|
|
2384
|
-
return JSON.stringify(metadata);
|
|
2385
|
-
} catch {
|
|
2386
|
-
return JSON.stringify(String(metadata));
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
function isRootSpan() {
|
|
2390
|
-
const current = import_api.trace.getSpan(import_api.context.active());
|
|
2391
|
-
return !(current && current.isRecording());
|
|
2392
|
-
}
|
|
2393
|
-
function applyEndUserAttributes(span2, endUserId, endUserMetadata, isRoot = true) {
|
|
2394
|
-
if (!endUserId && !endUserMetadata) return;
|
|
2395
|
-
if (!isRoot) {
|
|
2396
|
-
logger4.debug(
|
|
2397
|
-
"[end_user] Ignoring endUserId/endUserMetadata on a non-root span \u2014 declare it on the trace root (top-level trace()/span()) or init()."
|
|
2398
|
-
);
|
|
2399
|
-
return;
|
|
2400
|
-
}
|
|
2401
|
-
if (endUserId) {
|
|
2402
|
-
span2.setAttribute(END_USER_ID_KEY, String(endUserId));
|
|
2403
|
-
}
|
|
2404
|
-
const metaJson = normalizeEndUserMetadata(endUserMetadata);
|
|
2405
|
-
if (metaJson) {
|
|
2406
|
-
span2.setAttribute(END_USER_METADATA_KEY, metaJson);
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
|
|
2410
2450
|
// src/decorators/base.ts
|
|
2411
2451
|
var import_api2 = require("@opentelemetry/api");
|
|
2412
|
-
var
|
|
2452
|
+
var logger6 = getLogger();
|
|
2413
2453
|
var TRACER_NAME = "neatlogs";
|
|
2414
2454
|
function safeJsonDumps(value) {
|
|
2415
2455
|
try {
|
|
@@ -2468,13 +2508,14 @@ function decorateSpan(opts, fn) {
|
|
|
2468
2508
|
return tracer.startActiveSpan(spanName, (span2) => {
|
|
2469
2509
|
try {
|
|
2470
2510
|
setCommonSpanAttrs(span2, opts);
|
|
2511
|
+
applySessionAttributes(span2, opts.sessionId, isRoot);
|
|
2471
2512
|
applyEndUserAttributes(span2, opts.endUserId, opts.endUserMetadata, isRoot);
|
|
2472
2513
|
if (captureInput && doCapture && args.length > 0) {
|
|
2473
2514
|
try {
|
|
2474
2515
|
const inputValue = args.length === 1 ? serializeObj(args[0]) : args.map(serializeObj);
|
|
2475
2516
|
span2.setAttribute("input.value", safeJsonDumps(inputValue));
|
|
2476
2517
|
} catch (err) {
|
|
2477
|
-
|
|
2518
|
+
logger6.debug(`Failed to capture input: ${err}`);
|
|
2478
2519
|
}
|
|
2479
2520
|
}
|
|
2480
2521
|
const result = fn(...args);
|
|
@@ -2484,7 +2525,7 @@ function decorateSpan(opts, fn) {
|
|
|
2484
2525
|
try {
|
|
2485
2526
|
span2.setAttribute("output.value", safeJsonDumps(serializeObj(resolved)));
|
|
2486
2527
|
} catch (err) {
|
|
2487
|
-
|
|
2528
|
+
logger6.debug(`Failed to capture output: ${err}`);
|
|
2488
2529
|
}
|
|
2489
2530
|
}
|
|
2490
2531
|
if (opts.postprocessResult) {
|
|
@@ -2492,7 +2533,7 @@ function decorateSpan(opts, fn) {
|
|
|
2492
2533
|
const boundInputs = _extractBoundInputs(fn, args);
|
|
2493
2534
|
opts.postprocessResult(span2, resolved, boundInputs);
|
|
2494
2535
|
} catch (err) {
|
|
2495
|
-
|
|
2536
|
+
logger6.debug(`Postprocess failed: ${err}`);
|
|
2496
2537
|
}
|
|
2497
2538
|
}
|
|
2498
2539
|
span2.setStatus({ code: import_api2.SpanStatusCode.OK });
|
|
@@ -2512,7 +2553,7 @@ function decorateSpan(opts, fn) {
|
|
|
2512
2553
|
try {
|
|
2513
2554
|
span2.setAttribute("output.value", safeJsonDumps(serializeObj(result)));
|
|
2514
2555
|
} catch (err) {
|
|
2515
|
-
|
|
2556
|
+
logger6.debug(`Failed to capture output: ${err}`);
|
|
2516
2557
|
}
|
|
2517
2558
|
}
|
|
2518
2559
|
if (opts.postprocessResult) {
|
|
@@ -2520,7 +2561,7 @@ function decorateSpan(opts, fn) {
|
|
|
2520
2561
|
const boundInputs = _extractBoundInputs(fn, args);
|
|
2521
2562
|
opts.postprocessResult(span2, result, boundInputs);
|
|
2522
2563
|
} catch (err) {
|
|
2523
|
-
|
|
2564
|
+
logger6.debug(`Postprocess failed: ${err}`);
|
|
2524
2565
|
}
|
|
2525
2566
|
}
|
|
2526
2567
|
span2.setStatus({ code: import_api2.SpanStatusCode.OK });
|
|
@@ -2554,7 +2595,7 @@ function _extractBoundInputs(fn, args) {
|
|
|
2554
2595
|
}
|
|
2555
2596
|
|
|
2556
2597
|
// src/core/context.ts
|
|
2557
|
-
var
|
|
2598
|
+
var logger7 = getLogger();
|
|
2558
2599
|
var _sessionConfig = {};
|
|
2559
2600
|
function _setSessionConfig(config) {
|
|
2560
2601
|
_sessionConfig = config;
|
|
@@ -2578,6 +2619,7 @@ var KNOWN_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
|
2578
2619
|
"version",
|
|
2579
2620
|
"mask",
|
|
2580
2621
|
"attributes",
|
|
2622
|
+
"sessionId",
|
|
2581
2623
|
"endUserId",
|
|
2582
2624
|
"endUserMetadata"
|
|
2583
2625
|
]);
|
|
@@ -2596,7 +2638,7 @@ function _finalizePromptCapture(span2, isPromptTemplateObj, isUserPromptTemplate
|
|
|
2596
2638
|
"llm.prompt_template_variables",
|
|
2597
2639
|
JSON.stringify(capturedVars)
|
|
2598
2640
|
);
|
|
2599
|
-
|
|
2641
|
+
logger7.debug(
|
|
2600
2642
|
`[trace] Auto-captured variables from PromptContext: ${Object.keys(capturedVars).join(", ")}`
|
|
2601
2643
|
);
|
|
2602
2644
|
}
|
|
@@ -2608,7 +2650,7 @@ function _finalizePromptCapture(span2, isPromptTemplateObj, isUserPromptTemplate
|
|
|
2608
2650
|
"llm.user_prompt_template_variables",
|
|
2609
2651
|
JSON.stringify(capturedUserVars)
|
|
2610
2652
|
);
|
|
2611
|
-
|
|
2653
|
+
logger7.debug(
|
|
2612
2654
|
`[trace] Auto-captured variables from UserPromptContext: ${Object.keys(capturedUserVars).join(", ")}`
|
|
2613
2655
|
);
|
|
2614
2656
|
}
|
|
@@ -2625,13 +2667,13 @@ async function trace2(options, fn) {
|
|
|
2625
2667
|
userPromptVariables,
|
|
2626
2668
|
version,
|
|
2627
2669
|
mask,
|
|
2670
|
+
sessionId: sessionIdOption,
|
|
2628
2671
|
endUserId,
|
|
2629
2672
|
endUserMetadata,
|
|
2630
2673
|
attributes: explicitAttributes,
|
|
2631
2674
|
...extraOptions
|
|
2632
2675
|
} = options;
|
|
2633
|
-
const
|
|
2634
|
-
const sessionId = sessionConfig.sessionId;
|
|
2676
|
+
const sessionId = sessionIdOption ?? currentSessionId();
|
|
2635
2677
|
const currentSpan = import_api3.trace.getSpan(import_api3.context.active());
|
|
2636
2678
|
const isInActiveTrace = currentSpan !== void 0 && currentSpan.isRecording();
|
|
2637
2679
|
const shouldCreateRootTrace = !!sessionId && !isInActiveTrace;
|
|
@@ -2642,7 +2684,7 @@ async function trace2(options, fn) {
|
|
|
2642
2684
|
isPromptTemplateObj = true;
|
|
2643
2685
|
const t = promptTemplate.template;
|
|
2644
2686
|
templateString = typeof t === "string" ? t : JSON.stringify(t);
|
|
2645
|
-
|
|
2687
|
+
logger7.debug(
|
|
2646
2688
|
`[trace] Using PromptTemplate object with variables: ${promptTemplate.variables.join(", ")}`
|
|
2647
2689
|
);
|
|
2648
2690
|
} else if (typeof promptTemplate === "string") {
|
|
@@ -2659,7 +2701,7 @@ async function trace2(options, fn) {
|
|
|
2659
2701
|
isUserPromptTemplateObj = true;
|
|
2660
2702
|
const t = userPromptTemplate.template;
|
|
2661
2703
|
userTemplateString = typeof t === "string" ? t : JSON.stringify(t);
|
|
2662
|
-
|
|
2704
|
+
logger7.debug(
|
|
2663
2705
|
`[trace] Using UserPromptTemplate object with variables: ${userPromptTemplate.variables.join(", ")}`
|
|
2664
2706
|
);
|
|
2665
2707
|
} else if (typeof userPromptTemplate === "string") {
|
|
@@ -2674,23 +2716,23 @@ async function trace2(options, fn) {
|
|
|
2674
2716
|
const userVariablesJson = userPromptVariables ? JSON.stringify(userPromptVariables) : void 0;
|
|
2675
2717
|
if (variablesJson) {
|
|
2676
2718
|
ctx = ctx.setValue(PROMPT_VARIABLES_KEY, variablesJson);
|
|
2677
|
-
|
|
2719
|
+
logger7.debug(`[trace] Set neatlogs.prompt_variables in context: ${variablesJson}`);
|
|
2678
2720
|
}
|
|
2679
2721
|
if (templateString) {
|
|
2680
2722
|
ctx = ctx.setValue(PROMPT_TEMPLATE_KEY, templateString);
|
|
2681
|
-
|
|
2723
|
+
logger7.debug(`[trace] Set neatlogs.prompt_template in context: ${templateString}`);
|
|
2682
2724
|
}
|
|
2683
2725
|
if (userVariablesJson) {
|
|
2684
2726
|
ctx = ctx.setValue(USER_PROMPT_VARIABLES_KEY, userVariablesJson);
|
|
2685
|
-
|
|
2727
|
+
logger7.debug(`[trace] Set neatlogs.user_prompt_variables in context: ${userVariablesJson}`);
|
|
2686
2728
|
}
|
|
2687
2729
|
if (userTemplateString) {
|
|
2688
2730
|
ctx = ctx.setValue(USER_PROMPT_TEMPLATE_KEY, userTemplateString);
|
|
2689
|
-
|
|
2731
|
+
logger7.debug(`[trace] Set neatlogs.user_prompt_template in context: ${userTemplateString}`);
|
|
2690
2732
|
}
|
|
2691
2733
|
if (version) {
|
|
2692
2734
|
ctx = ctx.setValue(PROMPT_VERSION_KEY, version);
|
|
2693
|
-
|
|
2735
|
+
logger7.debug(`[trace] Set neatlogs.prompt_version in context: ${version}`);
|
|
2694
2736
|
}
|
|
2695
2737
|
const extraAttributes = { ...explicitAttributes ?? {} };
|
|
2696
2738
|
for (const [key, value] of Object.entries(extraOptions)) {
|
|
@@ -2702,6 +2744,7 @@ async function trace2(options, fn) {
|
|
|
2702
2744
|
const tracer = import_api3.trace.getTracer("neatlogs.trace");
|
|
2703
2745
|
const spanCallback = async (span2) => {
|
|
2704
2746
|
_setSpanAttributes(span2, kind, extraAttributes);
|
|
2747
|
+
applySessionAttributes(span2, sessionId, isRootTrace);
|
|
2705
2748
|
applyEndUserAttributes(span2, endUserId, endUserMetadata, isRootTrace);
|
|
2706
2749
|
if (input !== void 0 && input !== null) {
|
|
2707
2750
|
span2.setAttribute("input.value", safeJsonDumps(serializeObj(input)));
|
|
@@ -2741,23 +2784,23 @@ async function trace2(options, fn) {
|
|
|
2741
2784
|
}
|
|
2742
2785
|
};
|
|
2743
2786
|
if (shouldCreateRootTrace) {
|
|
2744
|
-
|
|
2787
|
+
logger7.debug(`[trace] Creating NEW root trace '${name}' (sessionId=${sessionId})`);
|
|
2745
2788
|
return tracer.startActiveSpan(name, {}, import_api3.ROOT_CONTEXT, spanCallback);
|
|
2746
2789
|
} else {
|
|
2747
|
-
|
|
2790
|
+
logger7.debug(`[trace] Creating child span '${name}'`);
|
|
2748
2791
|
return tracer.startActiveSpan(name, {}, ctx, spanCallback);
|
|
2749
2792
|
}
|
|
2750
2793
|
}
|
|
2751
2794
|
|
|
2752
2795
|
// src/core/crewai-task-registry.ts
|
|
2753
|
-
var
|
|
2796
|
+
var logger8 = getLogger();
|
|
2754
2797
|
var _registry = /* @__PURE__ */ new Map();
|
|
2755
2798
|
function registerCrewaiTask(task, userTpl, vars) {
|
|
2756
2799
|
const taskId = String(task.id);
|
|
2757
2800
|
const tplStr = String(userTpl.template);
|
|
2758
2801
|
const varsJson = vars && Object.keys(vars).length > 0 ? JSON.stringify(vars, (_key, val) => typeof val === "undefined" ? null : val) : null;
|
|
2759
2802
|
_registry.set(taskId, [tplStr, varsJson]);
|
|
2760
|
-
|
|
2803
|
+
logger8.debug(`Registered CrewAI task ${taskId}`);
|
|
2761
2804
|
}
|
|
2762
2805
|
function popEntry(taskId) {
|
|
2763
2806
|
const entry = _registry.get(taskId);
|
|
@@ -3899,7 +3942,7 @@ var attribute_mapping_default = {
|
|
|
3899
3942
|
};
|
|
3900
3943
|
|
|
3901
3944
|
// src/config/attribute-mapper.ts
|
|
3902
|
-
var
|
|
3945
|
+
var logger9 = getLogger();
|
|
3903
3946
|
function flattenSources(sources) {
|
|
3904
3947
|
if (!sources) return [];
|
|
3905
3948
|
if (Array.isArray(sources)) return sources;
|
|
@@ -4220,7 +4263,7 @@ var AttributeMapper = class {
|
|
|
4220
4263
|
};
|
|
4221
4264
|
|
|
4222
4265
|
// src/core/span-processor.ts
|
|
4223
|
-
var
|
|
4266
|
+
var logger10 = getLogger();
|
|
4224
4267
|
function resolveLogFilePath(configuredPath) {
|
|
4225
4268
|
return path.isAbsolute(configuredPath) ? configuredPath : path.join(process.cwd(), configuredPath);
|
|
4226
4269
|
}
|
|
@@ -4233,7 +4276,7 @@ function createLogStream(configuredPath) {
|
|
|
4233
4276
|
const stream = fs.createWriteStream(logPath, { fd, autoClose: true });
|
|
4234
4277
|
fd = null;
|
|
4235
4278
|
stream.on("error", (error) => {
|
|
4236
|
-
|
|
4279
|
+
logger10.warn(`Failed to write span log file ${logPath}: ${error}`);
|
|
4237
4280
|
stream.destroy();
|
|
4238
4281
|
});
|
|
4239
4282
|
return stream;
|
|
@@ -4244,7 +4287,7 @@ function createLogStream(configuredPath) {
|
|
|
4244
4287
|
} catch {
|
|
4245
4288
|
}
|
|
4246
4289
|
}
|
|
4247
|
-
|
|
4290
|
+
logger10.warn(`Failed to open span log file ${logPath}: ${error}`);
|
|
4248
4291
|
return null;
|
|
4249
4292
|
}
|
|
4250
4293
|
}
|
|
@@ -4253,7 +4296,7 @@ async function closeLogStream(stream, description) {
|
|
|
4253
4296
|
if (!stream || stream.destroyed || stream.writableEnded) {
|
|
4254
4297
|
return;
|
|
4255
4298
|
}
|
|
4256
|
-
await new Promise((
|
|
4299
|
+
await new Promise((resolve) => {
|
|
4257
4300
|
let settled = false;
|
|
4258
4301
|
const settle = () => {
|
|
4259
4302
|
if (settled) return;
|
|
@@ -4261,15 +4304,15 @@ async function closeLogStream(stream, description) {
|
|
|
4261
4304
|
clearTimeout(timer);
|
|
4262
4305
|
stream.off("close", closeHandler);
|
|
4263
4306
|
stream.off("error", errorHandler);
|
|
4264
|
-
|
|
4307
|
+
resolve();
|
|
4265
4308
|
};
|
|
4266
4309
|
const closeHandler = settle;
|
|
4267
4310
|
const errorHandler = (error) => {
|
|
4268
|
-
|
|
4311
|
+
logger10.warn(`Failed to close ${description} log file handle: ${error}`);
|
|
4269
4312
|
settle();
|
|
4270
4313
|
};
|
|
4271
4314
|
const timer = setTimeout(() => {
|
|
4272
|
-
|
|
4315
|
+
logger10.warn(
|
|
4273
4316
|
`Timed out waiting for ${description} log stream to close; destroying`
|
|
4274
4317
|
);
|
|
4275
4318
|
stream.destroy();
|
|
@@ -4280,7 +4323,7 @@ async function closeLogStream(stream, description) {
|
|
|
4280
4323
|
try {
|
|
4281
4324
|
stream.end();
|
|
4282
4325
|
} catch (error) {
|
|
4283
|
-
|
|
4326
|
+
logger10.warn(`Failed to close ${description} log file handle: ${error}`);
|
|
4284
4327
|
settle();
|
|
4285
4328
|
}
|
|
4286
4329
|
});
|
|
@@ -4359,7 +4402,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
4359
4402
|
const rawPath = process.env.NEATLOGS_LOG_RAW_SPANS_FILE ?? "spans_raw_optimized.log";
|
|
4360
4403
|
this._rawLogStream = createLogStream(rawPath);
|
|
4361
4404
|
if (this._rawLogStream) {
|
|
4362
|
-
|
|
4405
|
+
logger10.info(
|
|
4363
4406
|
`Raw span logging enabled: ${resolveLogFilePath(rawPath)}`
|
|
4364
4407
|
);
|
|
4365
4408
|
}
|
|
@@ -4371,7 +4414,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
4371
4414
|
const processedPath = process.env.NEATLOGS_LOG_SPANS_FILE ?? "spans_optimized.log";
|
|
4372
4415
|
this._processedLogStream = createLogStream(processedPath);
|
|
4373
4416
|
if (this._processedLogStream) {
|
|
4374
|
-
|
|
4417
|
+
logger10.info(
|
|
4375
4418
|
`Processed span logging enabled: ${resolveLogFilePath(processedPath)}`
|
|
4376
4419
|
);
|
|
4377
4420
|
}
|
|
@@ -4381,6 +4424,10 @@ var NeatlogsSpanProcessor = class {
|
|
|
4381
4424
|
onStart(span2, parentContext) {
|
|
4382
4425
|
const startTime = import_node_perf_hooks.performance.now();
|
|
4383
4426
|
try {
|
|
4427
|
+
if (!span2.parentSpanId) {
|
|
4428
|
+
applySessionAttributes(span2, void 0, true);
|
|
4429
|
+
applyEndUserAttributes(span2, void 0, void 0, true);
|
|
4430
|
+
}
|
|
4384
4431
|
const attrs = span2.attributes ?? {};
|
|
4385
4432
|
const spanKind = attrs["openinference.span.kind"];
|
|
4386
4433
|
const spanName = typeof span2.name === "string" ? span2.name : "";
|
|
@@ -4417,14 +4464,14 @@ var NeatlogsSpanProcessor = class {
|
|
|
4417
4464
|
}
|
|
4418
4465
|
}
|
|
4419
4466
|
if (this.debug) {
|
|
4420
|
-
|
|
4467
|
+
logger10.debug(
|
|
4421
4468
|
`[SpanProcessor.onStart] LLM span '${spanName}' starting`
|
|
4422
4469
|
);
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4470
|
+
logger10.debug(` variables_json from context: ${variablesJson}`);
|
|
4471
|
+
logger10.debug(` template from context: ${template}`);
|
|
4472
|
+
logger10.debug(` version from context: ${versionVal}`);
|
|
4473
|
+
logger10.debug(` user_template from context: ${userTemplate}`);
|
|
4474
|
+
logger10.debug(
|
|
4428
4475
|
` user_variables_json from context: ${userVariablesJson}`
|
|
4429
4476
|
);
|
|
4430
4477
|
}
|
|
@@ -4459,7 +4506,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
4459
4506
|
this.perfStats.spansProcessed += 1;
|
|
4460
4507
|
try {
|
|
4461
4508
|
if (this.debug) {
|
|
4462
|
-
|
|
4509
|
+
logger10.debug(`[SpanProcessor.onEnd] Span ending: ${span2.name}`);
|
|
4463
4510
|
}
|
|
4464
4511
|
if (this._rawLogStream && !this._rawLogStream.destroyed) {
|
|
4465
4512
|
try {
|
|
@@ -4467,7 +4514,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
4467
4514
|
JSON.stringify(spanToDict(span2)) + "\n"
|
|
4468
4515
|
);
|
|
4469
4516
|
} catch (e) {
|
|
4470
|
-
|
|
4517
|
+
logger10.warn(`Failed to write span to raw log file: ${e}`);
|
|
4471
4518
|
}
|
|
4472
4519
|
}
|
|
4473
4520
|
if (this.sampleRate < 1 && Math.random() > this.sampleRate) {
|
|
@@ -4490,7 +4537,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
4490
4537
|
delete unifiedAttrs[key];
|
|
4491
4538
|
}
|
|
4492
4539
|
if (this.debug && keysToRemove.length > 0) {
|
|
4493
|
-
|
|
4540
|
+
logger10.debug(
|
|
4494
4541
|
`[EMBEDDING Filter] Removed ${keysToRemove.length} large attribute keys from ${nlKind} span (skip_output=${skipOutput})`
|
|
4495
4542
|
);
|
|
4496
4543
|
}
|
|
@@ -4517,7 +4564,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
4517
4564
|
this._retrieversToSuppress.delete(spanId2);
|
|
4518
4565
|
unifiedAttrs["neatlogs.internal"] = true;
|
|
4519
4566
|
if (this.debug) {
|
|
4520
|
-
|
|
4567
|
+
logger10.debug(
|
|
4521
4568
|
`[Retriever Merge] Marked OI retriever '${span2.name}' as internal (had neatlogs retriever child)`
|
|
4522
4569
|
);
|
|
4523
4570
|
}
|
|
@@ -4535,7 +4582,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
4535
4582
|
}
|
|
4536
4583
|
}
|
|
4537
4584
|
if (this.debug && "neatlogs.tags" in resourceAttrs) {
|
|
4538
|
-
|
|
4585
|
+
logger10.debug(
|
|
4539
4586
|
`[Tags] Span ${span2.name}: resource.neatlogs.tags = ${resourceAttrs["neatlogs.tags"]}`
|
|
4540
4587
|
);
|
|
4541
4588
|
}
|
|
@@ -4545,7 +4592,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
4545
4592
|
let parentSpanId = span2.parentSpanId ?? null;
|
|
4546
4593
|
if (parentSpanId === spanId) {
|
|
4547
4594
|
if (this.debug) {
|
|
4548
|
-
|
|
4595
|
+
logger10.warn(
|
|
4549
4596
|
`[SpanProcessor] Detected self-parenting span. trace_id=${traceId} span_id=${spanId} name=${span2.name}. Setting parent_span_id=None.`
|
|
4550
4597
|
);
|
|
4551
4598
|
}
|
|
@@ -4608,7 +4655,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
4608
4655
|
}
|
|
4609
4656
|
} catch (wbExc) {
|
|
4610
4657
|
if (this.debug) {
|
|
4611
|
-
|
|
4658
|
+
logger10.debug(
|
|
4612
4659
|
`[SpanProcessor] Attr write-back failed: ${wbExc}`
|
|
4613
4660
|
);
|
|
4614
4661
|
}
|
|
@@ -4619,7 +4666,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
4619
4666
|
JSON.stringify(spanData) + "\n"
|
|
4620
4667
|
);
|
|
4621
4668
|
} catch (e) {
|
|
4622
|
-
|
|
4669
|
+
logger10.warn(`Failed to write span to processed log file: ${e}`);
|
|
4623
4670
|
}
|
|
4624
4671
|
}
|
|
4625
4672
|
this.perfStats.spansExported += 1;
|
|
@@ -4651,12 +4698,12 @@ var NeatlogsSpanProcessor = class {
|
|
|
4651
4698
|
}
|
|
4652
4699
|
marker.end();
|
|
4653
4700
|
if (this.debug) {
|
|
4654
|
-
|
|
4701
|
+
logger10.debug(
|
|
4655
4702
|
`[SpanProcessor] Emitted completion marker for trace ${traceId}`
|
|
4656
4703
|
);
|
|
4657
4704
|
}
|
|
4658
4705
|
} catch (e) {
|
|
4659
|
-
|
|
4706
|
+
logger10.warn(`[SpanProcessor] Failed to emit completion marker: ${e}`);
|
|
4660
4707
|
}
|
|
4661
4708
|
}
|
|
4662
4709
|
// ── Framework span name normalization ─────────────────
|
|
@@ -4723,7 +4770,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
4723
4770
|
if (respMeta?.model_name && respMeta.model_name !== currentModel) {
|
|
4724
4771
|
attrs["neatlogs.llm.model_name"] = respMeta.model_name;
|
|
4725
4772
|
if (this.debug) {
|
|
4726
|
-
|
|
4773
|
+
logger10.debug(
|
|
4727
4774
|
`[ModelResolve] LangChain span: ${currentModel} \u2192 ${respMeta.model_name}`
|
|
4728
4775
|
);
|
|
4729
4776
|
}
|
|
@@ -4733,13 +4780,13 @@ var NeatlogsSpanProcessor = class {
|
|
|
4733
4780
|
if (output?.model && output.model !== currentModel) {
|
|
4734
4781
|
attrs["neatlogs.llm.model_name"] = output.model;
|
|
4735
4782
|
if (this.debug) {
|
|
4736
|
-
|
|
4783
|
+
logger10.debug(
|
|
4737
4784
|
`[ModelResolve] Direct response: ${currentModel} \u2192 ${output.model}`
|
|
4738
4785
|
);
|
|
4739
4786
|
}
|
|
4740
4787
|
}
|
|
4741
4788
|
} catch (e) {
|
|
4742
|
-
|
|
4789
|
+
logger10.warn(`[ModelResolve] Failed to parse LLM output for model extraction: ${e}`);
|
|
4743
4790
|
}
|
|
4744
4791
|
}
|
|
4745
4792
|
// ── forceFlush / shutdown ─────────────────────────────
|
|
@@ -4760,7 +4807,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
4760
4807
|
const totalTime = stats.onStartTime + stats.onEndTime;
|
|
4761
4808
|
const avgMs = totalTime / stats.spansProcessed;
|
|
4762
4809
|
try {
|
|
4763
|
-
|
|
4810
|
+
logger10.info(
|
|
4764
4811
|
`Neatlogs overhead: ${totalTime.toFixed(2)}ms total, ${avgMs.toFixed(3)}ms/span (${stats.spansProcessed} spans processed, ${stats.spansExported} spans logged)`
|
|
4765
4812
|
);
|
|
4766
4813
|
} catch {
|
|
@@ -4801,187 +4848,9 @@ var FilteringExporter = class {
|
|
|
4801
4848
|
}
|
|
4802
4849
|
};
|
|
4803
4850
|
|
|
4804
|
-
// src/core/
|
|
4805
|
-
var logger10 = getLogger();
|
|
4806
|
-
var NeatlogsExporter = class {
|
|
4807
|
-
baseUrl;
|
|
4808
|
-
apiKey;
|
|
4809
|
-
batchSize;
|
|
4810
|
-
flushIntervalMs;
|
|
4811
|
-
disableExport;
|
|
4812
|
-
buffer = [];
|
|
4813
|
-
flushTimer = null;
|
|
4814
|
-
_shutdown = false;
|
|
4815
|
-
constructor(options) {
|
|
4816
|
-
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
4817
|
-
this.apiKey = options.apiKey;
|
|
4818
|
-
this.batchSize = options.batchSize ?? 50;
|
|
4819
|
-
this.flushIntervalMs = options.flushIntervalMs ?? 5e3;
|
|
4820
|
-
this.disableExport = options.disableExport ?? false;
|
|
4821
|
-
if (!this.disableExport) {
|
|
4822
|
-
this.flushTimer = setInterval(() => this.flush(), this.flushIntervalMs);
|
|
4823
|
-
if (this.flushTimer.unref) {
|
|
4824
|
-
this.flushTimer.unref();
|
|
4825
|
-
}
|
|
4826
|
-
}
|
|
4827
|
-
}
|
|
4828
|
-
/** Add a span-like dict to the buffer. */
|
|
4829
|
-
export(spanData) {
|
|
4830
|
-
if (this._shutdown || this.disableExport) return;
|
|
4831
|
-
this.buffer.push(spanData);
|
|
4832
|
-
if (this.buffer.length >= this.batchSize) {
|
|
4833
|
-
this.flush().catch((err) => {
|
|
4834
|
-
logger10.warn(`Failed to flush batch: ${err}`);
|
|
4835
|
-
});
|
|
4836
|
-
}
|
|
4837
|
-
}
|
|
4838
|
-
/** Flush all buffered spans to the API. */
|
|
4839
|
-
async flush() {
|
|
4840
|
-
if (this.disableExport || this.buffer.length === 0) return;
|
|
4841
|
-
const batch = this.buffer.splice(0, this.buffer.length);
|
|
4842
|
-
try {
|
|
4843
|
-
const url = `${this.baseUrl}/api/data/v4/batch`;
|
|
4844
|
-
const response = await fetch(url, {
|
|
4845
|
-
method: "POST",
|
|
4846
|
-
headers: {
|
|
4847
|
-
"Content-Type": "application/json",
|
|
4848
|
-
"x-api-key": this.apiKey
|
|
4849
|
-
},
|
|
4850
|
-
body: JSON.stringify({ spans: batch })
|
|
4851
|
-
});
|
|
4852
|
-
if (!response.ok) {
|
|
4853
|
-
logger10.warn(
|
|
4854
|
-
`Failed to export batch: ${response.status} ${response.statusText}`
|
|
4855
|
-
);
|
|
4856
|
-
this._requeueBatch(batch);
|
|
4857
|
-
} else {
|
|
4858
|
-
logger10.debug(`Exported ${batch.length} log spans`);
|
|
4859
|
-
}
|
|
4860
|
-
} catch (err) {
|
|
4861
|
-
logger10.warn(`Failed to export batch: ${err}`);
|
|
4862
|
-
this._requeueBatch(batch);
|
|
4863
|
-
}
|
|
4864
|
-
}
|
|
4865
|
-
/** Re-insert a failed batch into the buffer for retry, up to a limit. */
|
|
4866
|
-
_requeueBatch(batch) {
|
|
4867
|
-
if (this.buffer.length < this.batchSize * 3) {
|
|
4868
|
-
this.buffer.unshift(...batch);
|
|
4869
|
-
}
|
|
4870
|
-
}
|
|
4871
|
-
/** Shutdown the exporter, flushing remaining items. */
|
|
4872
|
-
async shutdown() {
|
|
4873
|
-
this._shutdown = true;
|
|
4874
|
-
if (this.flushTimer) {
|
|
4875
|
-
clearInterval(this.flushTimer);
|
|
4876
|
-
this.flushTimer = null;
|
|
4877
|
-
}
|
|
4878
|
-
await this.flush();
|
|
4879
|
-
}
|
|
4880
|
-
};
|
|
4881
|
-
|
|
4882
|
-
// src/core/log-exporter.ts
|
|
4883
|
-
var crypto = __toESM(require("crypto"));
|
|
4884
|
-
var fs2 = __toESM(require("fs"));
|
|
4885
|
-
var path2 = __toESM(require("path"));
|
|
4886
|
-
|
|
4887
|
-
// node_modules/@opentelemetry/core/build/esm/trace/suppress-tracing.js
|
|
4851
|
+
// src/core/log.ts
|
|
4888
4852
|
var import_api5 = require("@opentelemetry/api");
|
|
4889
|
-
var SUPPRESS_TRACING_KEY = (0, import_api5.createContextKey)("OpenTelemetry SDK Context Key SUPPRESS_TRACING");
|
|
4890
|
-
function suppressTracing(context3) {
|
|
4891
|
-
return context3.setValue(SUPPRESS_TRACING_KEY, true);
|
|
4892
|
-
}
|
|
4893
|
-
|
|
4894
|
-
// node_modules/@opentelemetry/core/build/esm/ExportResult.js
|
|
4895
|
-
var ExportResultCode;
|
|
4896
|
-
(function(ExportResultCode2) {
|
|
4897
|
-
ExportResultCode2[ExportResultCode2["SUCCESS"] = 0] = "SUCCESS";
|
|
4898
|
-
ExportResultCode2[ExportResultCode2["FAILED"] = 1] = "FAILED";
|
|
4899
|
-
})(ExportResultCode || (ExportResultCode = {}));
|
|
4900
|
-
|
|
4901
|
-
// src/core/log-exporter.ts
|
|
4902
4853
|
var logger11 = getLogger();
|
|
4903
|
-
var NeatlogsLogExporter = class {
|
|
4904
|
-
exporter;
|
|
4905
|
-
logFileHandle = null;
|
|
4906
|
-
logEnabled;
|
|
4907
|
-
constructor(exporter) {
|
|
4908
|
-
this.exporter = exporter;
|
|
4909
|
-
this.logEnabled = ["1", "true", "yes"].includes(
|
|
4910
|
-
(process.env.NEATLOGS_LOG_LOGS ?? "").toLowerCase()
|
|
4911
|
-
);
|
|
4912
|
-
const logFile = process.env.NEATLOGS_LOG_LOGS_FILE ?? "";
|
|
4913
|
-
if (this.logEnabled && logFile) {
|
|
4914
|
-
const filePath = path2.resolve(process.cwd(), logFile);
|
|
4915
|
-
try {
|
|
4916
|
-
this.logFileHandle = fs2.openSync(filePath, "a");
|
|
4917
|
-
logger11.info(`Log record logging enabled: ${filePath}`);
|
|
4918
|
-
} catch (err) {
|
|
4919
|
-
logger11.warn(`Failed to open log file ${filePath}: ${err}`);
|
|
4920
|
-
}
|
|
4921
|
-
}
|
|
4922
|
-
}
|
|
4923
|
-
export(logRecords, resultCallback) {
|
|
4924
|
-
try {
|
|
4925
|
-
for (const record of logRecords) {
|
|
4926
|
-
const spanDict = this._convertLogRecord(record);
|
|
4927
|
-
this.exporter.export(spanDict);
|
|
4928
|
-
this._writeToFile(record, spanDict);
|
|
4929
|
-
}
|
|
4930
|
-
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
4931
|
-
} catch (err) {
|
|
4932
|
-
logger11.warn(`Failed to export log records: ${err}`);
|
|
4933
|
-
resultCallback({ code: ExportResultCode.FAILED });
|
|
4934
|
-
}
|
|
4935
|
-
}
|
|
4936
|
-
async shutdown() {
|
|
4937
|
-
if (this.logFileHandle !== null) {
|
|
4938
|
-
fs2.closeSync(this.logFileHandle);
|
|
4939
|
-
this.logFileHandle = null;
|
|
4940
|
-
}
|
|
4941
|
-
}
|
|
4942
|
-
async forceFlush() {
|
|
4943
|
-
await this.exporter.flush();
|
|
4944
|
-
}
|
|
4945
|
-
_writeToFile(record, spanDict) {
|
|
4946
|
-
if (!this.logEnabled || this.logFileHandle === null) return;
|
|
4947
|
-
const entry = {
|
|
4948
|
-
trace_id: spanDict.trace_id || "",
|
|
4949
|
-
span_id: spanDict.span_id || "",
|
|
4950
|
-
body: spanDict.attributes?.["log.message"] ?? "",
|
|
4951
|
-
severity: record.severityText ?? "",
|
|
4952
|
-
template: spanDict.attributes?.["log.template"] ?? "",
|
|
4953
|
-
timestamp: spanDict.start_time
|
|
4954
|
-
};
|
|
4955
|
-
fs2.writeSync(this.logFileHandle, JSON.stringify(entry) + "\n");
|
|
4956
|
-
}
|
|
4957
|
-
_convertLogRecord(record) {
|
|
4958
|
-
const attributes = { ...record.attributes ?? {} };
|
|
4959
|
-
if (record.body !== void 0 && record.body !== null) {
|
|
4960
|
-
attributes["log.message"] = String(record.body);
|
|
4961
|
-
}
|
|
4962
|
-
attributes["openinference.span.kind"] = "LOG";
|
|
4963
|
-
attributes["neatlogs.span.kind"] = "log";
|
|
4964
|
-
return {
|
|
4965
|
-
name: attributes["log.template"] ?? "log",
|
|
4966
|
-
kind: "LOG",
|
|
4967
|
-
trace_id: record.spanContext?.traceId ?? "",
|
|
4968
|
-
span_id: crypto.randomBytes(8).toString("hex"),
|
|
4969
|
-
parent_span_id: record.spanContext?.spanId ?? "",
|
|
4970
|
-
start_time: record.hrTime ? this._hrTimeToIso(record.hrTime) : (/* @__PURE__ */ new Date()).toISOString(),
|
|
4971
|
-
end_time: record.hrTime ? this._hrTimeToIso(record.hrTime) : (/* @__PURE__ */ new Date()).toISOString(),
|
|
4972
|
-
status: "OK",
|
|
4973
|
-
attributes
|
|
4974
|
-
};
|
|
4975
|
-
}
|
|
4976
|
-
_hrTimeToIso(hrTime) {
|
|
4977
|
-
const ms = hrTime[0] * 1e3 + hrTime[1] / 1e6;
|
|
4978
|
-
return new Date(ms).toISOString();
|
|
4979
|
-
}
|
|
4980
|
-
};
|
|
4981
|
-
|
|
4982
|
-
// src/core/log.ts
|
|
4983
|
-
var import_api6 = require("@opentelemetry/api");
|
|
4984
|
-
var logger12 = getLogger();
|
|
4985
4854
|
var _otelLogger = null;
|
|
4986
4855
|
var _debugMode = false;
|
|
4987
4856
|
function _setOtelLogger(otelLogger, debug) {
|
|
@@ -4998,7 +4867,7 @@ function log(msgTemplate, options) {
|
|
|
4998
4867
|
console.log(`[neatlogs:log] ${rendered}`);
|
|
4999
4868
|
}
|
|
5000
4869
|
if (_otelLogger) {
|
|
5001
|
-
const activeSpan =
|
|
4870
|
+
const activeSpan = import_api5.trace.getSpan(import_api5.context.active());
|
|
5002
4871
|
const spanContext = activeSpan?.spanContext();
|
|
5003
4872
|
const attributes = {
|
|
5004
4873
|
"log.template": msgTemplate,
|
|
@@ -5014,7 +4883,7 @@ function log(msgTemplate, options) {
|
|
|
5014
4883
|
...spanContext ? { spanContext } : {}
|
|
5015
4884
|
});
|
|
5016
4885
|
} catch (err) {
|
|
5017
|
-
|
|
4886
|
+
logger11.warn(`Failed to emit log record: ${err}`);
|
|
5018
4887
|
}
|
|
5019
4888
|
}
|
|
5020
4889
|
}
|
|
@@ -5443,7 +5312,7 @@ function getLibraryInfo(library) {
|
|
|
5443
5312
|
}
|
|
5444
5313
|
|
|
5445
5314
|
// src/instrumentation/manager.ts
|
|
5446
|
-
var
|
|
5315
|
+
var logger12 = getLogger();
|
|
5447
5316
|
var InstrumentationManager = class {
|
|
5448
5317
|
provider;
|
|
5449
5318
|
_instrumented = [];
|
|
@@ -5462,7 +5331,7 @@ var InstrumentationManager = class {
|
|
|
5462
5331
|
for (const lib of libraries) {
|
|
5463
5332
|
const info = getLibraryInfo(lib);
|
|
5464
5333
|
if (!info) {
|
|
5465
|
-
|
|
5334
|
+
logger12.warn(
|
|
5466
5335
|
`Unknown library '${lib}' \u2014 not in instrumentation registry. Skipping.`
|
|
5467
5336
|
);
|
|
5468
5337
|
continue;
|
|
@@ -5478,7 +5347,7 @@ var InstrumentationManager = class {
|
|
|
5478
5347
|
if (typeof instrumentor.instrument === "function") {
|
|
5479
5348
|
instrumentor.instrument({ tracerProvider: this.provider });
|
|
5480
5349
|
this._instrumented.push(lib);
|
|
5481
|
-
|
|
5350
|
+
logger12.debug(
|
|
5482
5351
|
`Instrumented '${lib}' via neatlogs custom instrumentor`
|
|
5483
5352
|
);
|
|
5484
5353
|
continue;
|
|
@@ -5491,23 +5360,23 @@ var InstrumentationManager = class {
|
|
|
5491
5360
|
const targetMod = await import(info.npm_package);
|
|
5492
5361
|
instrumentor.patchEager(targetMod);
|
|
5493
5362
|
} catch (e) {
|
|
5494
|
-
|
|
5363
|
+
logger12.debug(
|
|
5495
5364
|
`Eager patch for '${lib}' skipped \u2014 ${info.npm_package} not available: ${e}`
|
|
5496
5365
|
);
|
|
5497
5366
|
}
|
|
5498
5367
|
}
|
|
5499
5368
|
this._instrumented.push(lib);
|
|
5500
|
-
|
|
5369
|
+
logger12.debug(
|
|
5501
5370
|
`Instrumented '${lib}' via neatlogs OTel instrumentor`
|
|
5502
5371
|
);
|
|
5503
5372
|
continue;
|
|
5504
5373
|
}
|
|
5505
5374
|
}
|
|
5506
|
-
|
|
5375
|
+
logger12.debug(
|
|
5507
5376
|
`neatlogs instrumentor for '${lib}' loaded but has no instrument() method \u2014 trying OpenInference`
|
|
5508
5377
|
);
|
|
5509
5378
|
} catch (err) {
|
|
5510
|
-
|
|
5379
|
+
logger12.debug(
|
|
5511
5380
|
`neatlogs instrumentor for '${lib}' failed to load: ${err} \u2014 trying OpenInference`
|
|
5512
5381
|
);
|
|
5513
5382
|
}
|
|
@@ -5523,7 +5392,7 @@ var InstrumentationManager = class {
|
|
|
5523
5392
|
if (typeof instrumentor.instrument === "function") {
|
|
5524
5393
|
instrumentor.instrument({ tracerProvider: this.provider });
|
|
5525
5394
|
this._instrumented.push(lib);
|
|
5526
|
-
|
|
5395
|
+
logger12.debug(`Instrumented '${lib}' via OpenInference`);
|
|
5527
5396
|
continue;
|
|
5528
5397
|
}
|
|
5529
5398
|
if (typeof instrumentor.setTracerProvider === "function" && typeof instrumentor.manuallyInstrument === "function") {
|
|
@@ -5533,16 +5402,16 @@ var InstrumentationManager = class {
|
|
|
5533
5402
|
const targetMod = await import(info.npm_package);
|
|
5534
5403
|
instrumentor.manuallyInstrument(targetMod);
|
|
5535
5404
|
this._instrumented.push(lib);
|
|
5536
|
-
|
|
5405
|
+
logger12.debug(`Instrumented '${lib}' via OpenInference (manual patch)`);
|
|
5537
5406
|
continue;
|
|
5538
5407
|
} catch (importErr) {
|
|
5539
|
-
|
|
5408
|
+
logger12.debug(
|
|
5540
5409
|
`Could not import '${info.npm_package}' for manual instrumentation of '${lib}': ${importErr}`
|
|
5541
5410
|
);
|
|
5542
5411
|
}
|
|
5543
5412
|
}
|
|
5544
5413
|
this._instrumented.push(lib);
|
|
5545
|
-
|
|
5414
|
+
logger12.debug(`Instrumented '${lib}' via OpenInference (tracer set, awaiting module hook)`);
|
|
5546
5415
|
continue;
|
|
5547
5416
|
}
|
|
5548
5417
|
}
|
|
@@ -5551,32 +5420,41 @@ var InstrumentationManager = class {
|
|
|
5551
5420
|
tracerProvider: this.provider
|
|
5552
5421
|
});
|
|
5553
5422
|
this._instrumented.push(lib);
|
|
5554
|
-
|
|
5423
|
+
logger12.debug(`Instrumented '${lib}' via OpenInference`);
|
|
5555
5424
|
continue;
|
|
5556
5425
|
}
|
|
5557
|
-
|
|
5426
|
+
logger12.warn(
|
|
5558
5427
|
`OpenInference package for '${lib}' loaded but could not find instrumentor class`
|
|
5559
5428
|
);
|
|
5560
5429
|
} catch (err) {
|
|
5561
|
-
|
|
5430
|
+
logger12.debug(
|
|
5562
5431
|
`OpenInference instrumentor for '${lib}' not available: ${err}`
|
|
5563
5432
|
);
|
|
5564
5433
|
}
|
|
5565
5434
|
}
|
|
5566
5435
|
if (!info.openinference && !info.neatlogs) {
|
|
5567
|
-
|
|
5436
|
+
logger12.debug(
|
|
5568
5437
|
`'${lib}' instrumentation not yet available for TypeScript \u2014 skipping`
|
|
5569
5438
|
);
|
|
5570
5439
|
}
|
|
5571
5440
|
}
|
|
5572
5441
|
if (this._instrumented.length > 0) {
|
|
5573
|
-
|
|
5442
|
+
logger12.info(`Instrumented: ${this._instrumented.join(", ")}`);
|
|
5574
5443
|
}
|
|
5575
5444
|
}
|
|
5576
5445
|
};
|
|
5577
5446
|
|
|
5578
5447
|
// src/prompt/client.ts
|
|
5579
5448
|
var import_api7 = require("@opentelemetry/api");
|
|
5449
|
+
|
|
5450
|
+
// node_modules/@opentelemetry/core/build/esm/trace/suppress-tracing.js
|
|
5451
|
+
var import_api6 = require("@opentelemetry/api");
|
|
5452
|
+
var SUPPRESS_TRACING_KEY = (0, import_api6.createContextKey)("OpenTelemetry SDK Context Key SUPPRESS_TRACING");
|
|
5453
|
+
function suppressTracing(context3) {
|
|
5454
|
+
return context3.setValue(SUPPRESS_TRACING_KEY, true);
|
|
5455
|
+
}
|
|
5456
|
+
|
|
5457
|
+
// src/prompt/client.ts
|
|
5580
5458
|
var PromptClientError = class extends Error {
|
|
5581
5459
|
constructor(message) {
|
|
5582
5460
|
super(message);
|
|
@@ -5765,8 +5643,8 @@ var PromptClient = class {
|
|
|
5765
5643
|
const version = options?.version;
|
|
5766
5644
|
const label = options?.label;
|
|
5767
5645
|
if (label != null) {
|
|
5768
|
-
const
|
|
5769
|
-
const url = `${
|
|
5646
|
+
const path3 = `/api/v1/prompts/${encodeURIComponent(name)}/fetch`;
|
|
5647
|
+
const url = `${path3}?label=${encodeURIComponent(label)}`;
|
|
5770
5648
|
const payload = await this._request(url);
|
|
5771
5649
|
return new PromptHandle(normalizePromptObject(payload));
|
|
5772
5650
|
}
|
|
@@ -5870,8 +5748,8 @@ var PromptClient = class {
|
|
|
5870
5748
|
/**
|
|
5871
5749
|
* Internal fetch wrapper with auth headers and OTel suppression.
|
|
5872
5750
|
*/
|
|
5873
|
-
async _request(
|
|
5874
|
-
const url = `${this.baseUrl}${
|
|
5751
|
+
async _request(path3, options) {
|
|
5752
|
+
const url = `${this.baseUrl}${path3}`;
|
|
5875
5753
|
const headers = {
|
|
5876
5754
|
Accept: "application/json",
|
|
5877
5755
|
"Content-Type": "application/json",
|
|
@@ -5894,13 +5772,13 @@ var PromptClient = class {
|
|
|
5894
5772
|
if (!response.ok) {
|
|
5895
5773
|
const body = await response.text().catch(() => "<unavailable>");
|
|
5896
5774
|
throw new PromptApiError(
|
|
5897
|
-
`${fetchOptions.method} ${
|
|
5775
|
+
`${fetchOptions.method} ${path3} failed (${response.status}): ${body.slice(0, 400)}`
|
|
5898
5776
|
);
|
|
5899
5777
|
}
|
|
5900
5778
|
try {
|
|
5901
5779
|
return await response.json();
|
|
5902
5780
|
} catch {
|
|
5903
|
-
throw new PromptApiError(`${fetchOptions.method} ${
|
|
5781
|
+
throw new PromptApiError(`${fetchOptions.method} ${path3} returned non-JSON response`);
|
|
5904
5782
|
}
|
|
5905
5783
|
}
|
|
5906
5784
|
};
|
|
@@ -5942,15 +5820,14 @@ async function removeTag(name, tag) {
|
|
|
5942
5820
|
}
|
|
5943
5821
|
|
|
5944
5822
|
// src/version.ts
|
|
5945
|
-
var __version__ = "1.1.
|
|
5823
|
+
var __version__ = "1.1.4";
|
|
5946
5824
|
|
|
5947
5825
|
// src/init.ts
|
|
5948
|
-
var
|
|
5826
|
+
var logger13 = getLogger();
|
|
5949
5827
|
var _initialized = false;
|
|
5950
5828
|
var _tracerProvider = null;
|
|
5951
5829
|
var _meterProvider = null;
|
|
5952
5830
|
var _logProvider = null;
|
|
5953
|
-
var _logSpanExporter = null;
|
|
5954
5831
|
var _spanProcessor = null;
|
|
5955
5832
|
var _debugMode2 = false;
|
|
5956
5833
|
var _sigHandlersRegistered = false;
|
|
@@ -5962,19 +5839,16 @@ function _resolveWorkflowName(workflowName) {
|
|
|
5962
5839
|
const provided = (workflowName ?? "").trim();
|
|
5963
5840
|
if (provided) return provided;
|
|
5964
5841
|
const argv1 = process.argv[1] ?? "";
|
|
5965
|
-
const base =
|
|
5842
|
+
const base = path2.basename(argv1, path2.extname(argv1));
|
|
5966
5843
|
const slug = base.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "").toLowerCase();
|
|
5967
5844
|
if (slug && !["node", "ts-node", "tsx", "npx", "-e"].includes(slug)) {
|
|
5968
5845
|
return slug;
|
|
5969
5846
|
}
|
|
5970
5847
|
return "neatlogs-app";
|
|
5971
5848
|
}
|
|
5972
|
-
function _randomHex(bytes) {
|
|
5973
|
-
return (0, import_node_crypto.randomBytes)(bytes).toString("hex");
|
|
5974
|
-
}
|
|
5975
5849
|
async function init(options = {}) {
|
|
5976
5850
|
if (_initialized) {
|
|
5977
|
-
|
|
5851
|
+
logger13.warn("Neatlogs already initialized, skipping re-initialization");
|
|
5978
5852
|
return;
|
|
5979
5853
|
}
|
|
5980
5854
|
let resolvedKey;
|
|
@@ -5990,7 +5864,7 @@ async function init(options = {}) {
|
|
|
5990
5864
|
disableExportResolved = true;
|
|
5991
5865
|
resolvedKey = "disabled";
|
|
5992
5866
|
if (options.debug) {
|
|
5993
|
-
|
|
5867
|
+
logger13.warn(
|
|
5994
5868
|
"No NEATLOGS_API_KEY set; HTTP export disabled. Set NEATLOGS_API_KEY (or pass apiKey) to send spans to the backend."
|
|
5995
5869
|
);
|
|
5996
5870
|
}
|
|
@@ -6000,17 +5874,9 @@ async function init(options = {}) {
|
|
|
6000
5874
|
}
|
|
6001
5875
|
_debugMode2 = options.debug ?? false;
|
|
6002
5876
|
const resolvedWorkflowName = _resolveWorkflowName(options.workflowName);
|
|
6003
|
-
|
|
6004
|
-
if (!sessionId && options.autoSession) {
|
|
6005
|
-
sessionId = `session_${Date.now()}_${_randomHex(4)}`;
|
|
6006
|
-
if (options.debug) {
|
|
6007
|
-
logger14.debug(`Auto-generated session_id: ${sessionId}`);
|
|
6008
|
-
}
|
|
6009
|
-
}
|
|
6010
|
-
const endpoint = options.endpoint ?? "https://staging-cloud.neatlogs.com";
|
|
5877
|
+
const endpoint = options.endpoint ?? "https://ingest.neatlogs.com";
|
|
6011
5878
|
const baseUrl = new URL(endpoint).origin;
|
|
6012
5879
|
_setSessionConfig({
|
|
6013
|
-
sessionId,
|
|
6014
5880
|
userId: options.userId,
|
|
6015
5881
|
workflowName: resolvedWorkflowName,
|
|
6016
5882
|
_apiKey: resolvedKey,
|
|
@@ -6024,15 +5890,7 @@ async function init(options = {}) {
|
|
|
6024
5890
|
"service.version": __version__,
|
|
6025
5891
|
"neatlogs.workflow_name": resolvedWorkflowName
|
|
6026
5892
|
};
|
|
6027
|
-
if (sessionId) resourceAttrs["session.id"] = sessionId;
|
|
6028
5893
|
if (options.userId) resourceAttrs["user.id"] = options.userId;
|
|
6029
|
-
if (options.endUserId) {
|
|
6030
|
-
resourceAttrs[END_USER_ID_KEY] = String(options.endUserId);
|
|
6031
|
-
}
|
|
6032
|
-
if (options.endUserMetadata) {
|
|
6033
|
-
const euMeta = normalizeEndUserMetadata(options.endUserMetadata);
|
|
6034
|
-
if (euMeta) resourceAttrs[END_USER_METADATA_KEY] = euMeta;
|
|
6035
|
-
}
|
|
6036
5894
|
const tags = options.tags;
|
|
6037
5895
|
if (tags !== void 0) {
|
|
6038
5896
|
if (!Array.isArray(tags) || !tags.every((t) => typeof t === "string")) {
|
|
@@ -6071,40 +5929,30 @@ async function init(options = {}) {
|
|
|
6071
5929
|
});
|
|
6072
5930
|
provider.addSpanProcessor(batchProcessor);
|
|
6073
5931
|
if (options.debug) {
|
|
6074
|
-
|
|
5932
|
+
logger13.debug(`OTLP trace exporter configured: ${tracesEndpoint}`);
|
|
6075
5933
|
}
|
|
6076
5934
|
} else if (options.debug) {
|
|
6077
|
-
|
|
5935
|
+
logger13.debug("Export disabled \u2014 spans will not be sent to backend");
|
|
6078
5936
|
}
|
|
6079
5937
|
provider.register();
|
|
6080
5938
|
_tracerProvider = provider;
|
|
6081
5939
|
if (options.debug) {
|
|
6082
|
-
|
|
5940
|
+
logger13.debug("Neatlogs tracer provider initialized");
|
|
6083
5941
|
}
|
|
6084
5942
|
try {
|
|
6085
5943
|
_meterProvider = new import_sdk_metrics.MeterProvider({ resource });
|
|
6086
5944
|
import_api8.metrics.setGlobalMeterProvider(_meterProvider);
|
|
6087
5945
|
if (options.debug) {
|
|
6088
|
-
|
|
5946
|
+
logger13.debug("Neatlogs meter provider initialized");
|
|
6089
5947
|
}
|
|
6090
5948
|
} catch {
|
|
6091
5949
|
if (options.debug) {
|
|
6092
|
-
|
|
5950
|
+
logger13.debug("MeterProvider not available \u2014 skipping");
|
|
6093
5951
|
}
|
|
6094
5952
|
}
|
|
6095
5953
|
const captureLogs = options.captureLogs ?? false;
|
|
6096
5954
|
if (captureLogs) {
|
|
6097
|
-
_logSpanExporter = new NeatlogsExporter({
|
|
6098
|
-
baseUrl,
|
|
6099
|
-
apiKey: resolvedKey,
|
|
6100
|
-
batchSize: options.batchSize ?? 100,
|
|
6101
|
-
flushIntervalMs: (options.flushInterval ?? 5) * 1e3,
|
|
6102
|
-
disableExport: disableExportResolved
|
|
6103
|
-
});
|
|
6104
5955
|
_logProvider = new import_sdk_logs.LoggerProvider({ resource });
|
|
6105
|
-
_logProvider.addLogRecordProcessor(
|
|
6106
|
-
new import_sdk_logs.SimpleLogRecordProcessor(new NeatlogsLogExporter(_logSpanExporter))
|
|
6107
|
-
);
|
|
6108
5956
|
if (!disableExportResolved) {
|
|
6109
5957
|
const logsEndpoint = endpoint.endsWith("/v1/logs") ? endpoint : `${baseUrl}/v1/logs`;
|
|
6110
5958
|
const otlpLogExporter = new import_exporter_logs_otlp_proto.OTLPLogExporter({
|
|
@@ -6112,20 +5960,23 @@ async function init(options = {}) {
|
|
|
6112
5960
|
headers: resolvedKey ? { "x-api-key": resolvedKey } : void 0
|
|
6113
5961
|
});
|
|
6114
5962
|
_logProvider.addLogRecordProcessor(
|
|
6115
|
-
new import_sdk_logs.BatchLogRecordProcessor(otlpLogExporter
|
|
5963
|
+
new import_sdk_logs.BatchLogRecordProcessor(otlpLogExporter, {
|
|
5964
|
+
maxExportBatchSize: options.batchSize ?? 100,
|
|
5965
|
+
scheduledDelayMillis: (options.flushInterval ?? 5) * 1e3
|
|
5966
|
+
})
|
|
6116
5967
|
);
|
|
6117
5968
|
if (options.debug) {
|
|
6118
|
-
|
|
5969
|
+
logger13.debug(`OTLP log exporter configured: ${logsEndpoint}`);
|
|
6119
5970
|
}
|
|
6120
5971
|
}
|
|
6121
5972
|
import_api_logs.logs.setGlobalLoggerProvider(_logProvider);
|
|
6122
5973
|
const otelLogger = _logProvider.getLogger("neatlogs");
|
|
6123
5974
|
_setOtelLogger(otelLogger, options.debug ?? false);
|
|
6124
5975
|
if (options.debug) {
|
|
6125
|
-
|
|
5976
|
+
logger13.debug(`Neatlogs log capture enabled (endpoint: ${baseUrl}/v1/logs)`);
|
|
6126
5977
|
}
|
|
6127
5978
|
} else if (options.debug) {
|
|
6128
|
-
|
|
5979
|
+
logger13.debug("Log capture disabled (pass captureLogs: true to enable)");
|
|
6129
5980
|
}
|
|
6130
5981
|
const manager = new InstrumentationManager({
|
|
6131
5982
|
provider,
|
|
@@ -6134,7 +5985,7 @@ async function init(options = {}) {
|
|
|
6134
5985
|
if (options.instrumentations?.length) {
|
|
6135
5986
|
await manager.instrument(options.instrumentations);
|
|
6136
5987
|
if (options.debug) {
|
|
6137
|
-
|
|
5988
|
+
logger13.debug(`Instrumented libraries: ${manager.instrumented.join(", ")}`);
|
|
6138
5989
|
}
|
|
6139
5990
|
}
|
|
6140
5991
|
if (!_sigHandlersRegistered) {
|
|
@@ -6145,45 +5996,44 @@ async function init(options = {}) {
|
|
|
6145
5996
|
}
|
|
6146
5997
|
_initialized = true;
|
|
6147
5998
|
if (options.debug) {
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
logger14.info(`Sample Rate: ${options.sampleRate ?? 1}`);
|
|
5999
|
+
logger13.info("Neatlogs SDK initialized successfully");
|
|
6000
|
+
logger13.info(`Endpoint: ${endpoint}`);
|
|
6001
|
+
logger13.info(`Workflow: ${resolvedWorkflowName}`);
|
|
6002
|
+
logger13.info(`User: ${options.userId ?? "(none)"}`);
|
|
6003
|
+
logger13.info(`Tags: ${tags ?? []}`);
|
|
6004
|
+
logger13.info(`Instrumentations: ${manager.instrumented.join(", ") || "(none)"}`);
|
|
6005
|
+
logger13.info(`Sample Rate: ${options.sampleRate ?? 1}`);
|
|
6156
6006
|
}
|
|
6157
6007
|
}
|
|
6158
6008
|
async function flush() {
|
|
6159
6009
|
let success = true;
|
|
6160
6010
|
if (_tracerProvider) {
|
|
6161
6011
|
try {
|
|
6162
|
-
|
|
6012
|
+
logger13.debug("Flushing tracer provider...");
|
|
6163
6013
|
await _tracerProvider.forceFlush();
|
|
6164
|
-
|
|
6014
|
+
logger13.debug("Tracer provider flushed successfully");
|
|
6165
6015
|
} catch (e) {
|
|
6166
|
-
|
|
6016
|
+
logger13.error(`Error flushing spans: ${e}`);
|
|
6167
6017
|
success = false;
|
|
6168
6018
|
}
|
|
6169
6019
|
}
|
|
6170
6020
|
if (_meterProvider) {
|
|
6171
6021
|
try {
|
|
6172
|
-
|
|
6022
|
+
logger13.debug("Flushing meter provider...");
|
|
6173
6023
|
await _meterProvider.forceFlush();
|
|
6174
|
-
|
|
6024
|
+
logger13.debug("Meter provider flushed successfully");
|
|
6175
6025
|
} catch (e) {
|
|
6176
|
-
|
|
6026
|
+
logger13.error(`Error flushing metrics: ${e}`);
|
|
6177
6027
|
success = false;
|
|
6178
6028
|
}
|
|
6179
6029
|
}
|
|
6180
|
-
if (
|
|
6030
|
+
if (_logProvider) {
|
|
6181
6031
|
try {
|
|
6182
|
-
|
|
6183
|
-
await
|
|
6184
|
-
|
|
6032
|
+
logger13.debug("Flushing log provider...");
|
|
6033
|
+
await _logProvider.forceFlush();
|
|
6034
|
+
logger13.debug("Log provider flushed successfully");
|
|
6185
6035
|
} catch (e) {
|
|
6186
|
-
|
|
6036
|
+
logger13.error(`Error flushing logs: ${e}`);
|
|
6187
6037
|
success = false;
|
|
6188
6038
|
}
|
|
6189
6039
|
}
|
|
@@ -6199,41 +6049,31 @@ async function shutdown() {
|
|
|
6199
6049
|
let success = true;
|
|
6200
6050
|
if (_tracerProvider) {
|
|
6201
6051
|
try {
|
|
6202
|
-
|
|
6052
|
+
logger13.debug("Shutting down tracer provider...");
|
|
6203
6053
|
await _tracerProvider.shutdown();
|
|
6204
|
-
|
|
6054
|
+
logger13.debug("Tracer provider shut down successfully");
|
|
6205
6055
|
} catch (e) {
|
|
6206
|
-
|
|
6056
|
+
logger13.error(`Error shutting down tracer provider: ${e}`);
|
|
6207
6057
|
success = false;
|
|
6208
6058
|
}
|
|
6209
6059
|
}
|
|
6210
6060
|
if (_meterProvider) {
|
|
6211
6061
|
try {
|
|
6212
|
-
|
|
6062
|
+
logger13.debug("Shutting down meter provider...");
|
|
6213
6063
|
await _meterProvider.shutdown();
|
|
6214
|
-
|
|
6064
|
+
logger13.debug("Meter provider shut down successfully");
|
|
6215
6065
|
} catch (e) {
|
|
6216
|
-
|
|
6066
|
+
logger13.error(`Error shutting down meter provider: ${e}`);
|
|
6217
6067
|
success = false;
|
|
6218
6068
|
}
|
|
6219
6069
|
}
|
|
6220
6070
|
if (_logProvider) {
|
|
6221
6071
|
try {
|
|
6222
|
-
|
|
6072
|
+
logger13.debug("Shutting down log provider...");
|
|
6223
6073
|
await _logProvider.shutdown();
|
|
6224
|
-
|
|
6225
|
-
} catch (e) {
|
|
6226
|
-
logger14.error(`Error shutting down log provider: ${e}`);
|
|
6227
|
-
success = false;
|
|
6228
|
-
}
|
|
6229
|
-
}
|
|
6230
|
-
if (_logSpanExporter) {
|
|
6231
|
-
try {
|
|
6232
|
-
logger14.debug("Shutting down log span exporter...");
|
|
6233
|
-
await _logSpanExporter.shutdown();
|
|
6234
|
-
logger14.debug("Log span exporter shut down successfully");
|
|
6074
|
+
logger13.debug("Log provider shut down successfully");
|
|
6235
6075
|
} catch (e) {
|
|
6236
|
-
|
|
6076
|
+
logger13.error(`Error shutting down log provider: ${e}`);
|
|
6237
6077
|
success = false;
|
|
6238
6078
|
}
|
|
6239
6079
|
}
|
|
@@ -6241,11 +6081,10 @@ async function shutdown() {
|
|
|
6241
6081
|
_tracerProvider = null;
|
|
6242
6082
|
_meterProvider = null;
|
|
6243
6083
|
_logProvider = null;
|
|
6244
|
-
_logSpanExporter = null;
|
|
6245
6084
|
_spanProcessor = null;
|
|
6246
6085
|
_debugMode2 = false;
|
|
6247
6086
|
_setSessionConfig({});
|
|
6248
|
-
|
|
6087
|
+
logger13.info("Neatlogs SDK shutdown complete");
|
|
6249
6088
|
return success;
|
|
6250
6089
|
}
|
|
6251
6090
|
function getTracerProvider() {
|
|
@@ -6261,7 +6100,7 @@ function isDebugEnabled() {
|
|
|
6261
6100
|
}
|
|
6262
6101
|
|
|
6263
6102
|
// src/decorators/orchestration.ts
|
|
6264
|
-
var
|
|
6103
|
+
var logger14 = getLogger();
|
|
6265
6104
|
function span(options, fn) {
|
|
6266
6105
|
if (!VALID_SPAN_KINDS.has(options.kind)) {
|
|
6267
6106
|
throw new Error(
|
|
@@ -6599,6 +6438,10 @@ function resolveRootWorkflowName() {
|
|
|
6599
6438
|
}
|
|
6600
6439
|
return "workflow";
|
|
6601
6440
|
}
|
|
6441
|
+
function stampAutoRootIdentity(root) {
|
|
6442
|
+
applySessionAttributes(root, void 0, true);
|
|
6443
|
+
applyEndUserAttributes(root, void 0, void 0, true);
|
|
6444
|
+
}
|
|
6602
6445
|
function wrapSpanWithRoot(child, root) {
|
|
6603
6446
|
let ended = false;
|
|
6604
6447
|
return new Proxy(child, {
|
|
@@ -6633,6 +6476,7 @@ function maybeOpenAutoRoot(tracer, kind, baseCtx) {
|
|
|
6633
6476
|
{ attributes: { "neatlogs.span.kind": "workflow", "neatlogs.auto_root": true } },
|
|
6634
6477
|
baseCtx
|
|
6635
6478
|
);
|
|
6479
|
+
stampAutoRootIdentity(root);
|
|
6636
6480
|
return { root, ctx: import_api10.trace.setSpan(baseCtx, root) };
|
|
6637
6481
|
}
|
|
6638
6482
|
function endAutoRoot(root) {
|
|
@@ -6662,6 +6506,7 @@ var AutoRootTracer = class {
|
|
|
6662
6506
|
{ attributes: { "neatlogs.span.kind": "workflow", "neatlogs.auto_root": true } },
|
|
6663
6507
|
ctx
|
|
6664
6508
|
);
|
|
6509
|
+
stampAutoRootIdentity(root);
|
|
6665
6510
|
const childCtx = import_api10.trace.setSpan(ctx, root);
|
|
6666
6511
|
const child = this._tracer.startSpan(name, options, childCtx);
|
|
6667
6512
|
return wrapSpanWithRoot(child, root);
|
|
@@ -6710,12 +6555,12 @@ function traceTool(name, fn) {
|
|
|
6710
6555
|
);
|
|
6711
6556
|
};
|
|
6712
6557
|
}
|
|
6713
|
-
function wrapNamespace(target,
|
|
6558
|
+
function wrapNamespace(target, path3) {
|
|
6714
6559
|
return new Proxy(target, {
|
|
6715
6560
|
get(obj, prop, receiver) {
|
|
6716
6561
|
const value = Reflect.get(obj, prop, receiver);
|
|
6717
6562
|
if (typeof prop === "symbol" || String(prop).startsWith("_")) return value;
|
|
6718
|
-
const currentPath = [...
|
|
6563
|
+
const currentPath = [...path3, String(prop)];
|
|
6719
6564
|
const pathStr = currentPath.join(".");
|
|
6720
6565
|
if (pathStr === "chat.completions.create" && typeof value === "function") {
|
|
6721
6566
|
return tracedChatCompletionsCreate(value.bind(obj));
|
|
@@ -6730,9 +6575,9 @@ function wrapNamespace(target, path4) {
|
|
|
6730
6575
|
}
|
|
6731
6576
|
});
|
|
6732
6577
|
}
|
|
6733
|
-
function isNamespace(
|
|
6734
|
-
if (
|
|
6735
|
-
const key =
|
|
6578
|
+
function isNamespace(path3) {
|
|
6579
|
+
if (path3.length > 3) return false;
|
|
6580
|
+
const key = path3[path3.length - 1];
|
|
6736
6581
|
return ["chat", "completions", "responses", "beta"].includes(key);
|
|
6737
6582
|
}
|
|
6738
6583
|
function tracedChatCompletionsCreate(original) {
|
|
@@ -7022,12 +6867,12 @@ function traceTool2(name, fn) {
|
|
|
7022
6867
|
);
|
|
7023
6868
|
};
|
|
7024
6869
|
}
|
|
7025
|
-
function wrapNamespace2(target,
|
|
6870
|
+
function wrapNamespace2(target, path3) {
|
|
7026
6871
|
return new Proxy(target, {
|
|
7027
6872
|
get(obj, prop, receiver) {
|
|
7028
6873
|
const value = Reflect.get(obj, prop, receiver);
|
|
7029
6874
|
if (typeof prop === "symbol" || String(prop).startsWith("_")) return value;
|
|
7030
|
-
const currentPath = [...
|
|
6875
|
+
const currentPath = [...path3, String(prop)];
|
|
7031
6876
|
const pathStr = currentPath.join(".");
|
|
7032
6877
|
if (pathStr === "messages.create" && typeof value === "function") {
|
|
7033
6878
|
return tracedMessagesCreate(value.bind(obj));
|
|
@@ -7042,9 +6887,9 @@ function wrapNamespace2(target, path4) {
|
|
|
7042
6887
|
}
|
|
7043
6888
|
});
|
|
7044
6889
|
}
|
|
7045
|
-
function isNamespace2(
|
|
7046
|
-
if (
|
|
7047
|
-
const key =
|
|
6890
|
+
function isNamespace2(path3) {
|
|
6891
|
+
if (path3.length > 3) return false;
|
|
6892
|
+
const key = path3[path3.length - 1];
|
|
7048
6893
|
return ["messages", "beta"].includes(key);
|
|
7049
6894
|
}
|
|
7050
6895
|
function tracedMessagesCreate(original) {
|
|
@@ -7367,12 +7212,12 @@ function traceTool3(name, fn) {
|
|
|
7367
7212
|
);
|
|
7368
7213
|
};
|
|
7369
7214
|
}
|
|
7370
|
-
function wrapNamespace3(target,
|
|
7215
|
+
function wrapNamespace3(target, path3) {
|
|
7371
7216
|
return new Proxy(target, {
|
|
7372
7217
|
get(obj, prop, receiver) {
|
|
7373
7218
|
const value = Reflect.get(obj, prop, receiver);
|
|
7374
7219
|
if (typeof prop === "symbol" || String(prop).startsWith("_")) return value;
|
|
7375
|
-
const currentPath = [...
|
|
7220
|
+
const currentPath = [...path3, String(prop)];
|
|
7376
7221
|
const pathStr = currentPath.join(".");
|
|
7377
7222
|
if (pathStr === "chat.completions.create" && typeof value === "function") {
|
|
7378
7223
|
return tracedChatCompletionsCreate2(value.bind(obj));
|
|
@@ -7387,9 +7232,9 @@ function wrapNamespace3(target, path4) {
|
|
|
7387
7232
|
}
|
|
7388
7233
|
});
|
|
7389
7234
|
}
|
|
7390
|
-
function isNamespace3(
|
|
7391
|
-
if (
|
|
7392
|
-
const key =
|
|
7235
|
+
function isNamespace3(path3) {
|
|
7236
|
+
if (path3.length > 3) return false;
|
|
7237
|
+
const key = path3[path3.length - 1];
|
|
7393
7238
|
return ["chat", "completions", "responses", "beta"].includes(key);
|
|
7394
7239
|
}
|
|
7395
7240
|
function tracedChatCompletionsCreate2(original) {
|
|
@@ -7681,12 +7526,12 @@ function traceTool4(name, fn) {
|
|
|
7681
7526
|
);
|
|
7682
7527
|
};
|
|
7683
7528
|
}
|
|
7684
|
-
function wrapNamespace4(target,
|
|
7529
|
+
function wrapNamespace4(target, path3) {
|
|
7685
7530
|
return new Proxy(target, {
|
|
7686
7531
|
get(obj, prop, receiver) {
|
|
7687
7532
|
const value = Reflect.get(obj, prop, receiver);
|
|
7688
7533
|
if (typeof prop === "symbol" || String(prop).startsWith("_")) return value;
|
|
7689
|
-
const currentPath = [...
|
|
7534
|
+
const currentPath = [...path3, String(prop)];
|
|
7690
7535
|
const pathStr = currentPath.join(".");
|
|
7691
7536
|
if (pathStr === "models.generateContent" && typeof value === "function") {
|
|
7692
7537
|
return tracedGenerateContent(value.bind(obj), false);
|
|
@@ -7707,9 +7552,9 @@ function wrapNamespace4(target, path4) {
|
|
|
7707
7552
|
}
|
|
7708
7553
|
});
|
|
7709
7554
|
}
|
|
7710
|
-
function isNamespace4(
|
|
7711
|
-
if (
|
|
7712
|
-
return ["models", "chats"].includes(
|
|
7555
|
+
function isNamespace4(path3) {
|
|
7556
|
+
if (path3.length > 2) return false;
|
|
7557
|
+
return ["models", "chats"].includes(path3[path3.length - 1]);
|
|
7713
7558
|
}
|
|
7714
7559
|
function wrapVertexAIChat(chat) {
|
|
7715
7560
|
const c = chat;
|
|
@@ -10660,21 +10505,21 @@ var ExportTraceServiceRequest = protoRoot.lookupType(
|
|
|
10660
10505
|
"opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest"
|
|
10661
10506
|
);
|
|
10662
10507
|
var SpanStatusCode16 = { UNSET: 0, OK: 1, ERROR: 2 };
|
|
10663
|
-
function
|
|
10508
|
+
function randomBytes(length) {
|
|
10664
10509
|
const out = new Uint8Array(length);
|
|
10665
|
-
const
|
|
10666
|
-
if (
|
|
10667
|
-
|
|
10510
|
+
const crypto = globalThis.crypto;
|
|
10511
|
+
if (crypto && typeof crypto.getRandomValues === "function") {
|
|
10512
|
+
crypto.getRandomValues(out);
|
|
10668
10513
|
return out;
|
|
10669
10514
|
}
|
|
10670
10515
|
for (let i = 0; i < out.length; i++) out[i] = Math.floor(Math.random() * 256);
|
|
10671
10516
|
return out;
|
|
10672
10517
|
}
|
|
10673
10518
|
function generateTraceId() {
|
|
10674
|
-
return
|
|
10519
|
+
return randomBytes(16);
|
|
10675
10520
|
}
|
|
10676
10521
|
function generateSpanId() {
|
|
10677
|
-
return
|
|
10522
|
+
return randomBytes(8);
|
|
10678
10523
|
}
|
|
10679
10524
|
function nowNanoString() {
|
|
10680
10525
|
return (BigInt(Date.now()) * 1000000n).toString();
|
|
@@ -10816,7 +10661,7 @@ function nanoToLong(nanoStr) {
|
|
|
10816
10661
|
}
|
|
10817
10662
|
|
|
10818
10663
|
// src/opencode-plugin.ts
|
|
10819
|
-
var DEFAULT_ENDPOINT = "https://
|
|
10664
|
+
var DEFAULT_ENDPOINT = "https://ingest.neatlogs.com";
|
|
10820
10665
|
var NeatlogsOpencodePlugin = async (_ctx) => {
|
|
10821
10666
|
const apiKey = (process.env.NEATLOGS_API_KEY ?? "").trim();
|
|
10822
10667
|
const endpoint = (process.env.NEATLOGS_ENDPOINT ?? DEFAULT_ENDPOINT).trim();
|
|
@@ -11140,7 +10985,7 @@ function safeStringify15(value) {
|
|
|
11140
10985
|
}
|
|
11141
10986
|
|
|
11142
10987
|
// src/core/llm-binder.ts
|
|
11143
|
-
var
|
|
10988
|
+
var logger15 = getLogger();
|
|
11144
10989
|
function bindTemplates(llm, systemTpl, userTpl, compiledVars) {
|
|
11145
10990
|
const systemStr = String(systemTpl.template);
|
|
11146
10991
|
const userStr = userTpl ? String(userTpl.template) : null;
|
|
@@ -11152,7 +10997,7 @@ function bindTemplates(llm, systemTpl, userTpl, compiledVars) {
|
|
|
11152
10997
|
llmCopy = structuredClone(llm);
|
|
11153
10998
|
} catch {
|
|
11154
10999
|
llmCopy = llm;
|
|
11155
|
-
|
|
11000
|
+
logger15.debug(
|
|
11156
11001
|
`LLM type ${llm?.constructor?.name ?? "unknown"} is not copyable \u2014 binding in place.`
|
|
11157
11002
|
);
|
|
11158
11003
|
}
|
|
@@ -11163,7 +11008,7 @@ function bindTemplates(llm, systemTpl, userTpl, compiledVars) {
|
|
|
11163
11008
|
} else if (typeof llmCopy.call === "function") {
|
|
11164
11009
|
methodName = "call";
|
|
11165
11010
|
} else {
|
|
11166
|
-
|
|
11011
|
+
logger15.warn(
|
|
11167
11012
|
`LLM type ${llm?.constructor?.name ?? "unknown"} has neither invoke() nor call() \u2014 prompt templates will not be captured on spans.`
|
|
11168
11013
|
);
|
|
11169
11014
|
return llmCopy;
|
|
@@ -11183,7 +11028,7 @@ function bindTemplates(llm, systemTpl, userTpl, compiledVars) {
|
|
|
11183
11028
|
}
|
|
11184
11029
|
}
|
|
11185
11030
|
};
|
|
11186
|
-
|
|
11031
|
+
logger15.debug(
|
|
11187
11032
|
`Wrapped ${llm?.constructor?.name ?? "unknown"}.${methodName}() with template injection.`
|
|
11188
11033
|
);
|
|
11189
11034
|
return llmCopy;
|
|
@@ -11209,6 +11054,7 @@ function bindTemplates(llm, systemTpl, userTpl, compiledVars) {
|
|
|
11209
11054
|
getMastraObservability,
|
|
11210
11055
|
getPrompt,
|
|
11211
11056
|
getSessionConfig,
|
|
11057
|
+
identify,
|
|
11212
11058
|
init,
|
|
11213
11059
|
isDebugEnabled,
|
|
11214
11060
|
langchainHandler,
|