neatlogs 1.1.19 → 1.1.21
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 +34 -2
- package/dist/ai-sdk.cjs +186 -11
- package/dist/ai-sdk.cjs.map +1 -1
- package/dist/ai-sdk.d.ts +17 -7
- package/dist/ai-sdk.mjs +189 -12
- package/dist/ai-sdk.mjs.map +1 -1
- package/dist/anthropic.cjs +31 -14
- package/dist/anthropic.cjs.map +1 -1
- package/dist/anthropic.mjs +31 -14
- package/dist/anthropic.mjs.map +1 -1
- package/dist/azure-openai.cjs +31 -14
- package/dist/azure-openai.cjs.map +1 -1
- package/dist/azure-openai.mjs +31 -14
- package/dist/azure-openai.mjs.map +1 -1
- package/dist/bedrock.cjs +31 -14
- package/dist/bedrock.cjs.map +1 -1
- package/dist/bedrock.mjs +31 -14
- package/dist/bedrock.mjs.map +1 -1
- package/dist/browser.cjs +26 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.mjs +26 -1
- package/dist/browser.mjs.map +1 -1
- package/dist/claude-agent-sdk.cjs +2 -2
- package/dist/claude-agent-sdk.cjs.map +1 -1
- package/dist/claude-agent-sdk.mjs +2 -2
- package/dist/claude-agent-sdk.mjs.map +1 -1
- package/dist/cli.cjs +452 -200
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +427 -173
- package/dist/cli.mjs.map +1 -1
- package/dist/google-genai.cjs +31 -14
- package/dist/google-genai.cjs.map +1 -1
- package/dist/google-genai.mjs +31 -14
- package/dist/google-genai.mjs.map +1 -1
- package/dist/index.cjs +652 -333
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -6
- package/dist/index.mjs +505 -184
- package/dist/index.mjs.map +1 -1
- package/dist/langchain.cjs +3 -3
- package/dist/langchain.cjs.map +1 -1
- package/dist/langchain.mjs +3 -3
- package/dist/langchain.mjs.map +1 -1
- package/dist/mastra-wrap.cjs +2 -2
- package/dist/mastra-wrap.cjs.map +1 -1
- package/dist/mastra-wrap.mjs +2 -2
- package/dist/mastra-wrap.mjs.map +1 -1
- package/dist/openai-agents.cjs.map +1 -1
- package/dist/openai-agents.mjs.map +1 -1
- package/dist/openai.cjs +31 -14
- package/dist/openai.cjs.map +1 -1
- package/dist/openai.mjs +31 -14
- package/dist/openai.mjs.map +1 -1
- package/dist/opencode-plugin.cjs +1 -1
- package/dist/opencode-plugin.cjs.map +1 -1
- package/dist/opencode-plugin.mjs +1 -1
- package/dist/opencode-plugin.mjs.map +1 -1
- package/dist/openrouter-agent.cjs +31 -14
- package/dist/openrouter-agent.cjs.map +1 -1
- package/dist/openrouter-agent.mjs +31 -14
- package/dist/openrouter-agent.mjs.map +1 -1
- package/dist/pi-agent.cjs.map +1 -1
- package/dist/pi-agent.mjs.map +1 -1
- package/dist/vertex-ai.cjs +31 -14
- package/dist/vertex-ai.cjs.map +1 -1
- package/dist/vertex-ai.mjs +31 -14
- package/dist/vertex-ai.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -130,7 +130,7 @@ var import_exporter_logs_otlp_proto = require("@opentelemetry/exporter-logs-otlp
|
|
|
130
130
|
var fs = __toESM(require("fs"));
|
|
131
131
|
var path = __toESM(require("path"));
|
|
132
132
|
var import_node_perf_hooks = require("perf_hooks");
|
|
133
|
-
var
|
|
133
|
+
var import_api6 = require("@opentelemetry/api");
|
|
134
134
|
|
|
135
135
|
// src/core/logger.ts
|
|
136
136
|
var LOG_LEVELS = {
|
|
@@ -183,9 +183,9 @@ var SCOPE_PATTERNS = {
|
|
|
183
183
|
// Neatlogs custom instrumentations
|
|
184
184
|
"@neatlogs/instrumentation-google-genai": { provider: "google", framework: "google_genai" },
|
|
185
185
|
"@neatlogs/instrumentation-mastra": { framework: "mastra" },
|
|
186
|
-
"@neatlogs/instrumentation-ai-sdk": { framework: "
|
|
186
|
+
"@neatlogs/instrumentation-ai-sdk": { framework: "vercel_ai_sdk" },
|
|
187
187
|
// Vercel AI SDK native scope (the `ai` package emits this directly)
|
|
188
|
-
ai: { framework: "
|
|
188
|
+
ai: { framework: "vercel_ai_sdk" },
|
|
189
189
|
// OpenInference instrumentations (npm @arizeai scope names)
|
|
190
190
|
"@arizeai/openinference-instrumentation-openai": { provider: "openai", framework: "openai" },
|
|
191
191
|
"@arizeai/openinference-instrumentation-anthropic": { provider: "anthropic", framework: "anthropic" },
|
|
@@ -274,7 +274,7 @@ function parseInstrumentationScope(scopeName) {
|
|
|
274
274
|
} else if (scopeLower.includes("dspy")) {
|
|
275
275
|
result.framework = "dspy";
|
|
276
276
|
} else if (scopeLower.includes("vercel-ai") || scopeLower.includes("ai-sdk")) {
|
|
277
|
-
result.framework = "
|
|
277
|
+
result.framework = "vercel_ai_sdk";
|
|
278
278
|
}
|
|
279
279
|
if (scopeLower.includes("openai")) {
|
|
280
280
|
result.provider = "openai";
|
|
@@ -388,15 +388,26 @@ var VALID_SPAN_KINDS = /* @__PURE__ */ new Set([
|
|
|
388
388
|
"RETRIEVER",
|
|
389
389
|
"EMBEDDING",
|
|
390
390
|
"MCP_TOOL",
|
|
391
|
-
"GUARDRAIL"
|
|
391
|
+
"GUARDRAIL",
|
|
392
|
+
"EVALUATOR"
|
|
392
393
|
]);
|
|
393
394
|
var ALL_SPAN_KINDS = /* @__PURE__ */ new Set([
|
|
394
395
|
...VALID_SPAN_KINDS,
|
|
395
396
|
"LLM",
|
|
396
397
|
"RERANKER",
|
|
397
|
-
"EVALUATOR",
|
|
398
398
|
"VECTOR_STORE"
|
|
399
399
|
]);
|
|
400
|
+
function resolveExplicitSpanKind(attributes) {
|
|
401
|
+
for (const key of [
|
|
402
|
+
"neatlogs.span.kind",
|
|
403
|
+
"openinference.span.kind",
|
|
404
|
+
"traceloop.span.kind"
|
|
405
|
+
]) {
|
|
406
|
+
const value = String(attributes[key] ?? "").trim();
|
|
407
|
+
if (value) return value;
|
|
408
|
+
}
|
|
409
|
+
return "";
|
|
410
|
+
}
|
|
400
411
|
function inferSpanKindFromName(spanName) {
|
|
401
412
|
const nameLower = spanName.toLowerCase();
|
|
402
413
|
if (["openai", "anthropic", "cohere", "bedrock", "chat", "completion", "llm", "gemini", "google_genai"].some(
|
|
@@ -2479,11 +2490,11 @@ function getNeatlogsParentContext(baseContext) {
|
|
|
2479
2490
|
function getNeatlogsBaseContext(baseContext) {
|
|
2480
2491
|
return baseContext ?? getNeatlogsActiveContext();
|
|
2481
2492
|
}
|
|
2482
|
-
function withNeatlogsSpan(span2, fn, baseContext) {
|
|
2493
|
+
function withNeatlogsSpan(span2, fn, baseContext, rootSpan) {
|
|
2483
2494
|
const base = baseContext ?? getNeatlogsActiveContext();
|
|
2484
2495
|
let ctx = import_api.trace.setSpan(base, span2);
|
|
2485
2496
|
if (base.getValue(NEATLOGS_ROOT_SPAN_KEY) === void 0) {
|
|
2486
|
-
ctx = ctx.setValue(NEATLOGS_ROOT_SPAN_KEY, span2);
|
|
2497
|
+
ctx = ctx.setValue(NEATLOGS_ROOT_SPAN_KEY, rootSpan ?? span2);
|
|
2487
2498
|
}
|
|
2488
2499
|
return privateContextStorage.run(ctx, fn);
|
|
2489
2500
|
}
|
|
@@ -2680,7 +2691,7 @@ var UserPromptTemplate = class extends BasePromptTemplate {
|
|
|
2680
2691
|
};
|
|
2681
2692
|
|
|
2682
2693
|
// src/core/context.ts
|
|
2683
|
-
var
|
|
2694
|
+
var import_api4 = require("@opentelemetry/api");
|
|
2684
2695
|
|
|
2685
2696
|
// src/core/media.ts
|
|
2686
2697
|
var import_node_crypto2 = require("crypto");
|
|
@@ -4317,8 +4328,139 @@ function discardPendingMediaOwner(owner) {
|
|
|
4317
4328
|
pendingMediaOwners.delete(owner ?? defaultPendingMediaOwner);
|
|
4318
4329
|
}
|
|
4319
4330
|
|
|
4320
|
-
// src/
|
|
4331
|
+
// src/core/auto-root.ts
|
|
4321
4332
|
var import_api2 = require("@opentelemetry/api");
|
|
4333
|
+
var boundAutoRoots = /* @__PURE__ */ new WeakMap();
|
|
4334
|
+
var ROOT_KINDS = /* @__PURE__ */ new Set(["workflow", "chain", "agent", "mcp_tool", "llm"]);
|
|
4335
|
+
function autoRootEnabled() {
|
|
4336
|
+
const val = (process.env.NEATLOGS_AUTO_ROOT ?? "").trim().toLowerCase();
|
|
4337
|
+
return !["false", "0", "no", "off"].includes(val);
|
|
4338
|
+
}
|
|
4339
|
+
function resolveRootWorkflowName() {
|
|
4340
|
+
const clientName = getActiveClient()?.workflowName;
|
|
4341
|
+
if (typeof clientName === "string" && clientName.trim()) return clientName;
|
|
4342
|
+
try {
|
|
4343
|
+
const name = getSessionConfig()?.workflowName;
|
|
4344
|
+
if (typeof name === "string" && name.trim()) return name;
|
|
4345
|
+
} catch {
|
|
4346
|
+
}
|
|
4347
|
+
return "workflow";
|
|
4348
|
+
}
|
|
4349
|
+
function stampRootIdentity(root) {
|
|
4350
|
+
applySessionAttributes(root, void 0, true);
|
|
4351
|
+
applyEndUserAttributes(root, void 0, void 0, true);
|
|
4352
|
+
}
|
|
4353
|
+
function bindSpanToAutoRoot(child, root) {
|
|
4354
|
+
if (!root) return child;
|
|
4355
|
+
let ended = false;
|
|
4356
|
+
const proxy = new Proxy(child, {
|
|
4357
|
+
get(target, prop, _receiver) {
|
|
4358
|
+
if (prop === "end") {
|
|
4359
|
+
return (...args) => {
|
|
4360
|
+
if (ended) return;
|
|
4361
|
+
ended = true;
|
|
4362
|
+
try {
|
|
4363
|
+
target.end(...args);
|
|
4364
|
+
} finally {
|
|
4365
|
+
try {
|
|
4366
|
+
root.end();
|
|
4367
|
+
} catch {
|
|
4368
|
+
}
|
|
4369
|
+
}
|
|
4370
|
+
};
|
|
4371
|
+
}
|
|
4372
|
+
const value = Reflect.get(target, prop, target);
|
|
4373
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
4374
|
+
}
|
|
4375
|
+
});
|
|
4376
|
+
boundAutoRoots.set(proxy, root);
|
|
4377
|
+
aliasMediaCaptureSpan(proxy, child);
|
|
4378
|
+
return proxy;
|
|
4379
|
+
}
|
|
4380
|
+
function maybeOpenAutoRoot(tracer, kind, baseCtx) {
|
|
4381
|
+
const k = String(kind ?? "").toLowerCase();
|
|
4382
|
+
const existing = getActiveNeatlogsSpan();
|
|
4383
|
+
if (!autoRootEnabled() || ROOT_KINDS.has(k) || existing !== void 0 && existing.isRecording()) {
|
|
4384
|
+
return { root: void 0, ctx: baseCtx };
|
|
4385
|
+
}
|
|
4386
|
+
const root = tracer.startSpan(
|
|
4387
|
+
resolveRootWorkflowName(),
|
|
4388
|
+
{ attributes: { "neatlogs.span.kind": "workflow", "neatlogs.auto_root": true } },
|
|
4389
|
+
baseCtx
|
|
4390
|
+
);
|
|
4391
|
+
stampRootIdentity(root);
|
|
4392
|
+
return { root, ctx: import_api2.trace.setSpan(baseCtx, root) };
|
|
4393
|
+
}
|
|
4394
|
+
function endAutoRoot(root) {
|
|
4395
|
+
if (!root) return;
|
|
4396
|
+
try {
|
|
4397
|
+
root.end();
|
|
4398
|
+
} catch {
|
|
4399
|
+
}
|
|
4400
|
+
}
|
|
4401
|
+
var AutoRootTracer = class {
|
|
4402
|
+
constructor(_tracer) {
|
|
4403
|
+
this._tracer = _tracer;
|
|
4404
|
+
}
|
|
4405
|
+
_tracer;
|
|
4406
|
+
startSpan(name, options, context2) {
|
|
4407
|
+
const kind = String(
|
|
4408
|
+
options?.attributes?.["neatlogs.span.kind"] ?? ""
|
|
4409
|
+
).toLowerCase();
|
|
4410
|
+
const hasExplicitContext = context2 !== void 0;
|
|
4411
|
+
const ctx = context2 ?? getNeatlogsParentContext();
|
|
4412
|
+
const parent = getActiveNeatlogsSpan();
|
|
4413
|
+
const isParentless = !hasExplicitContext && !(parent !== void 0 && parent.isRecording());
|
|
4414
|
+
const needsRoot = autoRootEnabled() && !ROOT_KINDS.has(kind) && isParentless;
|
|
4415
|
+
if (!needsRoot) {
|
|
4416
|
+
const span2 = this._tracer.startSpan(name, options, ctx);
|
|
4417
|
+
if (isParentless && ROOT_KINDS.has(kind)) stampRootIdentity(span2);
|
|
4418
|
+
return span2;
|
|
4419
|
+
}
|
|
4420
|
+
const root = this._tracer.startSpan(
|
|
4421
|
+
resolveRootWorkflowName(),
|
|
4422
|
+
{ attributes: { "neatlogs.span.kind": "workflow", "neatlogs.auto_root": true } },
|
|
4423
|
+
ctx
|
|
4424
|
+
);
|
|
4425
|
+
stampRootIdentity(root);
|
|
4426
|
+
const childCtx = import_api2.trace.setSpan(ctx, root);
|
|
4427
|
+
const child = this._tracer.startSpan(name, options, childCtx);
|
|
4428
|
+
return bindSpanToAutoRoot(child, root);
|
|
4429
|
+
}
|
|
4430
|
+
startActiveSpan = ((name, ...args) => {
|
|
4431
|
+
const callback = args.at(-1);
|
|
4432
|
+
if (typeof callback !== "function") {
|
|
4433
|
+
throw new TypeError("startActiveSpan requires a callback");
|
|
4434
|
+
}
|
|
4435
|
+
const options = args.length >= 2 ? args[0] : void 0;
|
|
4436
|
+
const parentContext = args.length >= 3 ? args[1] : getNeatlogsParentContext();
|
|
4437
|
+
const span2 = args.length >= 3 ? this.startSpan(name, options, parentContext) : this.startSpan(name, options);
|
|
4438
|
+
return withNeatlogsSpan(
|
|
4439
|
+
span2,
|
|
4440
|
+
() => callback(span2),
|
|
4441
|
+
parentContext,
|
|
4442
|
+
boundAutoRoots.get(span2)
|
|
4443
|
+
);
|
|
4444
|
+
});
|
|
4445
|
+
};
|
|
4446
|
+
function getProviderTracer(name) {
|
|
4447
|
+
return new AutoRootTracer(getNeatlogsTracer(name));
|
|
4448
|
+
}
|
|
4449
|
+
|
|
4450
|
+
// src/errors.ts
|
|
4451
|
+
var NeatlogsConfigurationError = class extends TypeError {
|
|
4452
|
+
code;
|
|
4453
|
+
option;
|
|
4454
|
+
constructor(code, option, message) {
|
|
4455
|
+
super(message);
|
|
4456
|
+
this.name = "NeatlogsConfigurationError";
|
|
4457
|
+
this.code = code;
|
|
4458
|
+
this.option = option;
|
|
4459
|
+
}
|
|
4460
|
+
};
|
|
4461
|
+
|
|
4462
|
+
// src/decorators/base.ts
|
|
4463
|
+
var import_api3 = require("@opentelemetry/api");
|
|
4322
4464
|
|
|
4323
4465
|
// src/constants.ts
|
|
4324
4466
|
var DEFAULT_INGEST_ENDPOINT = "https://ingest.neatlogs.com";
|
|
@@ -4419,8 +4561,29 @@ function decorateSpan(opts, fn) {
|
|
|
4419
4561
|
const wrapped = (...args) => {
|
|
4420
4562
|
const tracer = getNeatlogsTracer(TRACER_NAME);
|
|
4421
4563
|
const isRoot = isRootSpan();
|
|
4422
|
-
const parentContext = isRoot ?
|
|
4423
|
-
const
|
|
4564
|
+
const parentContext = isRoot ? import_api3.ROOT_CONTEXT : getNeatlogsParentContext();
|
|
4565
|
+
const autoRoot = maybeOpenAutoRoot(
|
|
4566
|
+
tracer,
|
|
4567
|
+
String(opts.kind ?? ""),
|
|
4568
|
+
parentContext
|
|
4569
|
+
);
|
|
4570
|
+
if (autoRoot.root) {
|
|
4571
|
+
applySessionAttributes(autoRoot.root, opts.sessionId, true, {
|
|
4572
|
+
parentSessionId: opts.parentSessionId,
|
|
4573
|
+
sessionFeatureName: opts.sessionFeatureName,
|
|
4574
|
+
sessionEntryPoint: opts.sessionEntryPoint
|
|
4575
|
+
});
|
|
4576
|
+
applyEndUserAttributes(
|
|
4577
|
+
autoRoot.root,
|
|
4578
|
+
opts.endUserId,
|
|
4579
|
+
opts.endUserMetadata,
|
|
4580
|
+
true
|
|
4581
|
+
);
|
|
4582
|
+
}
|
|
4583
|
+
const span2 = bindSpanToAutoRoot(
|
|
4584
|
+
tracer.startSpan(spanName, {}, autoRoot.ctx),
|
|
4585
|
+
autoRoot.root
|
|
4586
|
+
);
|
|
4424
4587
|
return withNeatlogsSpan(span2, () => {
|
|
4425
4588
|
let finished = false;
|
|
4426
4589
|
let streamInterrupted = false;
|
|
@@ -4460,7 +4623,7 @@ function decorateSpan(opts, fn) {
|
|
|
4460
4623
|
if (finished) return;
|
|
4461
4624
|
finished = true;
|
|
4462
4625
|
captureResult(result);
|
|
4463
|
-
span2.setStatus({ code:
|
|
4626
|
+
span2.setStatus({ code: import_api3.SpanStatusCode.OK });
|
|
4464
4627
|
span2.end();
|
|
4465
4628
|
};
|
|
4466
4629
|
const setStreamCounts = () => {
|
|
@@ -4499,12 +4662,12 @@ function decorateSpan(opts, fn) {
|
|
|
4499
4662
|
setStreamCounts();
|
|
4500
4663
|
captureResult(streamCaptureValue());
|
|
4501
4664
|
}
|
|
4502
|
-
span2.setStatus({ code:
|
|
4665
|
+
span2.setStatus({ code: import_api3.SpanStatusCode.UNSET });
|
|
4503
4666
|
span2.end();
|
|
4504
4667
|
return;
|
|
4505
4668
|
}
|
|
4506
4669
|
span2.setStatus({
|
|
4507
|
-
code:
|
|
4670
|
+
code: import_api3.SpanStatusCode.ERROR,
|
|
4508
4671
|
message: error?.message ?? String(error)
|
|
4509
4672
|
});
|
|
4510
4673
|
span2.recordException(
|
|
@@ -4569,7 +4732,7 @@ function decorateSpan(opts, fn) {
|
|
|
4569
4732
|
finished = true;
|
|
4570
4733
|
span2.setAttribute("neatlogs.stream.cancelled", true);
|
|
4571
4734
|
captureResult(streamCaptureValue());
|
|
4572
|
-
span2.setStatus({ code:
|
|
4735
|
+
span2.setStatus({ code: import_api3.SpanStatusCode.UNSET });
|
|
4573
4736
|
span2.end();
|
|
4574
4737
|
};
|
|
4575
4738
|
const wrapAsyncIterator = (iterator) => {
|
|
@@ -4789,7 +4952,8 @@ function decorateSpan(opts, fn) {
|
|
|
4789
4952
|
});
|
|
4790
4953
|
try {
|
|
4791
4954
|
setCommonSpanAttrs(span2, opts);
|
|
4792
|
-
|
|
4955
|
+
const spanIsRoot = isRoot && !autoRoot.root;
|
|
4956
|
+
applySessionAttributes(span2, opts.sessionId, spanIsRoot, {
|
|
4793
4957
|
parentSessionId: opts.parentSessionId,
|
|
4794
4958
|
sessionFeatureName: opts.sessionFeatureName,
|
|
4795
4959
|
sessionEntryPoint: opts.sessionEntryPoint
|
|
@@ -4798,7 +4962,7 @@ function decorateSpan(opts, fn) {
|
|
|
4798
4962
|
span2,
|
|
4799
4963
|
opts.endUserId,
|
|
4800
4964
|
opts.endUserMetadata,
|
|
4801
|
-
|
|
4965
|
+
spanIsRoot
|
|
4802
4966
|
);
|
|
4803
4967
|
if (captureInput && args.length > 0) {
|
|
4804
4968
|
try {
|
|
@@ -4838,7 +5002,7 @@ function decorateSpan(opts, fn) {
|
|
|
4838
5002
|
finishError(error);
|
|
4839
5003
|
throw error;
|
|
4840
5004
|
}
|
|
4841
|
-
});
|
|
5005
|
+
}, autoRoot.ctx, autoRoot.root);
|
|
4842
5006
|
};
|
|
4843
5007
|
Object.defineProperty(wrapped, "name", {
|
|
4844
5008
|
value: spanName,
|
|
@@ -4870,11 +5034,11 @@ function _setSessionConfig(config) {
|
|
|
4870
5034
|
function getSessionConfig() {
|
|
4871
5035
|
return { ..._sessionConfig };
|
|
4872
5036
|
}
|
|
4873
|
-
var PROMPT_VARIABLES_KEY = (0,
|
|
4874
|
-
var PROMPT_TEMPLATE_KEY = (0,
|
|
4875
|
-
var PROMPT_VERSION_KEY = (0,
|
|
4876
|
-
var USER_PROMPT_TEMPLATE_KEY = (0,
|
|
4877
|
-
var USER_PROMPT_VARIABLES_KEY = (0,
|
|
5037
|
+
var PROMPT_VARIABLES_KEY = (0, import_api4.createContextKey)("neatlogs.prompt_variables");
|
|
5038
|
+
var PROMPT_TEMPLATE_KEY = (0, import_api4.createContextKey)("neatlogs.prompt_template");
|
|
5039
|
+
var PROMPT_VERSION_KEY = (0, import_api4.createContextKey)("neatlogs.prompt_version");
|
|
5040
|
+
var USER_PROMPT_TEMPLATE_KEY = (0, import_api4.createContextKey)("neatlogs.user_prompt_template");
|
|
5041
|
+
var USER_PROMPT_VARIABLES_KEY = (0, import_api4.createContextKey)("neatlogs.user_prompt_variables");
|
|
4878
5042
|
var KNOWN_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
4879
5043
|
"name",
|
|
4880
5044
|
"kind",
|
|
@@ -4893,6 +5057,20 @@ var KNOWN_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
|
4893
5057
|
"endUserId",
|
|
4894
5058
|
"endUserMetadata"
|
|
4895
5059
|
]);
|
|
5060
|
+
function assertNoHttpSpanKind(kind, attributes) {
|
|
5061
|
+
const candidates = [
|
|
5062
|
+
kind,
|
|
5063
|
+
attributes?.["neatlogs.span.kind"],
|
|
5064
|
+
attributes?.["openinference.span.kind"]
|
|
5065
|
+
];
|
|
5066
|
+
if (candidates.some((value) => String(value ?? "").trim().toUpperCase() === "HTTP")) {
|
|
5067
|
+
throw new NeatlogsConfigurationError(
|
|
5068
|
+
"UNSUPPORTED_SPAN_KIND",
|
|
5069
|
+
"kind",
|
|
5070
|
+
"HTTP spans are not supported. Trace the semantic LLM, TOOL, RETRIEVER, or other AI operation instead."
|
|
5071
|
+
);
|
|
5072
|
+
}
|
|
5073
|
+
}
|
|
4896
5074
|
function _setSpanAttributes(span2, kind, attributes) {
|
|
4897
5075
|
if (kind?.toUpperCase() === "LLM") {
|
|
4898
5076
|
span2.setAttribute("neatlogs.internal", true);
|
|
@@ -4963,6 +5141,7 @@ async function trace(options, fn) {
|
|
|
4963
5141
|
attributes: explicitAttributes,
|
|
4964
5142
|
...extraOptions
|
|
4965
5143
|
} = options;
|
|
5144
|
+
assertNoHttpSpanKind(kind, explicitAttributes);
|
|
4966
5145
|
const sessionId = sessionIdOption ?? currentSessionId();
|
|
4967
5146
|
const currentSpan = getActiveNeatlogsSpan();
|
|
4968
5147
|
const rootSpan = getNeatlogsRootSpan();
|
|
@@ -5007,7 +5186,7 @@ async function trace(options, fn) {
|
|
|
5007
5186
|
}
|
|
5008
5187
|
let ctx = getNeatlogsActiveContext();
|
|
5009
5188
|
if (shouldFallbackToRoot) {
|
|
5010
|
-
ctx =
|
|
5189
|
+
ctx = import_api4.trace.setSpan(ctx, rootSpan);
|
|
5011
5190
|
}
|
|
5012
5191
|
const variablesJson = promptVariables ? JSON.stringify(promptVariables) : void 0;
|
|
5013
5192
|
const userVariablesJson = userPromptVariables ? JSON.stringify(userPromptVariables) : void 0;
|
|
@@ -5041,12 +5220,13 @@ async function trace(options, fn) {
|
|
|
5041
5220
|
const tracer = getNeatlogsTracer("neatlogs.trace");
|
|
5042
5221
|
const spanCallback = async (span3) => {
|
|
5043
5222
|
_setSpanAttributes(span3, kind, extraAttributes);
|
|
5044
|
-
|
|
5223
|
+
const spanIsRoot = isRootTrace && !autoRoot.root;
|
|
5224
|
+
applySessionAttributes(span3, sessionId, spanIsRoot, {
|
|
5045
5225
|
parentSessionId,
|
|
5046
5226
|
sessionFeatureName,
|
|
5047
5227
|
sessionEntryPoint
|
|
5048
5228
|
});
|
|
5049
|
-
applyEndUserAttributes(span3, endUserId, endUserMetadata,
|
|
5229
|
+
applyEndUserAttributes(span3, endUserId, endUserMetadata, spanIsRoot);
|
|
5050
5230
|
if (input !== void 0 && input !== null) {
|
|
5051
5231
|
const capturedInput = captureMedia(
|
|
5052
5232
|
span3,
|
|
@@ -5079,7 +5259,7 @@ async function trace(options, fn) {
|
|
|
5079
5259
|
return result;
|
|
5080
5260
|
} catch (error) {
|
|
5081
5261
|
span3.setStatus({
|
|
5082
|
-
code:
|
|
5262
|
+
code: import_api4.SpanStatusCode.ERROR,
|
|
5083
5263
|
message: error instanceof Error ? error.message : String(error)
|
|
5084
5264
|
});
|
|
5085
5265
|
span3.recordException(
|
|
@@ -5096,15 +5276,36 @@ async function trace(options, fn) {
|
|
|
5096
5276
|
span3.end();
|
|
5097
5277
|
}
|
|
5098
5278
|
};
|
|
5099
|
-
const parentContext = shouldCreateRootTrace ?
|
|
5279
|
+
const parentContext = shouldCreateRootTrace ? import_api4.ROOT_CONTEXT : getNeatlogsParentContext(ctx);
|
|
5100
5280
|
const startAttributes = kind ? { "openinference.span.kind": kind } : void 0;
|
|
5101
|
-
const
|
|
5281
|
+
const autoRoot = isRootTrace ? maybeOpenAutoRoot(tracer, String(kind ?? "CHAIN"), parentContext) : { root: void 0, ctx: parentContext };
|
|
5282
|
+
if (autoRoot.root) {
|
|
5283
|
+
applySessionAttributes(autoRoot.root, sessionId, true, {
|
|
5284
|
+
parentSessionId,
|
|
5285
|
+
sessionFeatureName,
|
|
5286
|
+
sessionEntryPoint
|
|
5287
|
+
});
|
|
5288
|
+
applyEndUserAttributes(autoRoot.root, endUserId, endUserMetadata, true);
|
|
5289
|
+
}
|
|
5290
|
+
const span2 = bindSpanToAutoRoot(
|
|
5291
|
+
tracer.startSpan(
|
|
5292
|
+
name,
|
|
5293
|
+
startAttributes ? { attributes: startAttributes } : {},
|
|
5294
|
+
autoRoot.ctx
|
|
5295
|
+
),
|
|
5296
|
+
autoRoot.root
|
|
5297
|
+
);
|
|
5102
5298
|
if (shouldCreateRootTrace) {
|
|
5103
5299
|
logger7.debug(`[trace] Creating NEW root trace '${name}' (sessionId=${sessionId})`);
|
|
5104
5300
|
} else {
|
|
5105
5301
|
logger7.debug(`[trace] Creating child span '${name}'`);
|
|
5106
5302
|
}
|
|
5107
|
-
return withNeatlogsSpan(
|
|
5303
|
+
return withNeatlogsSpan(
|
|
5304
|
+
span2,
|
|
5305
|
+
() => spanCallback(span2),
|
|
5306
|
+
autoRoot.ctx,
|
|
5307
|
+
autoRoot.root
|
|
5308
|
+
);
|
|
5108
5309
|
}
|
|
5109
5310
|
|
|
5110
5311
|
// src/core/crewai-task-registry.ts
|
|
@@ -6302,27 +6503,11 @@ var AttributeMapper = class {
|
|
|
6302
6503
|
/** Extract and normalize span kind from multiple possible sources. */
|
|
6303
6504
|
mapSpanKind(attributes) {
|
|
6304
6505
|
const spanKindConfig = this.mappings.span_kind ?? {};
|
|
6305
|
-
const sources = spanKindConfig.sources ?? [];
|
|
6306
6506
|
const valuesMap = spanKindConfig.values ?? {};
|
|
6307
|
-
const
|
|
6308
|
-
|
|
6309
|
-
|
|
6310
|
-
if (
|
|
6311
|
-
spanKindValue = attributes["openinference.span.kind"];
|
|
6312
|
-
}
|
|
6313
|
-
} else {
|
|
6314
|
-
for (const source of sources) {
|
|
6315
|
-
if (source in attributes) {
|
|
6316
|
-
spanKindValue = attributes[source];
|
|
6317
|
-
break;
|
|
6318
|
-
}
|
|
6319
|
-
}
|
|
6320
|
-
}
|
|
6321
|
-
if (!spanKindValue && "neatlogs.span.kind" in attributes) {
|
|
6322
|
-
spanKindValue = attributes["neatlogs.span.kind"];
|
|
6323
|
-
}
|
|
6324
|
-
if (spanKindValue && spanKindValue in valuesMap) {
|
|
6325
|
-
return valuesMap[spanKindValue];
|
|
6507
|
+
const spanKindValue = resolveExplicitSpanKind(attributes);
|
|
6508
|
+
if (spanKindValue) {
|
|
6509
|
+
const mapped = valuesMap[spanKindValue] ?? valuesMap[spanKindValue.toUpperCase()];
|
|
6510
|
+
if (mapped) return mapped;
|
|
6326
6511
|
}
|
|
6327
6512
|
if (spanKindValue && Object.values(valuesMap).includes(spanKindValue)) {
|
|
6328
6513
|
return spanKindValue;
|
|
@@ -6604,6 +6789,46 @@ function addVerificationMarkerResourceAttribute(attributes) {
|
|
|
6604
6789
|
if (marker) attributes[VERIFICATION_MARKER_KEY] = marker;
|
|
6605
6790
|
}
|
|
6606
6791
|
|
|
6792
|
+
// src/core/http-span.ts
|
|
6793
|
+
var import_api5 = require("@opentelemetry/api");
|
|
6794
|
+
var HTTP_SCOPE_PREFIXES = [
|
|
6795
|
+
"@opentelemetry/instrumentation-http",
|
|
6796
|
+
"@opentelemetry/instrumentation-fetch",
|
|
6797
|
+
"@opentelemetry/instrumentation-undici"
|
|
6798
|
+
];
|
|
6799
|
+
var HTTP_ATTRIBUTE_KEYS = [
|
|
6800
|
+
"http.method",
|
|
6801
|
+
"http.request.method",
|
|
6802
|
+
"http.url",
|
|
6803
|
+
"http.route",
|
|
6804
|
+
"url.full"
|
|
6805
|
+
];
|
|
6806
|
+
var SEMANTIC_AI_KINDS = /* @__PURE__ */ new Set([
|
|
6807
|
+
"WORKFLOW",
|
|
6808
|
+
"AGENT",
|
|
6809
|
+
"CHAIN",
|
|
6810
|
+
"TOOL",
|
|
6811
|
+
"RETRIEVER",
|
|
6812
|
+
"EMBEDDING",
|
|
6813
|
+
"GUARDRAIL",
|
|
6814
|
+
"LLM",
|
|
6815
|
+
"RERANKER",
|
|
6816
|
+
"VECTOR_STORE",
|
|
6817
|
+
"TASK",
|
|
6818
|
+
"EVALUATOR",
|
|
6819
|
+
"LOG",
|
|
6820
|
+
"MEMORY",
|
|
6821
|
+
"MCP_TOOL"
|
|
6822
|
+
]);
|
|
6823
|
+
function isHttpSpan(span2, attributes = span2.attributes ?? {}) {
|
|
6824
|
+
const resolvedKind = resolveExplicitSpanKind(attributes).toUpperCase();
|
|
6825
|
+
if (resolvedKind === "HTTP") return true;
|
|
6826
|
+
if (SEMANTIC_AI_KINDS.has(resolvedKind)) return false;
|
|
6827
|
+
const scopeName = span2.instrumentationLibrary.name ?? "";
|
|
6828
|
+
if (HTTP_SCOPE_PREFIXES.some((prefix) => scopeName.startsWith(prefix))) return true;
|
|
6829
|
+
return span2.kind === import_api5.SpanKind.CLIENT && HTTP_ATTRIBUTE_KEYS.some((key) => key in attributes);
|
|
6830
|
+
}
|
|
6831
|
+
|
|
6607
6832
|
// src/core/span-processor.ts
|
|
6608
6833
|
var logger10 = getLogger();
|
|
6609
6834
|
function resolveLogFilePath(configuredPath) {
|
|
@@ -6875,6 +7100,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
6875
7100
|
onEnd(span2) {
|
|
6876
7101
|
this._activeSpans.delete(span2.spanContext().spanId);
|
|
6877
7102
|
if (this._closed) return;
|
|
7103
|
+
if (isHttpSpan(span2)) return;
|
|
6878
7104
|
if (span2.name === "neatlogs.trace.complete") {
|
|
6879
7105
|
const markerData = spanToDict(span2, { includeScope: true });
|
|
6880
7106
|
markerData.resource = { attributes: markerData.resource };
|
|
@@ -6991,7 +7217,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
6991
7217
|
attributes: unifiedAttrs,
|
|
6992
7218
|
resource: { attributes: resourceAttrs },
|
|
6993
7219
|
status: {
|
|
6994
|
-
code:
|
|
7220
|
+
code: import_api6.SpanStatusCode[span2.status.code] ?? String(span2.status.code),
|
|
6995
7221
|
description: span2.status.message ?? null
|
|
6996
7222
|
},
|
|
6997
7223
|
links: span2.links.map((link) => ({
|
|
@@ -7034,6 +7260,7 @@ var NeatlogsSpanProcessor = class {
|
|
|
7034
7260
|
const maskResult = scheduleMask(span2, spanData, this.mask ?? null);
|
|
7035
7261
|
const pending = maskResult.then((maskedSpanData) => {
|
|
7036
7262
|
if (maskedSpanData === null) return;
|
|
7263
|
+
if (isHttpSpan(span2, maskedSpanData.attributes ?? {})) return;
|
|
7037
7264
|
if (this._processedLogStream && !this._processedLogStream.destroyed) {
|
|
7038
7265
|
try {
|
|
7039
7266
|
this._processedLogStream.write(JSON.stringify(maskedSpanData) + "\n");
|
|
@@ -7113,9 +7340,9 @@ var NeatlogsSpanProcessor = class {
|
|
|
7113
7340
|
_markInterrupted(span2, cleanReason) {
|
|
7114
7341
|
span2.setAttribute("neatlogs.trace.interrupted", true);
|
|
7115
7342
|
span2.setAttribute("neatlogs.trace.termination.reason", cleanReason);
|
|
7116
|
-
if (span2.status.code ===
|
|
7343
|
+
if (span2.status.code === import_api6.SpanStatusCode.UNSET) {
|
|
7117
7344
|
span2.setStatus({
|
|
7118
|
-
code:
|
|
7345
|
+
code: import_api6.SpanStatusCode.ERROR,
|
|
7119
7346
|
message: `Interrupted during ${cleanReason}`
|
|
7120
7347
|
});
|
|
7121
7348
|
}
|
|
@@ -7130,10 +7357,10 @@ var NeatlogsSpanProcessor = class {
|
|
|
7130
7357
|
traceId: rootSpan.spanContext().traceId,
|
|
7131
7358
|
spanId: rootSpan.spanContext().spanId,
|
|
7132
7359
|
isRemote: false,
|
|
7133
|
-
traceFlags:
|
|
7360
|
+
traceFlags: import_api6.TraceFlags.SAMPLED
|
|
7134
7361
|
};
|
|
7135
|
-
const wrappedSpan =
|
|
7136
|
-
const ctx =
|
|
7362
|
+
const wrappedSpan = import_api6.trace.wrapSpanContext(spanCtx);
|
|
7363
|
+
const ctx = import_api6.trace.setSpan(import_api6.ROOT_CONTEXT, wrappedSpan);
|
|
7137
7364
|
const marker = markerTracer.startSpan("neatlogs.trace.complete", void 0, ctx);
|
|
7138
7365
|
marker.setAttribute("neatlogs.trace.complete", true);
|
|
7139
7366
|
marker.setAttribute("neatlogs.internal", true);
|
|
@@ -7302,7 +7529,8 @@ var CompletionMarkerSpanProcessor = class {
|
|
|
7302
7529
|
onStart(_span, _parentContext) {
|
|
7303
7530
|
}
|
|
7304
7531
|
onEnd(span2) {
|
|
7305
|
-
if (this.closed || span2.name === "neatlogs.trace.complete" || span2.parentSpanId)
|
|
7532
|
+
if (this.closed || span2.name === "neatlogs.trace.complete" || span2.parentSpanId || isHttpSpan(span2))
|
|
7533
|
+
return;
|
|
7306
7534
|
if (!this.source.ownsSpan(span2)) return;
|
|
7307
7535
|
const task = this.source.whenMaskComplete(span2).then((eligible) => {
|
|
7308
7536
|
if (!eligible || this.closed) return;
|
|
@@ -7351,7 +7579,7 @@ function getRegisteredClients() {
|
|
|
7351
7579
|
}
|
|
7352
7580
|
|
|
7353
7581
|
// src/core/filtering-exporter.ts
|
|
7354
|
-
var
|
|
7582
|
+
var import_api7 = require("@opentelemetry/api");
|
|
7355
7583
|
var import_core = require("@opentelemetry/core");
|
|
7356
7584
|
var import_resources = require("@opentelemetry/resources");
|
|
7357
7585
|
var MEDIA_RESOLUTION_CONCURRENCY = 4;
|
|
@@ -7390,7 +7618,7 @@ function toAttributes(value) {
|
|
|
7390
7618
|
function statusCode(value, fallback) {
|
|
7391
7619
|
if (typeof value === "number") return value;
|
|
7392
7620
|
if (typeof value === "string") {
|
|
7393
|
-
const resolved =
|
|
7621
|
+
const resolved = import_api7.SpanStatusCode[value];
|
|
7394
7622
|
if (typeof resolved === "number") return resolved;
|
|
7395
7623
|
}
|
|
7396
7624
|
return fallback;
|
|
@@ -7454,6 +7682,10 @@ var FilteringExporter = class {
|
|
|
7454
7682
|
_onPrepared;
|
|
7455
7683
|
export(spans, resultCallback) {
|
|
7456
7684
|
void mapWithConcurrency(spans, MEDIA_RESOLUTION_CONCURRENCY, async (span2) => {
|
|
7685
|
+
if (isHttpSpan(span2)) {
|
|
7686
|
+
discardPendingMedia(span2);
|
|
7687
|
+
return { span: null, mediaReady: true };
|
|
7688
|
+
}
|
|
7457
7689
|
if (span2.instrumentationLibrary.name === "next.js") {
|
|
7458
7690
|
discardPendingMedia(span2);
|
|
7459
7691
|
this.diagnostics?.recordFrameworkSpanDrop();
|
|
@@ -7474,6 +7706,11 @@ var FilteringExporter = class {
|
|
|
7474
7706
|
...masked.attributes && typeof masked.attributes === "object" ? masked.attributes : {}
|
|
7475
7707
|
};
|
|
7476
7708
|
const maskedData = { ...masked, attributes };
|
|
7709
|
+
const maskedSpan = maskedReadableSpan(span2, maskedData);
|
|
7710
|
+
if (isHttpSpan(maskedSpan)) {
|
|
7711
|
+
discardPendingMedia(span2);
|
|
7712
|
+
return { span: null, mediaReady: true };
|
|
7713
|
+
}
|
|
7477
7714
|
captureMediaInSnapshot(
|
|
7478
7715
|
span2,
|
|
7479
7716
|
maskedData,
|
|
@@ -7542,7 +7779,7 @@ var FilteringExporter = class {
|
|
|
7542
7779
|
};
|
|
7543
7780
|
|
|
7544
7781
|
// src/core/doctor-capture.ts
|
|
7545
|
-
var
|
|
7782
|
+
var import_api8 = require("@opentelemetry/api");
|
|
7546
7783
|
var MAX_TRACES = 16;
|
|
7547
7784
|
var MAX_SPANS_PER_TRACE = 64;
|
|
7548
7785
|
var MAX_BYTES_PER_TRACE = 256 * 1024;
|
|
@@ -7734,7 +7971,7 @@ function toDiagnosticSpan(span2) {
|
|
|
7734
7971
|
parent_span_id: span2.parentSpanId ?? null,
|
|
7735
7972
|
name: span2.name,
|
|
7736
7973
|
kind,
|
|
7737
|
-
status: span2.status.code ===
|
|
7974
|
+
status: span2.status.code === import_api8.SpanStatusCode.ERROR ? "ERROR" : span2.status.code === import_api8.SpanStatusCode.OK ? "OK" : "UNSET",
|
|
7738
7975
|
input: first(attributes, [`neatlogs.${kindKey}.input`]) ?? inputMessages,
|
|
7739
7976
|
output: first(attributes, [`neatlogs.${kindKey}.output`]) ?? outputMessages,
|
|
7740
7977
|
...choices ? { choices } : {},
|
|
@@ -8221,7 +8458,7 @@ var DeliveryDiagnostics = class {
|
|
|
8221
8458
|
};
|
|
8222
8459
|
|
|
8223
8460
|
// src/core/observable-batch-processors.ts
|
|
8224
|
-
var
|
|
8461
|
+
var import_api9 = require("@opentelemetry/api");
|
|
8225
8462
|
var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
8226
8463
|
var import_sdk_logs = require("@opentelemetry/sdk-logs");
|
|
8227
8464
|
var ObservableBatchSpanProcessor = class extends import_sdk_trace_base.BatchSpanProcessor {
|
|
@@ -8232,7 +8469,7 @@ var ObservableBatchSpanProcessor = class extends import_sdk_trace_base.BatchSpan
|
|
|
8232
8469
|
diagnostics;
|
|
8233
8470
|
onEnd(span2) {
|
|
8234
8471
|
const state = this;
|
|
8235
|
-
if ((span2.spanContext().traceFlags &
|
|
8472
|
+
if ((span2.spanContext().traceFlags & import_api9.TraceFlags.SAMPLED) !== 0 && state._finishedSpans.length >= state._maxQueueSize) {
|
|
8236
8473
|
discardPendingMedia(span2);
|
|
8237
8474
|
this.diagnostics.recordQueueDrop("span");
|
|
8238
8475
|
}
|
|
@@ -8304,7 +8541,7 @@ function log(msgTemplate, options) {
|
|
|
8304
8541
|
}
|
|
8305
8542
|
|
|
8306
8543
|
// src/prompt/client.ts
|
|
8307
|
-
var
|
|
8544
|
+
var import_api10 = require("@opentelemetry/api");
|
|
8308
8545
|
var import_core4 = require("@opentelemetry/core");
|
|
8309
8546
|
var PromptClientError = class extends Error {
|
|
8310
8547
|
constructor(message) {
|
|
@@ -9017,8 +9254,8 @@ var PromptClient = class _PromptClient {
|
|
|
9017
9254
|
let contextResult;
|
|
9018
9255
|
try {
|
|
9019
9256
|
try {
|
|
9020
|
-
const suppressedContext = (0, import_core4.suppressTracing)(
|
|
9021
|
-
contextResult =
|
|
9257
|
+
const suppressedContext = (0, import_core4.suppressTracing)(import_api10.context.active());
|
|
9258
|
+
contextResult = import_api10.context.with(suppressedContext, startTransport);
|
|
9022
9259
|
} catch {
|
|
9023
9260
|
}
|
|
9024
9261
|
if (contextResult && contextResult !== transportPromise) {
|
|
@@ -9139,19 +9376,7 @@ function _resetMastraCache() {
|
|
|
9139
9376
|
}
|
|
9140
9377
|
|
|
9141
9378
|
// src/version.ts
|
|
9142
|
-
var __version__ = "1.1.
|
|
9143
|
-
|
|
9144
|
-
// src/errors.ts
|
|
9145
|
-
var NeatlogsConfigurationError = class extends TypeError {
|
|
9146
|
-
code;
|
|
9147
|
-
option;
|
|
9148
|
-
constructor(code, option, message) {
|
|
9149
|
-
super(message);
|
|
9150
|
-
this.name = "NeatlogsConfigurationError";
|
|
9151
|
-
this.code = code;
|
|
9152
|
-
this.option = option;
|
|
9153
|
-
}
|
|
9154
|
-
};
|
|
9379
|
+
var __version__ = "1.1.21";
|
|
9155
9380
|
|
|
9156
9381
|
// src/core/deadline.ts
|
|
9157
9382
|
async function runByDeadline(operation, deadlineMs) {
|
|
@@ -9253,6 +9478,24 @@ var INIT_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
|
9253
9478
|
"piiSpanTypes",
|
|
9254
9479
|
"uploadAuthority"
|
|
9255
9480
|
]);
|
|
9481
|
+
function resolveInitEndpoint(endpoint) {
|
|
9482
|
+
const explicit = (endpoint ?? "").trim();
|
|
9483
|
+
if (explicit) return explicit;
|
|
9484
|
+
const fromEnv = (process.env.NEATLOGS_ENDPOINT ?? "").trim();
|
|
9485
|
+
return fromEnv || DEFAULT_INGEST_ENDPOINT;
|
|
9486
|
+
}
|
|
9487
|
+
function resolveIngestBaseUrl(endpoint) {
|
|
9488
|
+
const parsed = new URL(endpoint.trim());
|
|
9489
|
+
const path3 = parsed.pathname.replace(/\/+$/, "");
|
|
9490
|
+
if (path3 !== "" && path3 !== "/v1/traces") {
|
|
9491
|
+
throw new NeatlogsConfigurationError(
|
|
9492
|
+
"INVALID_ENDPOINT",
|
|
9493
|
+
"endpoint",
|
|
9494
|
+
"endpoint must be a base URL or an OTLP traces URL ending in /v1/traces."
|
|
9495
|
+
);
|
|
9496
|
+
}
|
|
9497
|
+
return parsed.origin;
|
|
9498
|
+
}
|
|
9256
9499
|
function validateInitOptions(options) {
|
|
9257
9500
|
const raw = options;
|
|
9258
9501
|
if (Object.prototype.hasOwnProperty.call(raw, "instrumentations")) {
|
|
@@ -9336,8 +9579,13 @@ function stableValue(value, ancestors = /* @__PURE__ */ new WeakSet(), location
|
|
|
9336
9579
|
ancestors.delete(value);
|
|
9337
9580
|
}
|
|
9338
9581
|
}
|
|
9582
|
+
function resolveApiKey(apiKey) {
|
|
9583
|
+
const explicit = (apiKey ?? "").trim();
|
|
9584
|
+
if (explicit) return explicit;
|
|
9585
|
+
return (process.env.NEATLOGS_API_KEY ?? "").trim();
|
|
9586
|
+
}
|
|
9339
9587
|
function initIdentity(options) {
|
|
9340
|
-
const apiKey = (options.apiKey
|
|
9588
|
+
const apiKey = resolveApiKey(options.apiKey);
|
|
9341
9589
|
const apiKeyDigest = (0, import_node_crypto4.createHash)("sha256").update(apiKey).digest("hex");
|
|
9342
9590
|
const serialized = stableValue({
|
|
9343
9591
|
apiKeyDigest,
|
|
@@ -9357,7 +9605,7 @@ function initIdentity(options) {
|
|
|
9357
9605
|
captureLogs: options.captureLogs ?? false,
|
|
9358
9606
|
pii: options.pii ?? null,
|
|
9359
9607
|
version: options.version ?? null,
|
|
9360
|
-
endpoint: options.endpoint
|
|
9608
|
+
endpoint: resolveInitEndpoint(options.endpoint),
|
|
9361
9609
|
batchSize: options.batchSize ?? 100,
|
|
9362
9610
|
flushInterval: options.flushInterval ?? 5,
|
|
9363
9611
|
piiEnabled: options.piiEnabled ?? null,
|
|
@@ -9437,12 +9685,7 @@ async function _performInit(options) {
|
|
|
9437
9685
|
);
|
|
9438
9686
|
}
|
|
9439
9687
|
_deliveryDiagnostics = new DeliveryDiagnostics();
|
|
9440
|
-
let resolvedKey;
|
|
9441
|
-
if (options.apiKey && options.apiKey.trim()) {
|
|
9442
|
-
resolvedKey = options.apiKey.trim();
|
|
9443
|
-
} else {
|
|
9444
|
-
resolvedKey = (process.env.NEATLOGS_API_KEY ?? "").trim();
|
|
9445
|
-
}
|
|
9688
|
+
let resolvedKey = resolveApiKey(options.apiKey);
|
|
9446
9689
|
let disableExportResolved = !!options.disableExport || ["true", "1", "yes"].includes(
|
|
9447
9690
|
(process.env.NEATLOGS_DISABLE_EXPORT ?? "").toLowerCase()
|
|
9448
9691
|
);
|
|
@@ -9463,8 +9706,8 @@ async function _performInit(options) {
|
|
|
9463
9706
|
}
|
|
9464
9707
|
_debugMode2 = options.debug ?? false;
|
|
9465
9708
|
const resolvedWorkflowName = _resolveWorkflowName(options.workflowName);
|
|
9466
|
-
const endpoint = options.endpoint
|
|
9467
|
-
const baseUrl =
|
|
9709
|
+
const endpoint = resolveInitEndpoint(options.endpoint);
|
|
9710
|
+
const baseUrl = resolveIngestBaseUrl(endpoint);
|
|
9468
9711
|
const uploadAuthority = disableExportResolved ? new DisabledUploadAuthority("export_disabled") : resolveUploadAuthority(
|
|
9469
9712
|
options.uploadAuthority,
|
|
9470
9713
|
process.env.NEATLOGS_UPLOADS_ENABLED,
|
|
@@ -9877,7 +10120,7 @@ function _doctorRuntimeSnapshot() {
|
|
|
9877
10120
|
}
|
|
9878
10121
|
|
|
9879
10122
|
// src/core/client.ts
|
|
9880
|
-
var
|
|
10123
|
+
var import_api11 = require("@opentelemetry/api");
|
|
9881
10124
|
var import_resources4 = require("@opentelemetry/resources");
|
|
9882
10125
|
var import_semantic_conventions2 = require("@opentelemetry/semantic-conventions");
|
|
9883
10126
|
var import_sdk_trace_node2 = require("@opentelemetry/sdk-trace-node");
|
|
@@ -9889,12 +10132,12 @@ var import_exporter_logs_otlp_proto2 = require("@opentelemetry/exporter-logs-otl
|
|
|
9889
10132
|
var logger14 = getLogger();
|
|
9890
10133
|
var closedTracer = {
|
|
9891
10134
|
startSpan() {
|
|
9892
|
-
return
|
|
10135
|
+
return import_api11.trace.wrapSpanContext(import_api11.INVALID_SPAN_CONTEXT);
|
|
9893
10136
|
},
|
|
9894
10137
|
startActiveSpan(_name, arg2, arg3, arg4) {
|
|
9895
10138
|
const fn = typeof arg2 === "function" ? arg2 : typeof arg3 === "function" ? arg3 : arg4;
|
|
9896
10139
|
return fn(
|
|
9897
|
-
|
|
10140
|
+
import_api11.trace.wrapSpanContext(import_api11.INVALID_SPAN_CONTEXT)
|
|
9898
10141
|
);
|
|
9899
10142
|
}
|
|
9900
10143
|
};
|
|
@@ -10372,7 +10615,7 @@ function Span(options) {
|
|
|
10372
10615
|
}
|
|
10373
10616
|
|
|
10374
10617
|
// src/core/propagation.ts
|
|
10375
|
-
var
|
|
10618
|
+
var import_api12 = require("@opentelemetry/api");
|
|
10376
10619
|
function injectTraceContext(carrier) {
|
|
10377
10620
|
const spanContext = getActiveNeatlogsSpan()?.spanContext();
|
|
10378
10621
|
if (!spanContext?.traceId || !spanContext.spanId) {
|
|
@@ -10381,7 +10624,7 @@ function injectTraceContext(carrier) {
|
|
|
10381
10624
|
if (spanContext.traceId === "00000000000000000000000000000000" || spanContext.spanId === "0000000000000000") {
|
|
10382
10625
|
return false;
|
|
10383
10626
|
}
|
|
10384
|
-
const flags = spanContext.traceFlags &
|
|
10627
|
+
const flags = spanContext.traceFlags & import_api12.TraceFlags.SAMPLED ? import_api12.TraceFlags.SAMPLED : import_api12.TraceFlags.NONE;
|
|
10385
10628
|
setHeader(
|
|
10386
10629
|
carrier,
|
|
10387
10630
|
"traceparent",
|
|
@@ -10401,7 +10644,7 @@ function extractTraceContext(carrier, fn) {
|
|
|
10401
10644
|
if (!spanContext) {
|
|
10402
10645
|
return fn();
|
|
10403
10646
|
}
|
|
10404
|
-
return withNeatlogsRemoteParent(
|
|
10647
|
+
return withNeatlogsRemoteParent(import_api12.trace.wrapSpanContext(spanContext), fn);
|
|
10405
10648
|
}
|
|
10406
10649
|
function parseTraceParent(traceparent, tracestate) {
|
|
10407
10650
|
const match = traceparent?.trim().match(
|
|
@@ -10414,9 +10657,9 @@ function parseTraceParent(traceparent, tracestate) {
|
|
|
10414
10657
|
return {
|
|
10415
10658
|
traceId: match[1],
|
|
10416
10659
|
spanId: match[2],
|
|
10417
|
-
traceFlags: flags &
|
|
10660
|
+
traceFlags: flags & import_api12.TraceFlags.SAMPLED ? import_api12.TraceFlags.SAMPLED : import_api12.TraceFlags.NONE,
|
|
10418
10661
|
isRemote: true,
|
|
10419
|
-
...tracestate?.trim() ? { traceState: (0,
|
|
10662
|
+
...tracestate?.trim() ? { traceState: (0, import_api12.createTraceState)(tracestate.trim()) } : {}
|
|
10420
10663
|
};
|
|
10421
10664
|
}
|
|
10422
10665
|
function getHeader(carrier, name) {
|
|
@@ -10437,10 +10680,12 @@ function setHeader(carrier, name, value) {
|
|
|
10437
10680
|
}
|
|
10438
10681
|
|
|
10439
10682
|
// src/ai-sdk.ts
|
|
10440
|
-
var
|
|
10683
|
+
var import_api13 = require("@opentelemetry/api");
|
|
10441
10684
|
var TRACER_NAME2 = "neatlogs.ai-sdk";
|
|
10442
10685
|
function createAITelemetry(opts = {}) {
|
|
10443
10686
|
const userMeta = opts.metadata ?? {};
|
|
10687
|
+
const neatlogsTracer = getRoutingNeatlogsTracer(TRACER_NAME2);
|
|
10688
|
+
const callerTracer = opts.tracer;
|
|
10444
10689
|
return {
|
|
10445
10690
|
isEnabled: true,
|
|
10446
10691
|
recordInputs: true,
|
|
@@ -10449,8 +10694,11 @@ function createAITelemetry(opts = {}) {
|
|
|
10449
10694
|
// internally, which would otherwise parent its native spans from the foreign
|
|
10450
10695
|
// global context AND push them onto it (so a co-tenant's next span inherits
|
|
10451
10696
|
// ours). The facade routes both through the private Neatlogs context.
|
|
10452
|
-
tracer:
|
|
10453
|
-
|
|
10697
|
+
tracer: callerTracer ? createMirroredTracer(callerTracer, neatlogsTracer) : neatlogsTracer,
|
|
10698
|
+
...opts.functionId !== void 0 ? { functionId: opts.functionId } : {},
|
|
10699
|
+
// The marker is an implementation detail used only when Neatlogs owns the
|
|
10700
|
+
// telemetry stream. Do not leak it into caller-owned providers.
|
|
10701
|
+
metadata: callerTracer ? { ...userMeta } : { ...userMeta, neatlogsWrapped: true }
|
|
10454
10702
|
};
|
|
10455
10703
|
}
|
|
10456
10704
|
function safeStringify2(value) {
|
|
@@ -10524,21 +10772,80 @@ var WRAPPED_FUNCTIONS = [
|
|
|
10524
10772
|
"embedMany",
|
|
10525
10773
|
"rerank"
|
|
10526
10774
|
];
|
|
10775
|
+
var WRAPPED_AGENT_CONSTRUCTORS = [
|
|
10776
|
+
"ToolLoopAgent",
|
|
10777
|
+
"Experimental_Agent"
|
|
10778
|
+
];
|
|
10779
|
+
var wrappedExports = /* @__PURE__ */ new WeakSet();
|
|
10780
|
+
var wrapperByOriginal = /* @__PURE__ */ new WeakMap();
|
|
10527
10781
|
function wrapAISDK(aiModule) {
|
|
10528
10782
|
const wrapped = { ...aiModule };
|
|
10529
10783
|
for (const name of WRAPPED_FUNCTIONS) {
|
|
10530
10784
|
const original = aiModule[name];
|
|
10531
10785
|
if (typeof original !== "function") continue;
|
|
10786
|
+
const existing = getExistingWrapper(original);
|
|
10787
|
+
if (existing) {
|
|
10788
|
+
wrapped[name] = existing;
|
|
10789
|
+
continue;
|
|
10790
|
+
}
|
|
10532
10791
|
if (name === "streamText" || name === "streamObject") {
|
|
10533
|
-
wrapped[name] =
|
|
10792
|
+
wrapped[name] = cacheWrapper(
|
|
10793
|
+
original,
|
|
10794
|
+
createStreamWrapper(name, original)
|
|
10795
|
+
);
|
|
10534
10796
|
} else {
|
|
10535
|
-
wrapped[name] =
|
|
10797
|
+
wrapped[name] = cacheWrapper(
|
|
10798
|
+
original,
|
|
10799
|
+
createAsyncWrapper(name, original)
|
|
10800
|
+
);
|
|
10536
10801
|
}
|
|
10537
10802
|
}
|
|
10803
|
+
for (const name of WRAPPED_AGENT_CONSTRUCTORS) {
|
|
10804
|
+
const original = aiModule[name];
|
|
10805
|
+
if (typeof original !== "function") continue;
|
|
10806
|
+
const existing = getExistingWrapper(original);
|
|
10807
|
+
wrapped[name] = existing ?? cacheWrapper(
|
|
10808
|
+
original,
|
|
10809
|
+
createAgentConstructorWrapper(original)
|
|
10810
|
+
);
|
|
10811
|
+
}
|
|
10538
10812
|
return wrapped;
|
|
10539
10813
|
}
|
|
10814
|
+
function getExistingWrapper(original) {
|
|
10815
|
+
if (wrappedExports.has(original)) return original;
|
|
10816
|
+
return wrapperByOriginal.get(original);
|
|
10817
|
+
}
|
|
10818
|
+
function cacheWrapper(original, wrapped) {
|
|
10819
|
+
wrapperByOriginal.set(original, wrapped);
|
|
10820
|
+
wrappedExports.add(wrapped);
|
|
10821
|
+
return wrapped;
|
|
10822
|
+
}
|
|
10823
|
+
function createAgentConstructorWrapper(original) {
|
|
10824
|
+
return new Proxy(original, {
|
|
10825
|
+
construct(target, args, newTarget) {
|
|
10826
|
+
if (args.length === 0 || typeof args[0] !== "object" || args[0] === null) {
|
|
10827
|
+
return Reflect.construct(target, args, newTarget);
|
|
10828
|
+
}
|
|
10829
|
+
const settings = mergeAgentSettings(args[0]);
|
|
10830
|
+
return Reflect.construct(target, [settings, ...args.slice(1)], newTarget);
|
|
10831
|
+
}
|
|
10832
|
+
});
|
|
10833
|
+
}
|
|
10834
|
+
function mergeAgentSettings(settings) {
|
|
10835
|
+
const merged = mergeTelemetry(settings);
|
|
10836
|
+
const userPrepareCall = settings.prepareCall;
|
|
10837
|
+
if (typeof userPrepareCall !== "function") return merged;
|
|
10838
|
+
return {
|
|
10839
|
+
...merged,
|
|
10840
|
+
prepareCall: async function wrappedPrepareCall(...args) {
|
|
10841
|
+
const prepared = await Reflect.apply(userPrepareCall, this, args);
|
|
10842
|
+
return prepared == null ? prepared : mergeTelemetry(prepared, settings.experimental_telemetry);
|
|
10843
|
+
}
|
|
10844
|
+
};
|
|
10845
|
+
}
|
|
10540
10846
|
function rootSpanKind(name) {
|
|
10541
|
-
if (name === "embed" || name === "embedMany" || name === "rerank")
|
|
10847
|
+
if (name === "embed" || name === "embedMany" || name === "rerank")
|
|
10848
|
+
return "CHAIN";
|
|
10542
10849
|
return "WORKFLOW";
|
|
10543
10850
|
}
|
|
10544
10851
|
function getParentContext() {
|
|
@@ -10635,134 +10942,143 @@ function createStreamWrapper(name, original) {
|
|
|
10635
10942
|
);
|
|
10636
10943
|
};
|
|
10637
10944
|
}
|
|
10638
|
-
function
|
|
10945
|
+
function createMirroredSpan(primary, secondary) {
|
|
10946
|
+
const mirrored = {
|
|
10947
|
+
spanContext() {
|
|
10948
|
+
return primary.spanContext();
|
|
10949
|
+
},
|
|
10950
|
+
setAttribute(key, value) {
|
|
10951
|
+
primary.setAttribute(key, value);
|
|
10952
|
+
secondary.setAttribute(key, value);
|
|
10953
|
+
return mirrored;
|
|
10954
|
+
},
|
|
10955
|
+
setAttributes(attributes) {
|
|
10956
|
+
primary.setAttributes(attributes);
|
|
10957
|
+
secondary.setAttributes(attributes);
|
|
10958
|
+
return mirrored;
|
|
10959
|
+
},
|
|
10960
|
+
addEvent(name, attributesOrStartTime, startTime) {
|
|
10961
|
+
primary.addEvent(name, attributesOrStartTime, startTime);
|
|
10962
|
+
secondary.addEvent(name, attributesOrStartTime, startTime);
|
|
10963
|
+
return mirrored;
|
|
10964
|
+
},
|
|
10965
|
+
addLink(link) {
|
|
10966
|
+
primary.addLink(link);
|
|
10967
|
+
secondary.addLink(link);
|
|
10968
|
+
return mirrored;
|
|
10969
|
+
},
|
|
10970
|
+
addLinks(links) {
|
|
10971
|
+
primary.addLinks(links);
|
|
10972
|
+
secondary.addLinks(links);
|
|
10973
|
+
return mirrored;
|
|
10974
|
+
},
|
|
10975
|
+
setStatus(status) {
|
|
10976
|
+
primary.setStatus(status);
|
|
10977
|
+
secondary.setStatus(status);
|
|
10978
|
+
return mirrored;
|
|
10979
|
+
},
|
|
10980
|
+
updateName(name) {
|
|
10981
|
+
primary.updateName(name);
|
|
10982
|
+
secondary.updateName(name);
|
|
10983
|
+
return mirrored;
|
|
10984
|
+
},
|
|
10985
|
+
end(endTime) {
|
|
10986
|
+
primary.end(endTime);
|
|
10987
|
+
secondary.end(endTime);
|
|
10988
|
+
},
|
|
10989
|
+
isRecording() {
|
|
10990
|
+
return primary.isRecording() || secondary.isRecording();
|
|
10991
|
+
},
|
|
10992
|
+
recordException(exception, time) {
|
|
10993
|
+
primary.recordException(exception, time);
|
|
10994
|
+
secondary.recordException(exception, time);
|
|
10995
|
+
}
|
|
10996
|
+
};
|
|
10997
|
+
return mirrored;
|
|
10998
|
+
}
|
|
10999
|
+
function createMirroredTracer(primary, secondary) {
|
|
11000
|
+
return {
|
|
11001
|
+
startSpan(name, options, context2) {
|
|
11002
|
+
const primarySpan = primary.startSpan(name, options, context2);
|
|
11003
|
+
const secondarySpan = secondary.startSpan(name, options);
|
|
11004
|
+
return createMirroredSpan(primarySpan, secondarySpan);
|
|
11005
|
+
},
|
|
11006
|
+
startActiveSpan: ((name, arg2, arg3, arg4) => {
|
|
11007
|
+
let options;
|
|
11008
|
+
let context2;
|
|
11009
|
+
let fn;
|
|
11010
|
+
if (typeof arg2 === "function") {
|
|
11011
|
+
fn = arg2;
|
|
11012
|
+
} else if (typeof arg3 === "function") {
|
|
11013
|
+
options = arg2;
|
|
11014
|
+
fn = arg3;
|
|
11015
|
+
} else {
|
|
11016
|
+
options = arg2;
|
|
11017
|
+
context2 = arg3;
|
|
11018
|
+
fn = arg4;
|
|
11019
|
+
}
|
|
11020
|
+
const runSecondary = (primarySpan) => {
|
|
11021
|
+
const onSecondarySpan = (secondarySpan) => fn(createMirroredSpan(primarySpan, secondarySpan));
|
|
11022
|
+
return options === void 0 ? secondary.startActiveSpan(name, onSecondarySpan) : secondary.startActiveSpan(name, options, onSecondarySpan);
|
|
11023
|
+
};
|
|
11024
|
+
if (context2 !== void 0) {
|
|
11025
|
+
return primary.startActiveSpan(
|
|
11026
|
+
name,
|
|
11027
|
+
options ?? {},
|
|
11028
|
+
context2,
|
|
11029
|
+
runSecondary
|
|
11030
|
+
);
|
|
11031
|
+
}
|
|
11032
|
+
return options === void 0 ? primary.startActiveSpan(name, runSecondary) : primary.startActiveSpan(name, options, runSecondary);
|
|
11033
|
+
})
|
|
11034
|
+
};
|
|
11035
|
+
}
|
|
11036
|
+
function mergeTelemetry(opts, fallbackTelemetry) {
|
|
11037
|
+
const requestedTelemetry = {
|
|
11038
|
+
...fallbackTelemetry,
|
|
11039
|
+
...opts?.experimental_telemetry,
|
|
11040
|
+
metadata: {
|
|
11041
|
+
...fallbackTelemetry?.metadata,
|
|
11042
|
+
...opts?.experimental_telemetry?.metadata
|
|
11043
|
+
}
|
|
11044
|
+
};
|
|
10639
11045
|
const baseTelemetry = createAITelemetry({
|
|
10640
|
-
|
|
11046
|
+
functionId: requestedTelemetry.functionId,
|
|
11047
|
+
metadata: requestedTelemetry.metadata,
|
|
11048
|
+
tracer: requestedTelemetry.tracer
|
|
10641
11049
|
});
|
|
11050
|
+
const callerTracer = requestedTelemetry.tracer;
|
|
11051
|
+
const hasCallerTracer = callerTracer !== void 0;
|
|
10642
11052
|
return {
|
|
10643
11053
|
...opts,
|
|
10644
11054
|
experimental_telemetry: {
|
|
10645
|
-
...
|
|
10646
|
-
...
|
|
11055
|
+
...baseTelemetry,
|
|
11056
|
+
...requestedTelemetry,
|
|
11057
|
+
isEnabled: true,
|
|
11058
|
+
recordInputs: requestedTelemetry.recordInputs ?? true,
|
|
11059
|
+
recordOutputs: requestedTelemetry.recordOutputs ?? true,
|
|
11060
|
+
tracer: baseTelemetry.tracer,
|
|
11061
|
+
// Do not add Neatlogs-only marker metadata to a caller-owned telemetry
|
|
11062
|
+
// pipeline such as Laminar. Both providers receive the same AI SDK span
|
|
11063
|
+
// data, while their providers, parent contexts, and exporters stay separate.
|
|
11064
|
+
metadata: hasCallerTracer ? requestedTelemetry.metadata : baseTelemetry.metadata
|
|
10647
11065
|
}
|
|
10648
11066
|
};
|
|
10649
11067
|
}
|
|
10650
11068
|
function recordSpanError(span2, err) {
|
|
10651
11069
|
if (err instanceof Error) {
|
|
10652
|
-
span2.setStatus({ code:
|
|
11070
|
+
span2.setStatus({ code: import_api13.SpanStatusCode.ERROR, message: err.message });
|
|
10653
11071
|
span2.recordException(err);
|
|
10654
11072
|
} else {
|
|
10655
|
-
span2.setStatus({ code:
|
|
11073
|
+
span2.setStatus({ code: import_api13.SpanStatusCode.ERROR, message: String(err) });
|
|
10656
11074
|
}
|
|
10657
11075
|
}
|
|
10658
11076
|
|
|
10659
11077
|
// src/openai.ts
|
|
10660
|
-
var
|
|
10661
|
-
|
|
10662
|
-
// src/core/auto-root.ts
|
|
10663
|
-
var import_api12 = require("@opentelemetry/api");
|
|
10664
|
-
var ROOT_KINDS = /* @__PURE__ */ new Set(["workflow", "chain", "agent", "mcp_tool"]);
|
|
10665
|
-
function autoRootEnabled() {
|
|
10666
|
-
const val = (process.env.NEATLOGS_AUTO_ROOT ?? "").trim().toLowerCase();
|
|
10667
|
-
return !["false", "0", "no", "off"].includes(val);
|
|
10668
|
-
}
|
|
10669
|
-
function resolveRootWorkflowName() {
|
|
10670
|
-
const clientName = getActiveClient()?.workflowName;
|
|
10671
|
-
if (typeof clientName === "string" && clientName.trim()) return clientName;
|
|
10672
|
-
try {
|
|
10673
|
-
const name = getSessionConfig()?.workflowName;
|
|
10674
|
-
if (typeof name === "string" && name.trim()) return name;
|
|
10675
|
-
} catch {
|
|
10676
|
-
}
|
|
10677
|
-
return "workflow";
|
|
10678
|
-
}
|
|
10679
|
-
function stampAutoRootIdentity(root) {
|
|
10680
|
-
applySessionAttributes(root, void 0, true);
|
|
10681
|
-
applyEndUserAttributes(root, void 0, void 0, true);
|
|
10682
|
-
}
|
|
10683
|
-
function wrapSpanWithRoot(child, root) {
|
|
10684
|
-
let ended = false;
|
|
10685
|
-
const proxy = new Proxy(child, {
|
|
10686
|
-
get(target, prop, _receiver) {
|
|
10687
|
-
if (prop === "end") {
|
|
10688
|
-
return (...args) => {
|
|
10689
|
-
if (ended) return;
|
|
10690
|
-
ended = true;
|
|
10691
|
-
try {
|
|
10692
|
-
target.end(...args);
|
|
10693
|
-
} finally {
|
|
10694
|
-
try {
|
|
10695
|
-
root.end();
|
|
10696
|
-
} catch {
|
|
10697
|
-
}
|
|
10698
|
-
}
|
|
10699
|
-
};
|
|
10700
|
-
}
|
|
10701
|
-
const value = Reflect.get(target, prop, target);
|
|
10702
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
10703
|
-
}
|
|
10704
|
-
});
|
|
10705
|
-
aliasMediaCaptureSpan(proxy, child);
|
|
10706
|
-
return proxy;
|
|
10707
|
-
}
|
|
10708
|
-
function maybeOpenAutoRoot(tracer, kind, baseCtx) {
|
|
10709
|
-
const k = String(kind ?? "").toLowerCase();
|
|
10710
|
-
const existing = getActiveNeatlogsSpan();
|
|
10711
|
-
if (!autoRootEnabled() || ROOT_KINDS.has(k) || existing !== void 0 && existing.isRecording()) {
|
|
10712
|
-
return { root: void 0, ctx: baseCtx };
|
|
10713
|
-
}
|
|
10714
|
-
const root = tracer.startSpan(
|
|
10715
|
-
resolveRootWorkflowName(),
|
|
10716
|
-
{ attributes: { "neatlogs.span.kind": "workflow", "neatlogs.auto_root": true } },
|
|
10717
|
-
baseCtx
|
|
10718
|
-
);
|
|
10719
|
-
stampAutoRootIdentity(root);
|
|
10720
|
-
return { root, ctx: import_api12.trace.setSpan(baseCtx, root) };
|
|
10721
|
-
}
|
|
10722
|
-
function endAutoRoot(root) {
|
|
10723
|
-
if (!root) return;
|
|
10724
|
-
try {
|
|
10725
|
-
root.end();
|
|
10726
|
-
} catch {
|
|
10727
|
-
}
|
|
10728
|
-
}
|
|
10729
|
-
var AutoRootTracer = class {
|
|
10730
|
-
constructor(_tracer) {
|
|
10731
|
-
this._tracer = _tracer;
|
|
10732
|
-
}
|
|
10733
|
-
_tracer;
|
|
10734
|
-
startSpan(name, options, context2) {
|
|
10735
|
-
const kind = String(
|
|
10736
|
-
options?.attributes?.["neatlogs.span.kind"] ?? ""
|
|
10737
|
-
).toLowerCase();
|
|
10738
|
-
const ctx = context2 ?? getNeatlogsParentContext();
|
|
10739
|
-
const parent = getActiveNeatlogsSpan();
|
|
10740
|
-
const needsRoot = autoRootEnabled() && !ROOT_KINDS.has(kind) && !(parent !== void 0 && parent.isRecording());
|
|
10741
|
-
if (!needsRoot) {
|
|
10742
|
-
return this._tracer.startSpan(name, options, ctx);
|
|
10743
|
-
}
|
|
10744
|
-
const root = this._tracer.startSpan(
|
|
10745
|
-
resolveRootWorkflowName(),
|
|
10746
|
-
{ attributes: { "neatlogs.span.kind": "workflow", "neatlogs.auto_root": true } },
|
|
10747
|
-
ctx
|
|
10748
|
-
);
|
|
10749
|
-
stampAutoRootIdentity(root);
|
|
10750
|
-
const childCtx = import_api12.trace.setSpan(ctx, root);
|
|
10751
|
-
const child = this._tracer.startSpan(name, options, childCtx);
|
|
10752
|
-
return wrapSpanWithRoot(child, root);
|
|
10753
|
-
}
|
|
10754
|
-
// startActiveSpan is used by traceTool (callback-scoped, always under an
|
|
10755
|
-
// active span in practice) — pass straight through, no auto-root.
|
|
10756
|
-
startActiveSpan = ((...args) => this._tracer.startActiveSpan(
|
|
10757
|
-
...args
|
|
10758
|
-
));
|
|
10759
|
-
};
|
|
10760
|
-
function getProviderTracer(name) {
|
|
10761
|
-
return new AutoRootTracer(getNeatlogsTracer(name));
|
|
10762
|
-
}
|
|
11078
|
+
var import_api15 = require("@opentelemetry/api");
|
|
10763
11079
|
|
|
10764
11080
|
// src/core/choice-accumulator.ts
|
|
10765
|
-
var
|
|
11081
|
+
var import_api14 = require("@opentelemetry/api");
|
|
10766
11082
|
var import_node_crypto5 = require("crypto");
|
|
10767
11083
|
function hash(value) {
|
|
10768
11084
|
return (0, import_node_crypto5.createHash)("sha256").update(value).digest("hex");
|
|
@@ -10964,9 +11280,9 @@ var ChoiceAccumulator = class {
|
|
|
10964
11280
|
this.apply(span2);
|
|
10965
11281
|
if (interrupted) {
|
|
10966
11282
|
span2.setAttribute("neatlogs.stream.cancelled", true);
|
|
10967
|
-
span2.setStatus({ code:
|
|
11283
|
+
span2.setStatus({ code: import_api14.SpanStatusCode.UNSET });
|
|
10968
11284
|
} else {
|
|
10969
|
-
span2.setStatus({ code:
|
|
11285
|
+
span2.setStatus({ code: import_api14.SpanStatusCode.OK });
|
|
10970
11286
|
}
|
|
10971
11287
|
span2.end();
|
|
10972
11288
|
}
|
|
@@ -10976,9 +11292,9 @@ var ChoiceAccumulator = class {
|
|
|
10976
11292
|
this.apply(span2);
|
|
10977
11293
|
if (error?.name === "AbortError") {
|
|
10978
11294
|
span2.setAttribute("neatlogs.stream.cancelled", true);
|
|
10979
|
-
span2.setStatus({ code:
|
|
11295
|
+
span2.setStatus({ code: import_api14.SpanStatusCode.UNSET });
|
|
10980
11296
|
} else {
|
|
10981
|
-
span2.setStatus({ code:
|
|
11297
|
+
span2.setStatus({ code: import_api14.SpanStatusCode.ERROR, message: String(error) });
|
|
10982
11298
|
if (error instanceof Error) span2.recordException(error);
|
|
10983
11299
|
}
|
|
10984
11300
|
span2.end();
|
|
@@ -11143,7 +11459,7 @@ function traceTool(name, fn) {
|
|
|
11143
11459
|
"output.value",
|
|
11144
11460
|
safeStringify3(captureMedia(span2, "neatlogs.tool.output", result, "output"))
|
|
11145
11461
|
);
|
|
11146
|
-
span2.setStatus({ code:
|
|
11462
|
+
span2.setStatus({ code: import_api15.SpanStatusCode.OK });
|
|
11147
11463
|
return result;
|
|
11148
11464
|
} catch (err) {
|
|
11149
11465
|
recordError(span2, err);
|
|
@@ -11377,7 +11693,7 @@ function wrapResponsesAsyncIterableStream(stream, span2) {
|
|
|
11377
11693
|
);
|
|
11378
11694
|
if (error?.name === "AbortError") {
|
|
11379
11695
|
span2.setAttribute("neatlogs.stream.cancelled", true);
|
|
11380
|
-
span2.setStatus({ code:
|
|
11696
|
+
span2.setStatus({ code: import_api15.SpanStatusCode.UNSET });
|
|
11381
11697
|
span2.end();
|
|
11382
11698
|
return;
|
|
11383
11699
|
}
|
|
@@ -11451,9 +11767,9 @@ function finalizeResponsesResponse(span2, response, streamedText = "", interrupt
|
|
|
11451
11767
|
applyResponsesResponseAttributes(span2, response, streamedText);
|
|
11452
11768
|
if (interrupted) {
|
|
11453
11769
|
span2.setAttribute("neatlogs.stream.cancelled", true);
|
|
11454
|
-
span2.setStatus({ code:
|
|
11770
|
+
span2.setStatus({ code: import_api15.SpanStatusCode.UNSET });
|
|
11455
11771
|
} else {
|
|
11456
|
-
span2.setStatus({ code:
|
|
11772
|
+
span2.setStatus({ code: import_api15.SpanStatusCode.OK });
|
|
11457
11773
|
}
|
|
11458
11774
|
span2.end();
|
|
11459
11775
|
}
|
|
@@ -11668,16 +11984,16 @@ function safeStringify3(value) {
|
|
|
11668
11984
|
}
|
|
11669
11985
|
function recordError(span2, err) {
|
|
11670
11986
|
if (err instanceof Error) {
|
|
11671
|
-
span2.setStatus({ code:
|
|
11987
|
+
span2.setStatus({ code: import_api15.SpanStatusCode.ERROR, message: err.message });
|
|
11672
11988
|
span2.recordException(err);
|
|
11673
11989
|
} else {
|
|
11674
|
-
span2.setStatus({ code:
|
|
11990
|
+
span2.setStatus({ code: import_api15.SpanStatusCode.ERROR, message: String(err) });
|
|
11675
11991
|
}
|
|
11676
11992
|
span2.end();
|
|
11677
11993
|
}
|
|
11678
11994
|
|
|
11679
11995
|
// src/anthropic.ts
|
|
11680
|
-
var
|
|
11996
|
+
var import_api16 = require("@opentelemetry/api");
|
|
11681
11997
|
var TRACER_NAME4 = "neatlogs.anthropic";
|
|
11682
11998
|
function wrapAnthropic(client) {
|
|
11683
11999
|
return wrapNamespace2(client, []);
|
|
@@ -11706,7 +12022,7 @@ function traceTool2(name, fn) {
|
|
|
11706
12022
|
"output.value",
|
|
11707
12023
|
safeStringify4(captureMedia(span2, "neatlogs.tool.output", result, "output"))
|
|
11708
12024
|
);
|
|
11709
|
-
span2.setStatus({ code:
|
|
12025
|
+
span2.setStatus({ code: import_api16.SpanStatusCode.OK });
|
|
11710
12026
|
return result;
|
|
11711
12027
|
} catch (err) {
|
|
11712
12028
|
recordError2(span2, err);
|
|
@@ -11801,7 +12117,7 @@ function wrapStreamIterable(stream, span2) {
|
|
|
11801
12117
|
const accumulated = newAnthropicStreamAccumulator();
|
|
11802
12118
|
const originalAsyncIterator = stream[Symbol.asyncIterator]?.bind(stream);
|
|
11803
12119
|
if (!originalAsyncIterator) {
|
|
11804
|
-
span2.setStatus({ code:
|
|
12120
|
+
span2.setStatus({ code: import_api16.SpanStatusCode.OK });
|
|
11805
12121
|
span2.end();
|
|
11806
12122
|
return stream;
|
|
11807
12123
|
}
|
|
@@ -11854,7 +12170,7 @@ function wrapMessageStream(messageStream, span2) {
|
|
|
11854
12170
|
if (finalMsg) {
|
|
11855
12171
|
finalizeMessageResponse(span2, finalMsg);
|
|
11856
12172
|
} else {
|
|
11857
|
-
span2.setStatus({ code:
|
|
12173
|
+
span2.setStatus({ code: import_api16.SpanStatusCode.OK });
|
|
11858
12174
|
span2.end();
|
|
11859
12175
|
}
|
|
11860
12176
|
});
|
|
@@ -12005,7 +12321,7 @@ function finalizeStreamEvents(span2, accumulated) {
|
|
|
12005
12321
|
if (accumulated.stopReason) span2.setAttribute("neatlogs.llm.stop_reason", accumulated.stopReason);
|
|
12006
12322
|
setUsageAttrs(span2, accumulated.usage);
|
|
12007
12323
|
applyStreamDiagnostics2(span2, accumulated);
|
|
12008
|
-
span2.setStatus({ code:
|
|
12324
|
+
span2.setStatus({ code: import_api16.SpanStatusCode.OK });
|
|
12009
12325
|
span2.end();
|
|
12010
12326
|
}
|
|
12011
12327
|
function finalizeMessageResponse(span2, response) {
|
|
@@ -12046,7 +12362,7 @@ function finalizeMessageResponse(span2, response) {
|
|
|
12046
12362
|
setUsageAttrs(span2, response?.usage);
|
|
12047
12363
|
if (response?.model) span2.setAttribute("neatlogs.llm.model_name", response.model);
|
|
12048
12364
|
if (response?.stop_reason) span2.setAttribute("neatlogs.llm.stop_reason", response.stop_reason);
|
|
12049
|
-
span2.setStatus({ code:
|
|
12365
|
+
span2.setStatus({ code: import_api16.SpanStatusCode.OK });
|
|
12050
12366
|
span2.end();
|
|
12051
12367
|
}
|
|
12052
12368
|
function markStreamIncomplete(accumulated, reason) {
|
|
@@ -12165,16 +12481,16 @@ function safeStringify4(value) {
|
|
|
12165
12481
|
}
|
|
12166
12482
|
function recordError2(span2, err) {
|
|
12167
12483
|
if (err instanceof Error) {
|
|
12168
|
-
span2.setStatus({ code:
|
|
12484
|
+
span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: err.message });
|
|
12169
12485
|
span2.recordException(err);
|
|
12170
12486
|
} else {
|
|
12171
|
-
span2.setStatus({ code:
|
|
12487
|
+
span2.setStatus({ code: import_api16.SpanStatusCode.ERROR, message: String(err) });
|
|
12172
12488
|
}
|
|
12173
12489
|
span2.end();
|
|
12174
12490
|
}
|
|
12175
12491
|
|
|
12176
12492
|
// src/azure-openai.ts
|
|
12177
|
-
var
|
|
12493
|
+
var import_api17 = require("@opentelemetry/api");
|
|
12178
12494
|
var TRACER_NAME5 = "neatlogs.azure_openai";
|
|
12179
12495
|
var PROVIDER = "azure";
|
|
12180
12496
|
var SYSTEM = "azure";
|
|
@@ -12205,7 +12521,7 @@ function traceTool3(name, fn) {
|
|
|
12205
12521
|
"output.value",
|
|
12206
12522
|
safeStringify5(captureMedia(span2, "neatlogs.tool.output", result, "output"))
|
|
12207
12523
|
);
|
|
12208
|
-
span2.setStatus({ code:
|
|
12524
|
+
span2.setStatus({ code: import_api17.SpanStatusCode.OK });
|
|
12209
12525
|
return result;
|
|
12210
12526
|
} catch (err) {
|
|
12211
12527
|
recordError3(span2, err);
|
|
@@ -12346,7 +12662,7 @@ function tracedResponsesCreate2(original) {
|
|
|
12346
12662
|
if (response.usage.input_tokens != null) span2.setAttribute("neatlogs.llm.token_count.prompt", response.usage.input_tokens);
|
|
12347
12663
|
if (response.usage.output_tokens != null) span2.setAttribute("neatlogs.llm.token_count.completion", response.usage.output_tokens);
|
|
12348
12664
|
}
|
|
12349
|
-
span2.setStatus({ code:
|
|
12665
|
+
span2.setStatus({ code: import_api17.SpanStatusCode.OK });
|
|
12350
12666
|
span2.end();
|
|
12351
12667
|
return response;
|
|
12352
12668
|
},
|
|
@@ -12452,7 +12768,7 @@ function finalizeChatResponse2(span2, response) {
|
|
|
12452
12768
|
}
|
|
12453
12769
|
}
|
|
12454
12770
|
if (response?.model) span2.setAttribute("neatlogs.llm.model_name", response.model);
|
|
12455
|
-
span2.setStatus({ code:
|
|
12771
|
+
span2.setStatus({ code: import_api17.SpanStatusCode.OK });
|
|
12456
12772
|
span2.end();
|
|
12457
12773
|
}
|
|
12458
12774
|
function sanitizedJsonToolArguments2(span2, prefix, value) {
|
|
@@ -12502,16 +12818,16 @@ function safeStringify5(value) {
|
|
|
12502
12818
|
}
|
|
12503
12819
|
function recordError3(span2, err) {
|
|
12504
12820
|
if (err instanceof Error) {
|
|
12505
|
-
span2.setStatus({ code:
|
|
12821
|
+
span2.setStatus({ code: import_api17.SpanStatusCode.ERROR, message: err.message });
|
|
12506
12822
|
span2.recordException(err);
|
|
12507
12823
|
} else {
|
|
12508
|
-
span2.setStatus({ code:
|
|
12824
|
+
span2.setStatus({ code: import_api17.SpanStatusCode.ERROR, message: String(err) });
|
|
12509
12825
|
}
|
|
12510
12826
|
span2.end();
|
|
12511
12827
|
}
|
|
12512
12828
|
|
|
12513
12829
|
// src/vertex-ai.ts
|
|
12514
|
-
var
|
|
12830
|
+
var import_api18 = require("@opentelemetry/api");
|
|
12515
12831
|
var TRACER_NAME6 = "neatlogs.vertex_ai";
|
|
12516
12832
|
var PROVIDER2 = "vertex_ai";
|
|
12517
12833
|
var SYSTEM2 = "vertexai";
|
|
@@ -12542,7 +12858,7 @@ function traceTool4(name, fn) {
|
|
|
12542
12858
|
"output.value",
|
|
12543
12859
|
safeStringify6(captureMedia(span2, "neatlogs.tool.output", result, "output"))
|
|
12544
12860
|
);
|
|
12545
|
-
span2.setStatus({ code:
|
|
12861
|
+
span2.setStatus({ code: import_api18.SpanStatusCode.OK });
|
|
12546
12862
|
return result;
|
|
12547
12863
|
} catch (err) {
|
|
12548
12864
|
recordError4(span2, err);
|
|
@@ -12658,7 +12974,7 @@ function tracedEmbedContent(original) {
|
|
|
12658
12974
|
const vals = embeddings[0]?.values;
|
|
12659
12975
|
if (Array.isArray(vals)) span2.setAttribute("neatlogs.embedding.dimensions", vals.length);
|
|
12660
12976
|
}
|
|
12661
|
-
span2.setStatus({ code:
|
|
12977
|
+
span2.setStatus({ code: import_api18.SpanStatusCode.OK });
|
|
12662
12978
|
span2.end();
|
|
12663
12979
|
return response;
|
|
12664
12980
|
},
|
|
@@ -12684,7 +13000,7 @@ function tracedCountTokens(original) {
|
|
|
12684
13000
|
return Promise.resolve(result).then(
|
|
12685
13001
|
(response) => {
|
|
12686
13002
|
if (response?.totalTokens != null) span2.setAttribute("neatlogs.llm.token_count.prompt", response.totalTokens);
|
|
12687
|
-
span2.setStatus({ code:
|
|
13003
|
+
span2.setStatus({ code: import_api18.SpanStatusCode.OK });
|
|
12688
13004
|
span2.end();
|
|
12689
13005
|
return response;
|
|
12690
13006
|
},
|
|
@@ -12924,7 +13240,7 @@ function finalizeStreamChunks(span2, accumulated) {
|
|
|
12924
13240
|
}
|
|
12925
13241
|
setUsage(span2, accumulated.usage);
|
|
12926
13242
|
applyStreamDiagnostics3(span2, accumulated);
|
|
12927
|
-
span2.setStatus({ code:
|
|
13243
|
+
span2.setStatus({ code: import_api18.SpanStatusCode.OK });
|
|
12928
13244
|
span2.end();
|
|
12929
13245
|
}
|
|
12930
13246
|
function finalizeResponse(span2, response) {
|
|
@@ -12957,7 +13273,7 @@ function finalizeResponse(span2, response) {
|
|
|
12957
13273
|
span2.setAttribute("neatlogs.llm.output_messages.0.content", textParts.join(""));
|
|
12958
13274
|
}
|
|
12959
13275
|
setUsage(span2, response?.usageMetadata);
|
|
12960
|
-
span2.setStatus({ code:
|
|
13276
|
+
span2.setStatus({ code: import_api18.SpanStatusCode.OK });
|
|
12961
13277
|
span2.end();
|
|
12962
13278
|
}
|
|
12963
13279
|
function setUsage(span2, usage) {
|
|
@@ -13030,16 +13346,16 @@ function safeStringify6(value) {
|
|
|
13030
13346
|
}
|
|
13031
13347
|
function recordError4(span2, err) {
|
|
13032
13348
|
if (err instanceof Error) {
|
|
13033
|
-
span2.setStatus({ code:
|
|
13349
|
+
span2.setStatus({ code: import_api18.SpanStatusCode.ERROR, message: err.message });
|
|
13034
13350
|
span2.recordException(err);
|
|
13035
13351
|
} else {
|
|
13036
|
-
span2.setStatus({ code:
|
|
13352
|
+
span2.setStatus({ code: import_api18.SpanStatusCode.ERROR, message: String(err) });
|
|
13037
13353
|
}
|
|
13038
13354
|
span2.end();
|
|
13039
13355
|
}
|
|
13040
13356
|
|
|
13041
13357
|
// src/google-genai.ts
|
|
13042
|
-
var
|
|
13358
|
+
var import_api19 = require("@opentelemetry/api");
|
|
13043
13359
|
var TRACER_NAME7 = "neatlogs.google_genai";
|
|
13044
13360
|
var PROVIDER3 = "google";
|
|
13045
13361
|
var SYSTEM3 = "google_genai";
|
|
@@ -13070,7 +13386,7 @@ function traceTool5(name, fn) {
|
|
|
13070
13386
|
"output.value",
|
|
13071
13387
|
safeStringify7(captureMedia(span2, "neatlogs.tool.output", result, "output"))
|
|
13072
13388
|
);
|
|
13073
|
-
span2.setStatus({ code:
|
|
13389
|
+
span2.setStatus({ code: import_api19.SpanStatusCode.OK });
|
|
13074
13390
|
return result;
|
|
13075
13391
|
} catch (err) {
|
|
13076
13392
|
recordError5(span2, err);
|
|
@@ -13186,7 +13502,7 @@ function tracedEmbedContent2(original) {
|
|
|
13186
13502
|
const vals = embeddings[0]?.values;
|
|
13187
13503
|
if (Array.isArray(vals)) span2.setAttribute("neatlogs.embedding.dimensions", vals.length);
|
|
13188
13504
|
}
|
|
13189
|
-
span2.setStatus({ code:
|
|
13505
|
+
span2.setStatus({ code: import_api19.SpanStatusCode.OK });
|
|
13190
13506
|
span2.end();
|
|
13191
13507
|
return response;
|
|
13192
13508
|
},
|
|
@@ -13212,7 +13528,7 @@ function tracedCountTokens2(original) {
|
|
|
13212
13528
|
return Promise.resolve(result).then(
|
|
13213
13529
|
(response) => {
|
|
13214
13530
|
if (response?.totalTokens != null) span2.setAttribute("neatlogs.llm.token_count.prompt", response.totalTokens);
|
|
13215
|
-
span2.setStatus({ code:
|
|
13531
|
+
span2.setStatus({ code: import_api19.SpanStatusCode.OK });
|
|
13216
13532
|
span2.end();
|
|
13217
13533
|
return response;
|
|
13218
13534
|
},
|
|
@@ -13452,7 +13768,7 @@ function finalizeStreamChunks2(span2, accumulated) {
|
|
|
13452
13768
|
}
|
|
13453
13769
|
setUsage2(span2, accumulated.usage);
|
|
13454
13770
|
applyStreamDiagnostics4(span2, accumulated);
|
|
13455
|
-
span2.setStatus({ code:
|
|
13771
|
+
span2.setStatus({ code: import_api19.SpanStatusCode.OK });
|
|
13456
13772
|
span2.end();
|
|
13457
13773
|
}
|
|
13458
13774
|
function finalizeResponse2(span2, response) {
|
|
@@ -13485,7 +13801,7 @@ function finalizeResponse2(span2, response) {
|
|
|
13485
13801
|
span2.setAttribute("neatlogs.llm.output_messages.0.content", textParts.join(""));
|
|
13486
13802
|
}
|
|
13487
13803
|
setUsage2(span2, response?.usageMetadata);
|
|
13488
|
-
span2.setStatus({ code:
|
|
13804
|
+
span2.setStatus({ code: import_api19.SpanStatusCode.OK });
|
|
13489
13805
|
span2.end();
|
|
13490
13806
|
}
|
|
13491
13807
|
function setUsage2(span2, usage) {
|
|
@@ -13558,16 +13874,16 @@ function safeStringify7(value) {
|
|
|
13558
13874
|
}
|
|
13559
13875
|
function recordError5(span2, err) {
|
|
13560
13876
|
if (err instanceof Error) {
|
|
13561
|
-
span2.setStatus({ code:
|
|
13877
|
+
span2.setStatus({ code: import_api19.SpanStatusCode.ERROR, message: err.message });
|
|
13562
13878
|
span2.recordException(err);
|
|
13563
13879
|
} else {
|
|
13564
|
-
span2.setStatus({ code:
|
|
13880
|
+
span2.setStatus({ code: import_api19.SpanStatusCode.ERROR, message: String(err) });
|
|
13565
13881
|
}
|
|
13566
13882
|
span2.end();
|
|
13567
13883
|
}
|
|
13568
13884
|
|
|
13569
13885
|
// src/bedrock.ts
|
|
13570
|
-
var
|
|
13886
|
+
var import_api20 = require("@opentelemetry/api");
|
|
13571
13887
|
var TRACER_NAME8 = "neatlogs.bedrock";
|
|
13572
13888
|
var PROVIDER4 = "bedrock";
|
|
13573
13889
|
function traceTool6(name, fn) {
|
|
@@ -13594,7 +13910,7 @@ function traceTool6(name, fn) {
|
|
|
13594
13910
|
"output.value",
|
|
13595
13911
|
safeStringify8(captureMedia(span2, "neatlogs.tool.output", result, "output"))
|
|
13596
13912
|
);
|
|
13597
|
-
span2.setStatus({ code:
|
|
13913
|
+
span2.setStatus({ code: import_api20.SpanStatusCode.OK });
|
|
13598
13914
|
return result;
|
|
13599
13915
|
} catch (err) {
|
|
13600
13916
|
recordError6(span2, err);
|
|
@@ -13755,7 +14071,7 @@ function finalizeConverse(span2, response) {
|
|
|
13755
14071
|
}
|
|
13756
14072
|
if (response?.stopReason) span2.setAttribute("neatlogs.llm.finish_reason", String(response.stopReason));
|
|
13757
14073
|
setConverseUsage(span2, response?.usage);
|
|
13758
|
-
span2.setStatus({ code:
|
|
14074
|
+
span2.setStatus({ code: import_api20.SpanStatusCode.OK });
|
|
13759
14075
|
span2.end();
|
|
13760
14076
|
}
|
|
13761
14077
|
function setConverseUsage(span2, usage) {
|
|
@@ -13769,7 +14085,7 @@ function setConverseUsage(span2, usage) {
|
|
|
13769
14085
|
function wrapConverseStream(response, span2) {
|
|
13770
14086
|
const stream = response?.stream;
|
|
13771
14087
|
if (!stream || typeof stream[Symbol.asyncIterator] !== "function") {
|
|
13772
|
-
span2.setStatus({ code:
|
|
14088
|
+
span2.setStatus({ code: import_api20.SpanStatusCode.OK });
|
|
13773
14089
|
span2.end();
|
|
13774
14090
|
return response;
|
|
13775
14091
|
}
|
|
@@ -13875,7 +14191,7 @@ function finalizeConverseStream(span2, textParts, toolCalls, finishReason, usage
|
|
|
13875
14191
|
if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
|
|
13876
14192
|
setConverseUsage(span2, usage);
|
|
13877
14193
|
applyStreamDiagnostics5(span2, budget);
|
|
13878
|
-
span2.setStatus({ code:
|
|
14194
|
+
span2.setStatus({ code: import_api20.SpanStatusCode.OK });
|
|
13879
14195
|
span2.end();
|
|
13880
14196
|
}
|
|
13881
14197
|
function isEmbeddingModel(modelId) {
|
|
@@ -13919,7 +14235,7 @@ function tracedInvokeModel(originalSend, command, input, rest, isStream) {
|
|
|
13919
14235
|
finalizeInvoke(span2, vendor, decodeBody(response?.body));
|
|
13920
14236
|
}
|
|
13921
14237
|
} catch {
|
|
13922
|
-
span2.setStatus({ code:
|
|
14238
|
+
span2.setStatus({ code: import_api20.SpanStatusCode.OK });
|
|
13923
14239
|
span2.end();
|
|
13924
14240
|
}
|
|
13925
14241
|
return response;
|
|
@@ -13944,7 +14260,7 @@ function finalizeInvokeEmbedding(span2, body) {
|
|
|
13944
14260
|
span2.setAttribute("neatlogs.llm.token_count.prompt", body.inputTextTokenCount);
|
|
13945
14261
|
span2.setAttribute("neatlogs.embedding.token_count", body.inputTextTokenCount);
|
|
13946
14262
|
}
|
|
13947
|
-
span2.setStatus({ code:
|
|
14263
|
+
span2.setStatus({ code: import_api20.SpanStatusCode.OK });
|
|
13948
14264
|
span2.end();
|
|
13949
14265
|
}
|
|
13950
14266
|
function decodeBody(body) {
|
|
@@ -14071,13 +14387,13 @@ function finalizeInvoke(span2, vendor, body) {
|
|
|
14071
14387
|
span2.setAttribute("neatlogs.llm.token_count.total", promptTokens + completionTokens);
|
|
14072
14388
|
}
|
|
14073
14389
|
if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
|
|
14074
|
-
span2.setStatus({ code:
|
|
14390
|
+
span2.setStatus({ code: import_api20.SpanStatusCode.OK });
|
|
14075
14391
|
span2.end();
|
|
14076
14392
|
}
|
|
14077
14393
|
function wrapInvokeStream(response, span2, vendor) {
|
|
14078
14394
|
const body = response?.body;
|
|
14079
14395
|
if (!body || typeof body[Symbol.asyncIterator] !== "function") {
|
|
14080
|
-
span2.setStatus({ code:
|
|
14396
|
+
span2.setStatus({ code: import_api20.SpanStatusCode.OK });
|
|
14081
14397
|
span2.end();
|
|
14082
14398
|
return response;
|
|
14083
14399
|
}
|
|
@@ -14131,7 +14447,7 @@ function wrapInvokeStream(response, span2, vendor) {
|
|
|
14131
14447
|
if (completionTokens != null) span2.setAttribute("neatlogs.llm.token_count.completion", completionTokens);
|
|
14132
14448
|
if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
|
|
14133
14449
|
applyStreamDiagnostics5(span2, budget);
|
|
14134
|
-
span2.setStatus({ code:
|
|
14450
|
+
span2.setStatus({ code: import_api20.SpanStatusCode.OK });
|
|
14135
14451
|
span2.end();
|
|
14136
14452
|
};
|
|
14137
14453
|
const wrappedBody = {
|
|
@@ -14246,16 +14562,16 @@ function safeStringify8(value) {
|
|
|
14246
14562
|
}
|
|
14247
14563
|
function recordError6(span2, err) {
|
|
14248
14564
|
if (err instanceof Error) {
|
|
14249
|
-
span2.setStatus({ code:
|
|
14565
|
+
span2.setStatus({ code: import_api20.SpanStatusCode.ERROR, message: err.message });
|
|
14250
14566
|
span2.recordException(err);
|
|
14251
14567
|
} else {
|
|
14252
|
-
span2.setStatus({ code:
|
|
14568
|
+
span2.setStatus({ code: import_api20.SpanStatusCode.ERROR, message: String(err) });
|
|
14253
14569
|
}
|
|
14254
14570
|
span2.end();
|
|
14255
14571
|
}
|
|
14256
14572
|
|
|
14257
14573
|
// src/langchain.ts
|
|
14258
|
-
var
|
|
14574
|
+
var import_api21 = require("@opentelemetry/api");
|
|
14259
14575
|
var TRACER_NAME9 = "neatlogs.langchain";
|
|
14260
14576
|
function langchainHandler(opts) {
|
|
14261
14577
|
return new NeatlogsCallbackHandler(opts);
|
|
@@ -14281,7 +14597,7 @@ var NeatlogsCallbackHandler = class {
|
|
|
14281
14597
|
const base = getNeatlogsBaseContext();
|
|
14282
14598
|
const parentSpan = parentRunId ? this._spans.get(parentRunId) : void 0;
|
|
14283
14599
|
if (parentSpan) {
|
|
14284
|
-
return
|
|
14600
|
+
return import_api21.trace.setSpan(base, parentSpan);
|
|
14285
14601
|
}
|
|
14286
14602
|
const tracer = getNeatlogsTracer(TRACER_NAME9);
|
|
14287
14603
|
const { root, ctx } = maybeOpenAutoRoot(tracer, kind, base);
|
|
@@ -14314,7 +14630,7 @@ var NeatlogsCallbackHandler = class {
|
|
|
14314
14630
|
const span2 = this._spans.get(runId);
|
|
14315
14631
|
if (!span2) return;
|
|
14316
14632
|
if (outputs) span2.setAttribute("output.value", safeStringify9(outputs));
|
|
14317
|
-
span2.setStatus({ code:
|
|
14633
|
+
span2.setStatus({ code: import_api21.SpanStatusCode.OK });
|
|
14318
14634
|
span2.end();
|
|
14319
14635
|
this._spans.delete(runId);
|
|
14320
14636
|
this._endAutoRoot(runId);
|
|
@@ -14322,7 +14638,7 @@ var NeatlogsCallbackHandler = class {
|
|
|
14322
14638
|
async handleChainError(error, runId) {
|
|
14323
14639
|
const span2 = this._spans.get(runId);
|
|
14324
14640
|
if (!span2) return;
|
|
14325
|
-
span2.setStatus({ code:
|
|
14641
|
+
span2.setStatus({ code: import_api21.SpanStatusCode.ERROR, message: error.message });
|
|
14326
14642
|
span2.recordException(error);
|
|
14327
14643
|
span2.end();
|
|
14328
14644
|
this._spans.delete(runId);
|
|
@@ -14412,7 +14728,7 @@ var NeatlogsCallbackHandler = class {
|
|
|
14412
14728
|
span2.setAttribute("neatlogs.llm.token_count.total", usage.totalTokens ?? usage.total_tokens);
|
|
14413
14729
|
}
|
|
14414
14730
|
}
|
|
14415
|
-
span2.setStatus({ code:
|
|
14731
|
+
span2.setStatus({ code: import_api21.SpanStatusCode.OK });
|
|
14416
14732
|
span2.end();
|
|
14417
14733
|
this._spans.delete(runId);
|
|
14418
14734
|
this._endAutoRoot(runId);
|
|
@@ -14422,7 +14738,7 @@ var NeatlogsCallbackHandler = class {
|
|
|
14422
14738
|
async handleLLMError(error, runId) {
|
|
14423
14739
|
const span2 = this._spans.get(runId);
|
|
14424
14740
|
if (!span2) return;
|
|
14425
|
-
span2.setStatus({ code:
|
|
14741
|
+
span2.setStatus({ code: import_api21.SpanStatusCode.ERROR, message: error.message });
|
|
14426
14742
|
span2.recordException(error);
|
|
14427
14743
|
span2.end();
|
|
14428
14744
|
this._spans.delete(runId);
|
|
@@ -14446,7 +14762,7 @@ var NeatlogsCallbackHandler = class {
|
|
|
14446
14762
|
const span2 = this._spans.get(runId);
|
|
14447
14763
|
if (!span2) return;
|
|
14448
14764
|
span2.setAttribute("output.value", String(output));
|
|
14449
|
-
span2.setStatus({ code:
|
|
14765
|
+
span2.setStatus({ code: import_api21.SpanStatusCode.OK });
|
|
14450
14766
|
span2.end();
|
|
14451
14767
|
this._spans.delete(runId);
|
|
14452
14768
|
this._endAutoRoot(runId);
|
|
@@ -14454,7 +14770,7 @@ var NeatlogsCallbackHandler = class {
|
|
|
14454
14770
|
async handleToolError(error, runId) {
|
|
14455
14771
|
const span2 = this._spans.get(runId);
|
|
14456
14772
|
if (!span2) return;
|
|
14457
|
-
span2.setStatus({ code:
|
|
14773
|
+
span2.setStatus({ code: import_api21.SpanStatusCode.ERROR, message: error.message });
|
|
14458
14774
|
span2.recordException(error);
|
|
14459
14775
|
span2.end();
|
|
14460
14776
|
this._spans.delete(runId);
|
|
@@ -14485,7 +14801,7 @@ var NeatlogsCallbackHandler = class {
|
|
|
14485
14801
|
}
|
|
14486
14802
|
}
|
|
14487
14803
|
}
|
|
14488
|
-
span2.setStatus({ code:
|
|
14804
|
+
span2.setStatus({ code: import_api21.SpanStatusCode.OK });
|
|
14489
14805
|
span2.end();
|
|
14490
14806
|
this._spans.delete(runId);
|
|
14491
14807
|
this._endAutoRoot(runId);
|
|
@@ -14493,7 +14809,7 @@ var NeatlogsCallbackHandler = class {
|
|
|
14493
14809
|
async handleRetrieverError(error, runId) {
|
|
14494
14810
|
const span2 = this._spans.get(runId);
|
|
14495
14811
|
if (!span2) return;
|
|
14496
|
-
span2.setStatus({ code:
|
|
14812
|
+
span2.setStatus({ code: import_api21.SpanStatusCode.ERROR, message: error.message });
|
|
14497
14813
|
span2.recordException(error);
|
|
14498
14814
|
span2.end();
|
|
14499
14815
|
this._spans.delete(runId);
|
|
@@ -14534,7 +14850,7 @@ function strandsHooks(_agent) {
|
|
|
14534
14850
|
}
|
|
14535
14851
|
|
|
14536
14852
|
// src/openai-agents.ts
|
|
14537
|
-
var
|
|
14853
|
+
var import_api22 = require("@opentelemetry/api");
|
|
14538
14854
|
var TRACER_NAME10 = "neatlogs.openai_agents";
|
|
14539
14855
|
function openaiAgentsProcessor() {
|
|
14540
14856
|
return new NeatlogsTraceProcessor();
|
|
@@ -14563,7 +14879,7 @@ var NeatlogsTraceProcessor = class {
|
|
|
14563
14879
|
if (startTime) {
|
|
14564
14880
|
span2.setAttribute("neatlogs.metrics.duration_ms", Date.now() - startTime);
|
|
14565
14881
|
}
|
|
14566
|
-
span2.setStatus({ code:
|
|
14882
|
+
span2.setStatus({ code: import_api22.SpanStatusCode.OK });
|
|
14567
14883
|
span2.end();
|
|
14568
14884
|
this._spans.delete(key);
|
|
14569
14885
|
this._startTimes.delete(key);
|
|
@@ -14578,7 +14894,7 @@ var NeatlogsTraceProcessor = class {
|
|
|
14578
14894
|
const base = getNeatlogsBaseContext();
|
|
14579
14895
|
const parentKey = String(span2?.parentId ?? span2?.traceId ?? span2?.trace_id ?? "");
|
|
14580
14896
|
const parentSpan = this._spans.get(parentKey);
|
|
14581
|
-
const parentCtx = parentSpan ?
|
|
14897
|
+
const parentCtx = parentSpan ? import_api22.trace.setSpan(base, parentSpan) : base;
|
|
14582
14898
|
let otelSpan;
|
|
14583
14899
|
if (spanType === "agent" || spanType === "agent_run") {
|
|
14584
14900
|
const agentName = data?.name ?? data?.agent_name ?? "agent";
|
|
@@ -14687,13 +15003,13 @@ var NeatlogsTraceProcessor = class {
|
|
|
14687
15003
|
const error = data?.error ?? span2?.error;
|
|
14688
15004
|
if (error) {
|
|
14689
15005
|
if (error instanceof Error) {
|
|
14690
|
-
otelSpan.setStatus({ code:
|
|
15006
|
+
otelSpan.setStatus({ code: import_api22.SpanStatusCode.ERROR, message: error.message });
|
|
14691
15007
|
otelSpan.recordException(error);
|
|
14692
15008
|
} else {
|
|
14693
|
-
otelSpan.setStatus({ code:
|
|
15009
|
+
otelSpan.setStatus({ code: import_api22.SpanStatusCode.ERROR, message: String(error) });
|
|
14694
15010
|
}
|
|
14695
15011
|
} else {
|
|
14696
|
-
otelSpan.setStatus({ code:
|
|
15012
|
+
otelSpan.setStatus({ code: import_api22.SpanStatusCode.OK });
|
|
14697
15013
|
}
|
|
14698
15014
|
if (startTime) {
|
|
14699
15015
|
otelSpan.setAttribute("neatlogs.llm.metrics.duration_ms", Date.now() - startTime);
|
|
@@ -14704,7 +15020,7 @@ var NeatlogsTraceProcessor = class {
|
|
|
14704
15020
|
}
|
|
14705
15021
|
shutdown() {
|
|
14706
15022
|
for (const [, span2] of this._spans) {
|
|
14707
|
-
span2.setStatus({ code:
|
|
15023
|
+
span2.setStatus({ code: import_api22.SpanStatusCode.ERROR, message: "Processor shutdown before span completed" });
|
|
14708
15024
|
span2.end();
|
|
14709
15025
|
}
|
|
14710
15026
|
this._spans.clear();
|
|
@@ -14722,7 +15038,7 @@ function safeStringify10(value) {
|
|
|
14722
15038
|
}
|
|
14723
15039
|
|
|
14724
15040
|
// src/mastra-wrap.ts
|
|
14725
|
-
var
|
|
15041
|
+
var import_api23 = require("@opentelemetry/api");
|
|
14726
15042
|
var TRACER_NAME11 = "neatlogs.mastra";
|
|
14727
15043
|
var PATCH_FLAG = "_neatlogs_patched";
|
|
14728
15044
|
function wrapMastra(entity) {
|
|
@@ -15029,7 +15345,7 @@ function wrapRootMastra(mastra) {
|
|
|
15029
15345
|
function wrapStreamingOutput(output, span2) {
|
|
15030
15346
|
if (!output) {
|
|
15031
15347
|
span2.setAttribute("output.value", toOutputValue(output));
|
|
15032
|
-
span2.setStatus({ code:
|
|
15348
|
+
span2.setStatus({ code: import_api23.SpanStatusCode.OK });
|
|
15033
15349
|
span2.end();
|
|
15034
15350
|
return output;
|
|
15035
15351
|
}
|
|
@@ -15038,7 +15354,7 @@ function wrapStreamingOutput(output, span2) {
|
|
|
15038
15354
|
if (ended) return;
|
|
15039
15355
|
ended = true;
|
|
15040
15356
|
if (err) recordError7(span2, err);
|
|
15041
|
-
else span2.setStatus({ code:
|
|
15357
|
+
else span2.setStatus({ code: import_api23.SpanStatusCode.OK });
|
|
15042
15358
|
span2.end();
|
|
15043
15359
|
};
|
|
15044
15360
|
if (output.text && typeof output.text.then === "function") {
|
|
@@ -15251,7 +15567,7 @@ function wrapModelStreamingResult(result, span2) {
|
|
|
15251
15567
|
if (!stream || typeof stream.getReader !== "function") {
|
|
15252
15568
|
if (result?.usage) recordUsage(span2, result.usage);
|
|
15253
15569
|
span2.setAttribute("output.value", safeStringify11(result ?? { streamCompleted: true }));
|
|
15254
|
-
span2.setStatus({ code:
|
|
15570
|
+
span2.setStatus({ code: import_api23.SpanStatusCode.OK });
|
|
15255
15571
|
span2.end();
|
|
15256
15572
|
return result;
|
|
15257
15573
|
}
|
|
@@ -15264,7 +15580,7 @@ function wrapModelStreamingResult(result, span2) {
|
|
|
15264
15580
|
recordError7(span2, err);
|
|
15265
15581
|
} else {
|
|
15266
15582
|
finalizeModelStreamSpan(span2, capture);
|
|
15267
|
-
span2.setStatus({ code:
|
|
15583
|
+
span2.setStatus({ code: import_api23.SpanStatusCode.OK });
|
|
15268
15584
|
}
|
|
15269
15585
|
span2.end();
|
|
15270
15586
|
};
|
|
@@ -15447,7 +15763,7 @@ function withActiveSpan(name, attrs, fn) {
|
|
|
15447
15763
|
return withNeatlogsSpan(span2, async () => {
|
|
15448
15764
|
try {
|
|
15449
15765
|
const result = await fn(span2);
|
|
15450
|
-
span2.setStatus({ code:
|
|
15766
|
+
span2.setStatus({ code: import_api23.SpanStatusCode.OK });
|
|
15451
15767
|
return result;
|
|
15452
15768
|
} catch (err) {
|
|
15453
15769
|
recordError7(span2, err);
|
|
@@ -15494,15 +15810,15 @@ function recordError7(span2, err) {
|
|
|
15494
15810
|
error: err instanceof Error ? { name: err.name, message: err.message } : { message: String(err) }
|
|
15495
15811
|
}));
|
|
15496
15812
|
if (err instanceof Error) {
|
|
15497
|
-
span2.setStatus({ code:
|
|
15813
|
+
span2.setStatus({ code: import_api23.SpanStatusCode.ERROR, message: err.message });
|
|
15498
15814
|
span2.recordException(err);
|
|
15499
15815
|
} else {
|
|
15500
|
-
span2.setStatus({ code:
|
|
15816
|
+
span2.setStatus({ code: import_api23.SpanStatusCode.ERROR, message: String(err) });
|
|
15501
15817
|
}
|
|
15502
15818
|
}
|
|
15503
15819
|
|
|
15504
15820
|
// src/pi-agent.ts
|
|
15505
|
-
var
|
|
15821
|
+
var import_api24 = require("@opentelemetry/api");
|
|
15506
15822
|
var TRACER_NAME12 = "neatlogs.pi-agent";
|
|
15507
15823
|
var PATCH_FLAG2 = "_neatlogs_patched";
|
|
15508
15824
|
var HARNESS_METHOD_FLAG = "_neatlogs_harness_methods_patched";
|
|
@@ -15579,7 +15895,7 @@ function emitHarnessOperation(method, input, result, failure2, model, capturedPa
|
|
|
15579
15895
|
let root;
|
|
15580
15896
|
const inputText = safeStringify12(input ?? {});
|
|
15581
15897
|
const outputText = failure2 ? `[error] ${failure2 instanceof Error ? failure2.message : String(failure2)}` : harnessOperationOutput(method, result);
|
|
15582
|
-
if (!
|
|
15898
|
+
if (!import_api24.trace.getSpan(parent)?.isRecording()) {
|
|
15583
15899
|
root = tracer.startSpan(
|
|
15584
15900
|
`pi_agent.harness.${method}`,
|
|
15585
15901
|
{
|
|
@@ -15591,7 +15907,7 @@ function emitHarnessOperation(method, input, result, failure2, model, capturedPa
|
|
|
15591
15907
|
},
|
|
15592
15908
|
parent
|
|
15593
15909
|
);
|
|
15594
|
-
parent =
|
|
15910
|
+
parent = import_api24.trace.setSpan(parent, root);
|
|
15595
15911
|
}
|
|
15596
15912
|
const chain = tracer.startSpan(
|
|
15597
15913
|
`pi_agent.harness.${method}`,
|
|
@@ -15605,7 +15921,7 @@ function emitHarnessOperation(method, input, result, failure2, model, capturedPa
|
|
|
15605
15921
|
},
|
|
15606
15922
|
parent
|
|
15607
15923
|
);
|
|
15608
|
-
const chainCtx =
|
|
15924
|
+
const chainCtx = import_api24.trace.setSpan(parent, chain);
|
|
15609
15925
|
const usage = harnessOperationUsage(method, result);
|
|
15610
15926
|
const madeModelCall = observedModelCall ?? (failure2 ? isHarnessSummarizationFailure(failure2) : method === "compact" ? Boolean(result?.usage) : Boolean(result?.summaryEntry) && result.summaryEntry.fromHook !== true);
|
|
15611
15927
|
if (madeModelCall || failure2) {
|
|
@@ -15646,9 +15962,9 @@ function emitHarnessOperation(method, input, result, failure2, model, capturedPa
|
|
|
15646
15962
|
if (failure2) {
|
|
15647
15963
|
const message = failure2 instanceof Error ? failure2.message : String(failure2);
|
|
15648
15964
|
chain.setAttribute("neatlogs.error.message", message);
|
|
15649
|
-
chain.setStatus({ code:
|
|
15965
|
+
chain.setStatus({ code: import_api24.SpanStatusCode.ERROR, message });
|
|
15650
15966
|
} else {
|
|
15651
|
-
chain.setStatus({ code:
|
|
15967
|
+
chain.setStatus({ code: import_api24.SpanStatusCode.OK });
|
|
15652
15968
|
}
|
|
15653
15969
|
chain.end(endedAt);
|
|
15654
15970
|
if (root) {
|
|
@@ -15656,9 +15972,9 @@ function emitHarnessOperation(method, input, result, failure2, model, capturedPa
|
|
|
15656
15972
|
if (failure2) {
|
|
15657
15973
|
const message = failure2 instanceof Error ? failure2.message : String(failure2);
|
|
15658
15974
|
root.setAttribute("neatlogs.error.message", message);
|
|
15659
|
-
root.setStatus({ code:
|
|
15975
|
+
root.setStatus({ code: import_api24.SpanStatusCode.ERROR, message });
|
|
15660
15976
|
} else {
|
|
15661
|
-
root.setStatus({ code:
|
|
15977
|
+
root.setStatus({ code: import_api24.SpanStatusCode.OK });
|
|
15662
15978
|
}
|
|
15663
15979
|
root.end(endedAt);
|
|
15664
15980
|
}
|
|
@@ -15685,7 +16001,7 @@ function closeLlmFailure(llm, failure2, endedAt) {
|
|
|
15685
16001
|
const message = failure2 instanceof Error ? failure2.message : String(failure2);
|
|
15686
16002
|
llm.span.setAttribute("output.value", `[error] ${message}`);
|
|
15687
16003
|
llm.span.setAttribute("neatlogs.error.message", message);
|
|
15688
|
-
llm.span.setStatus({ code:
|
|
16004
|
+
llm.span.setStatus({ code: import_api24.SpanStatusCode.ERROR, message });
|
|
15689
16005
|
llm.span.end(endedAt);
|
|
15690
16006
|
}
|
|
15691
16007
|
function tracePiAgentEvents(getTranscript) {
|
|
@@ -15707,13 +16023,13 @@ function tracePiStream(streamFn) {
|
|
|
15707
16023
|
const state = { toolSpans: /* @__PURE__ */ new Map(), inputMessages: [], turnIndex: 0 };
|
|
15708
16024
|
state.inputMessages = promptMessagesOf(context2);
|
|
15709
16025
|
let parent = getNeatlogsParentContext();
|
|
15710
|
-
if (!
|
|
16026
|
+
if (!import_api24.trace.getSpan(parent)?.isRecording()) {
|
|
15711
16027
|
root = tracer.startSpan(
|
|
15712
16028
|
"pi_agent.stream",
|
|
15713
16029
|
{ attributes: { "neatlogs.span.kind": "WORKFLOW" } },
|
|
15714
16030
|
parent
|
|
15715
16031
|
);
|
|
15716
|
-
parent =
|
|
16032
|
+
parent = import_api24.trace.setSpan(parent, root);
|
|
15717
16033
|
const rootInput = state.inputMessages.length ? safeStringify12({ messages: state.inputMessages }) : void 0;
|
|
15718
16034
|
if (rootInput) root.setAttribute("input.value", rootInput);
|
|
15719
16035
|
}
|
|
@@ -15791,7 +16107,7 @@ function closeStreamFailure(llm, root, err) {
|
|
|
15791
16107
|
try {
|
|
15792
16108
|
llm?.span.setAttribute("output.value", `[error] ${message}`);
|
|
15793
16109
|
llm?.span.setAttribute("neatlogs.error.message", message);
|
|
15794
|
-
llm?.span.setStatus({ code:
|
|
16110
|
+
llm?.span.setStatus({ code: import_api24.SpanStatusCode.ERROR, message });
|
|
15795
16111
|
llm?.span.end();
|
|
15796
16112
|
} catch {
|
|
15797
16113
|
}
|
|
@@ -15811,7 +16127,7 @@ function closeStreamRoot(root, msg, error) {
|
|
|
15811
16127
|
} else if (error) {
|
|
15812
16128
|
root.setAttribute("output.value", `[error] ${error}`);
|
|
15813
16129
|
root.setAttribute("neatlogs.error.message", error);
|
|
15814
|
-
root.setStatus({ code:
|
|
16130
|
+
root.setStatus({ code: import_api24.SpanStatusCode.ERROR, message: error });
|
|
15815
16131
|
}
|
|
15816
16132
|
root.end();
|
|
15817
16133
|
} catch {
|
|
@@ -15850,7 +16166,7 @@ function handleEvent(tracer, state, event, getTranscript) {
|
|
|
15850
16166
|
base
|
|
15851
16167
|
);
|
|
15852
16168
|
state.agentSpan = span2;
|
|
15853
|
-
state.agentCtx =
|
|
16169
|
+
state.agentCtx = import_api24.trace.setSpan(base, span2);
|
|
15854
16170
|
state.inputMessages = transcriptRows(getTranscript?.());
|
|
15855
16171
|
state.turnIndex = 0;
|
|
15856
16172
|
state.runInput = void 0;
|
|
@@ -15874,7 +16190,7 @@ function handleEvent(tracer, state, event, getTranscript) {
|
|
|
15874
16190
|
parent
|
|
15875
16191
|
);
|
|
15876
16192
|
state.turnSpan = span2;
|
|
15877
|
-
state.turnCtx =
|
|
16193
|
+
state.turnCtx = import_api24.trace.setSpan(parent, span2);
|
|
15878
16194
|
state.turnHasInput = !!priorInput;
|
|
15879
16195
|
state.turnStartEpochMs = Date.now();
|
|
15880
16196
|
break;
|
|
@@ -15964,10 +16280,10 @@ function handleEvent(tracer, state, event, getTranscript) {
|
|
|
15964
16280
|
span2.setAttribute("output.value", safeStringify12(event.result));
|
|
15965
16281
|
}
|
|
15966
16282
|
if (event.isError) {
|
|
15967
|
-
span2.setStatus({ code:
|
|
16283
|
+
span2.setStatus({ code: import_api24.SpanStatusCode.ERROR, message: toolErrorText(event.result) });
|
|
15968
16284
|
span2.setAttribute("neatlogs.tool.is_error", true);
|
|
15969
16285
|
} else {
|
|
15970
|
-
span2.setStatus({ code:
|
|
16286
|
+
span2.setStatus({ code: import_api24.SpanStatusCode.OK });
|
|
15971
16287
|
}
|
|
15972
16288
|
span2.end();
|
|
15973
16289
|
if (event.toolCallId) state.toolSpans.delete(event.toolCallId);
|
|
@@ -15976,7 +16292,7 @@ function handleEvent(tracer, state, event, getTranscript) {
|
|
|
15976
16292
|
case "agent_end": {
|
|
15977
16293
|
for (const ts of state.toolSpans.values()) {
|
|
15978
16294
|
try {
|
|
15979
|
-
ts.setStatus({ code:
|
|
16295
|
+
ts.setStatus({ code: import_api24.SpanStatusCode.ERROR, message: "run ended before tool completed" });
|
|
15980
16296
|
ts.end();
|
|
15981
16297
|
} catch {
|
|
15982
16298
|
}
|
|
@@ -15985,7 +16301,7 @@ function handleEvent(tracer, state, event, getTranscript) {
|
|
|
15985
16301
|
if (state.llm) {
|
|
15986
16302
|
try {
|
|
15987
16303
|
state.llm.span.setAttribute("output.value", "[incomplete] run ended mid-stream");
|
|
15988
|
-
state.llm.span.setStatus({ code:
|
|
16304
|
+
state.llm.span.setStatus({ code: import_api24.SpanStatusCode.ERROR, message: "run ended mid-stream" });
|
|
15989
16305
|
state.llm.span.end();
|
|
15990
16306
|
} catch {
|
|
15991
16307
|
}
|
|
@@ -16013,9 +16329,9 @@ function handleEvent(tracer, state, event, getTranscript) {
|
|
|
16013
16329
|
if (err) {
|
|
16014
16330
|
state.agentSpan.setAttribute("neatlogs.agent.stop_reason", err.stopReason);
|
|
16015
16331
|
if (err.message) state.agentSpan.setAttribute("neatlogs.error.message", err.message);
|
|
16016
|
-
state.agentSpan.setStatus({ code:
|
|
16332
|
+
state.agentSpan.setStatus({ code: import_api24.SpanStatusCode.ERROR, message: err.message ?? err.stopReason });
|
|
16017
16333
|
} else {
|
|
16018
|
-
state.agentSpan.setStatus({ code:
|
|
16334
|
+
state.agentSpan.setStatus({ code: import_api24.SpanStatusCode.OK });
|
|
16019
16335
|
}
|
|
16020
16336
|
state.agentSpan.end();
|
|
16021
16337
|
state.agentSpan = void 0;
|
|
@@ -16068,9 +16384,9 @@ function terminalSummary(msg) {
|
|
|
16068
16384
|
function applyStopReasonStatus(span2, msg) {
|
|
16069
16385
|
const reason = msg?.stopReason;
|
|
16070
16386
|
if (reason === "aborted" || reason === "error") {
|
|
16071
|
-
span2.setStatus({ code:
|
|
16387
|
+
span2.setStatus({ code: import_api24.SpanStatusCode.ERROR, message: msg?.errorMessage ?? reason });
|
|
16072
16388
|
} else {
|
|
16073
|
-
span2.setStatus({ code:
|
|
16389
|
+
span2.setStatus({ code: import_api24.SpanStatusCode.OK });
|
|
16074
16390
|
}
|
|
16075
16391
|
}
|
|
16076
16392
|
function isContentDelta(type) {
|
|
@@ -16238,7 +16554,7 @@ function safeStringify12(value) {
|
|
|
16238
16554
|
}
|
|
16239
16555
|
|
|
16240
16556
|
// src/claude-agent-sdk.ts
|
|
16241
|
-
var
|
|
16557
|
+
var import_api25 = require("@opentelemetry/api");
|
|
16242
16558
|
var TRACER_NAME13 = "neatlogs.claude_agent_sdk";
|
|
16243
16559
|
var ROOT_SCOPE = "__root__";
|
|
16244
16560
|
function wrapClaudeAgentSDK(sdk, options = {}) {
|
|
@@ -16274,7 +16590,7 @@ function wrapQuery(original, options) {
|
|
|
16274
16590
|
} else if (params && isAsyncIterable2(params.prompt)) {
|
|
16275
16591
|
params = { ...params, prompt: tapPromptStream(params.prompt, promptRef) };
|
|
16276
16592
|
}
|
|
16277
|
-
const agentCtx =
|
|
16593
|
+
const agentCtx = import_api25.trace.setSpan(getNeatlogsBaseContext(), agentSpan);
|
|
16278
16594
|
const queryObj = withNeatlogsSpan(agentSpan, () => original(params, ...rest));
|
|
16279
16595
|
return instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRef);
|
|
16280
16596
|
};
|
|
@@ -16294,7 +16610,7 @@ async function* tapPromptStream(prompt, ref) {
|
|
|
16294
16610
|
function instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRef) {
|
|
16295
16611
|
const originalAsyncIterator = queryObj?.[Symbol.asyncIterator]?.bind(queryObj);
|
|
16296
16612
|
if (!originalAsyncIterator) {
|
|
16297
|
-
agentSpan.setStatus({ code:
|
|
16613
|
+
agentSpan.setStatus({ code: import_api25.SpanStatusCode.OK });
|
|
16298
16614
|
agentSpan.end();
|
|
16299
16615
|
return queryObj;
|
|
16300
16616
|
}
|
|
@@ -16331,7 +16647,7 @@ function instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRe
|
|
|
16331
16647
|
if (status === "error") {
|
|
16332
16648
|
recordError8(agentSpan, err);
|
|
16333
16649
|
} else {
|
|
16334
|
-
agentSpan.setStatus({ code:
|
|
16650
|
+
agentSpan.setStatus({ code: import_api25.SpanStatusCode.OK });
|
|
16335
16651
|
agentSpan.end();
|
|
16336
16652
|
}
|
|
16337
16653
|
};
|
|
@@ -16373,7 +16689,7 @@ function instrumentQueryIterable(queryObj, agentSpan, agentCtx, tracer, promptRe
|
|
|
16373
16689
|
function closeScope(scope, status) {
|
|
16374
16690
|
try {
|
|
16375
16691
|
if (scope.finalText) scope.span.setAttribute("output.value", scope.finalText);
|
|
16376
|
-
scope.span.setStatus({ code: status === "ok" ?
|
|
16692
|
+
scope.span.setStatus({ code: status === "ok" ? import_api25.SpanStatusCode.OK : import_api25.SpanStatusCode.ERROR });
|
|
16377
16693
|
scope.span.end();
|
|
16378
16694
|
} catch {
|
|
16379
16695
|
}
|
|
@@ -16388,7 +16704,7 @@ function getScope(tracer, state, msg) {
|
|
|
16388
16704
|
flushAssistantTurn(tracer, root, state);
|
|
16389
16705
|
}
|
|
16390
16706
|
const parentToolSpan = state.toolSpans.get(parentId);
|
|
16391
|
-
const parentCtx = parentToolSpan ?
|
|
16707
|
+
const parentCtx = parentToolSpan ? import_api25.trace.setSpan(getNeatlogsBaseContext(), parentToolSpan) : state.scopes.get(ROOT_SCOPE).ctx;
|
|
16392
16708
|
const subType = msg?.subagent_type ? String(msg.subagent_type) : "subagent";
|
|
16393
16709
|
const attrs = {
|
|
16394
16710
|
"neatlogs.span.kind": "AGENT",
|
|
@@ -16398,7 +16714,7 @@ function getScope(tracer, state, msg) {
|
|
|
16398
16714
|
const span2 = tracer.startSpan(`claude_agent.subagent.${subType}`, { attributes: attrs }, parentCtx);
|
|
16399
16715
|
const scope = {
|
|
16400
16716
|
span: span2,
|
|
16401
|
-
ctx:
|
|
16717
|
+
ctx: import_api25.trace.setSpan(getNeatlogsBaseContext(), span2),
|
|
16402
16718
|
inputMessages: msg?.task_description ? [{ role: "user", content: String(msg.task_description) }] : [],
|
|
16403
16719
|
assistantBuffer: null,
|
|
16404
16720
|
finalText: "",
|
|
@@ -16522,7 +16838,7 @@ function flushAssistantTurn(tracer, scope, state) {
|
|
|
16522
16838
|
if (buf.stopReason) attrs["neatlogs.llm.finish_reason"] = String(buf.stopReason);
|
|
16523
16839
|
const span2 = tracer.startSpan(`claude_agent.llm.${model || "model"}`, { attributes: attrs }, scope.ctx);
|
|
16524
16840
|
if (buf.usage) setUsage3(span2, buf.usage);
|
|
16525
|
-
span2.setStatus({ code:
|
|
16841
|
+
span2.setStatus({ code: import_api25.SpanStatusCode.OK });
|
|
16526
16842
|
span2.end();
|
|
16527
16843
|
if (outText) scope.finalText = outText;
|
|
16528
16844
|
const turnParts = [];
|
|
@@ -16557,10 +16873,10 @@ function closeToolSpansFromUser(state, scope, msg) {
|
|
|
16557
16873
|
if (!span2) continue;
|
|
16558
16874
|
span2.setAttribute("output.value", outText);
|
|
16559
16875
|
if (block.is_error) {
|
|
16560
|
-
span2.setStatus({ code:
|
|
16876
|
+
span2.setStatus({ code: import_api25.SpanStatusCode.ERROR });
|
|
16561
16877
|
span2.setAttribute("neatlogs.tool.is_error", true);
|
|
16562
16878
|
} else {
|
|
16563
|
-
span2.setStatus({ code:
|
|
16879
|
+
span2.setStatus({ code: import_api25.SpanStatusCode.OK });
|
|
16564
16880
|
}
|
|
16565
16881
|
span2.end();
|
|
16566
16882
|
state.toolSpans.delete(id);
|
|
@@ -16612,16 +16928,16 @@ function recordError8(span2, err) {
|
|
|
16612
16928
|
JSON.stringify({ status: "error", error: message })
|
|
16613
16929
|
);
|
|
16614
16930
|
if (err instanceof Error) {
|
|
16615
|
-
span2.setStatus({ code:
|
|
16931
|
+
span2.setStatus({ code: import_api25.SpanStatusCode.ERROR, message: err.message });
|
|
16616
16932
|
span2.recordException(err);
|
|
16617
16933
|
} else {
|
|
16618
|
-
span2.setStatus({ code:
|
|
16934
|
+
span2.setStatus({ code: import_api25.SpanStatusCode.ERROR, message });
|
|
16619
16935
|
}
|
|
16620
16936
|
span2.end();
|
|
16621
16937
|
}
|
|
16622
16938
|
|
|
16623
16939
|
// src/openrouter-agent.ts
|
|
16624
|
-
var
|
|
16940
|
+
var import_api26 = require("@opentelemetry/api");
|
|
16625
16941
|
var TRACER_NAME14 = "neatlogs.openrouter_agent";
|
|
16626
16942
|
var PROVIDER5 = "openrouter";
|
|
16627
16943
|
function wrapOpenRouterAgent(client) {
|
|
@@ -16713,7 +17029,7 @@ function startLlmSpan(opts) {
|
|
|
16713
17029
|
}
|
|
16714
17030
|
function instrumentModelResult(result, span2) {
|
|
16715
17031
|
if (!result || typeof result !== "object" && typeof result !== "function") {
|
|
16716
|
-
span2.setStatus({ code:
|
|
17032
|
+
span2.setStatus({ code: import_api26.SpanStatusCode.OK });
|
|
16717
17033
|
span2.end();
|
|
16718
17034
|
return result;
|
|
16719
17035
|
}
|
|
@@ -16724,7 +17040,7 @@ function instrumentModelResult(result, span2) {
|
|
|
16724
17040
|
try {
|
|
16725
17041
|
finalizeLlm(span2, resolved);
|
|
16726
17042
|
} catch {
|
|
16727
|
-
span2.setStatus({ code:
|
|
17043
|
+
span2.setStatus({ code: import_api26.SpanStatusCode.OK });
|
|
16728
17044
|
span2.end();
|
|
16729
17045
|
}
|
|
16730
17046
|
};
|
|
@@ -16827,7 +17143,7 @@ function finalizeLlm(span2, result) {
|
|
|
16827
17143
|
const finishReason = result?.finishReason ?? result?.finish_reason ?? result?.choices?.[0]?.finish_reason;
|
|
16828
17144
|
if (finishReason) span2.setAttribute("neatlogs.llm.finish_reason", String(finishReason));
|
|
16829
17145
|
setOpenResponsesUsage(span2, result);
|
|
16830
|
-
span2.setStatus({ code:
|
|
17146
|
+
span2.setStatus({ code: import_api26.SpanStatusCode.OK });
|
|
16831
17147
|
span2.end();
|
|
16832
17148
|
}
|
|
16833
17149
|
function extractOpenResponsesText(result) {
|
|
@@ -16853,10 +17169,10 @@ function safeStringify14(value) {
|
|
|
16853
17169
|
}
|
|
16854
17170
|
function recordError9(span2, err) {
|
|
16855
17171
|
if (err instanceof Error) {
|
|
16856
|
-
span2.setStatus({ code:
|
|
17172
|
+
span2.setStatus({ code: import_api26.SpanStatusCode.ERROR, message: err.message });
|
|
16857
17173
|
span2.recordException(err);
|
|
16858
17174
|
} else {
|
|
16859
|
-
span2.setStatus({ code:
|
|
17175
|
+
span2.setStatus({ code: import_api26.SpanStatusCode.ERROR, message: String(err) });
|
|
16860
17176
|
}
|
|
16861
17177
|
span2.end();
|
|
16862
17178
|
}
|
|
@@ -17912,6 +18228,7 @@ var neatlogs_telemetry_schema_default = {
|
|
|
17912
18228
|
"VECTOR_STORE",
|
|
17913
18229
|
"MEMORY",
|
|
17914
18230
|
"GUARDRAIL",
|
|
18231
|
+
"EVALUATOR",
|
|
17915
18232
|
"LOG",
|
|
17916
18233
|
"HTTP",
|
|
17917
18234
|
"UNKNOWN"
|
|
@@ -19340,6 +19657,7 @@ var neatlogs_telemetry_schema_default = {
|
|
|
19340
19657
|
"AGENT",
|
|
19341
19658
|
"CHAIN",
|
|
19342
19659
|
"TASK",
|
|
19660
|
+
"EVALUATOR",
|
|
19343
19661
|
"HTTP",
|
|
19344
19662
|
"UNKNOWN"
|
|
19345
19663
|
]
|
|
@@ -19503,6 +19821,7 @@ var neatlogs_telemetry_schema_default = {
|
|
|
19503
19821
|
"neatlogs.vector_store.*",
|
|
19504
19822
|
"neatlogs.memory.*",
|
|
19505
19823
|
"neatlogs.guardrail.*",
|
|
19824
|
+
"neatlogs.evaluator.*",
|
|
19506
19825
|
"neatlogs.mcp.*",
|
|
19507
19826
|
"neatlogs.code.*"
|
|
19508
19827
|
],
|
|
@@ -19581,7 +19900,7 @@ var neatlogs_telemetry_schema_default = {
|
|
|
19581
19900
|
// src/schema-v2.ts
|
|
19582
19901
|
var TELEMETRY_CONTRACT_VERSION = "2.0.0";
|
|
19583
19902
|
var TELEMETRY_SCHEMA_VERSION = 2;
|
|
19584
|
-
var TELEMETRY_SCHEMA_SHA256 = "
|
|
19903
|
+
var TELEMETRY_SCHEMA_SHA256 = "ae79717d127e2faa761ad83c8a51a08cae6fce00a04446d46dcc6d1a371818ce";
|
|
19585
19904
|
var TELEMETRY_SCHEMA_V2 = Object.freeze(neatlogs_telemetry_schema_default);
|
|
19586
19905
|
var TELEMETRY_CONFLICT_PRECEDENCE = Object.freeze(
|
|
19587
19906
|
[...neatlogs_telemetry_schema_default["x-neatlogs-policy"].conflict_precedence]
|