neatlogs 1.1.13 → 1.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-sdk.cjs.map +1 -1
- package/dist/ai-sdk.mjs.map +1 -1
- package/dist/anthropic.cjs.map +1 -1
- package/dist/anthropic.mjs +1 -0
- package/dist/anthropic.mjs.map +1 -1
- package/dist/azure-openai.cjs.map +1 -1
- package/dist/azure-openai.mjs +1 -0
- package/dist/azure-openai.mjs.map +1 -1
- package/dist/bedrock.cjs.map +1 -1
- package/dist/bedrock.mjs +1 -0
- package/dist/bedrock.mjs.map +1 -1
- package/dist/claude-agent-sdk.cjs.map +1 -1
- package/dist/claude-agent-sdk.mjs.map +1 -1
- package/dist/google-genai.cjs.map +1 -1
- package/dist/google-genai.mjs +1 -0
- package/dist/google-genai.mjs.map +1 -1
- package/dist/index.cjs +54 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.mjs +62 -9
- package/dist/index.mjs.map +1 -1
- package/dist/langchain.cjs.map +1 -1
- package/dist/langchain.mjs +1 -0
- package/dist/langchain.mjs.map +1 -1
- package/dist/mastra-wrap.cjs.map +1 -1
- 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.map +1 -1
- package/dist/openai.mjs +1 -0
- 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.map +1 -1
- package/dist/openrouter-agent.mjs +1 -0
- 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.map +1 -1
- package/dist/vertex-ai.mjs +1 -0
- package/dist/vertex-ai.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -388,14 +388,21 @@ declare function identify<T>(opts: IdentifyOptions, fn: () => T): T;
|
|
|
388
388
|
* callers opt in at the exact cross-process boundary where Neatlogs context
|
|
389
389
|
* should travel.
|
|
390
390
|
*/
|
|
391
|
-
type TraceContextCarrier = Record<string, string> | {
|
|
392
|
-
|
|
391
|
+
type TraceContextCarrier = Record<string, string | undefined> | {
|
|
392
|
+
get?(name: string): string | null | undefined;
|
|
393
|
+
set?(name: string, value: string): unknown;
|
|
393
394
|
};
|
|
394
395
|
/**
|
|
395
396
|
* Inject the active private Neatlogs span as W3C `traceparent`/`tracestate`
|
|
396
397
|
* headers. Returns false when no valid Neatlogs span is active.
|
|
397
398
|
*/
|
|
398
399
|
declare function injectTraceContext(carrier: TraceContextCarrier): boolean;
|
|
400
|
+
/**
|
|
401
|
+
* Run a callback under a remote W3C parent in Neatlogs' private context.
|
|
402
|
+
* Invalid or absent context is ignored, so request handling remains fail-open.
|
|
403
|
+
* The process-global OpenTelemetry context and propagator are never touched.
|
|
404
|
+
*/
|
|
405
|
+
declare function extractTraceContext<T>(carrier: TraceContextCarrier, fn: () => T): T;
|
|
399
406
|
|
|
400
407
|
interface ContextSetter {
|
|
401
408
|
set(template: string, variables: Record<string, any>): void;
|
|
@@ -656,6 +663,6 @@ declare function registerCrewaiTask(task: {
|
|
|
656
663
|
* SDK version. Kept in sync with package.json by the `version:sync` script
|
|
657
664
|
* (runs automatically on `prebuild`). Do not edit by hand — bump package.json.
|
|
658
665
|
*/
|
|
659
|
-
declare const __version__ = "1.1.
|
|
666
|
+
declare const __version__ = "1.1.15";
|
|
660
667
|
|
|
661
|
-
export { type CachedPrompt, type InitOptions, type MaskFunction, PromptApiError, PromptClient, PromptClientError, PromptHandle, type PromptMessage, PromptNotFoundError, PromptTemplate, Span, type SpanKind, type SpanOptions, type TraceContextCarrier, type TraceOptions, UserPromptTemplate, __version__, bindTemplates, createPrompt, deletePrompt, fetchPrompt, flush, getMastraObservability, getPrompt, getSessionConfig, identify, init, injectTraceContext, isDebugEnabled, listPrompts, log, registerCrewaiTask, removeTag, saveAsVersion, setTraceOutput, shutdown, span, trace, updatePrompt };
|
|
668
|
+
export { type CachedPrompt, type InitOptions, type MaskFunction, PromptApiError, PromptClient, PromptClientError, PromptHandle, type PromptMessage, PromptNotFoundError, PromptTemplate, Span, type SpanKind, type SpanOptions, type TraceContextCarrier, type TraceOptions, UserPromptTemplate, __version__, bindTemplates, createPrompt, deletePrompt, extractTraceContext, fetchPrompt, flush, getMastraObservability, getPrompt, getSessionConfig, identify, init, injectTraceContext, isDebugEnabled, listPrompts, log, registerCrewaiTask, removeTag, saveAsVersion, setTraceOutput, shutdown, span, trace, updatePrompt };
|
package/dist/index.mjs
CHANGED
|
@@ -2263,6 +2263,9 @@ function withNeatlogsSpan(span2, fn, baseContext) {
|
|
|
2263
2263
|
}
|
|
2264
2264
|
return privateContextStorage.run(ctx, fn);
|
|
2265
2265
|
}
|
|
2266
|
+
function withNeatlogsRemoteParent(span2, fn) {
|
|
2267
|
+
return privateContextStorage.run(otelTrace.setSpan(ROOT_CONTEXT, span2), fn);
|
|
2268
|
+
}
|
|
2266
2269
|
|
|
2267
2270
|
// src/core/end-user.ts
|
|
2268
2271
|
var logger5 = getLogger();
|
|
@@ -2454,6 +2457,7 @@ var UserPromptTemplate = class extends BasePromptTemplate {
|
|
|
2454
2457
|
|
|
2455
2458
|
// src/core/context.ts
|
|
2456
2459
|
import {
|
|
2460
|
+
trace as otelTrace2,
|
|
2457
2461
|
createContextKey as createContextKey2,
|
|
2458
2462
|
ROOT_CONTEXT as ROOT_CONTEXT3,
|
|
2459
2463
|
SpanStatusCode as SpanStatusCode2
|
|
@@ -2638,7 +2642,9 @@ var KNOWN_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
|
2638
2642
|
"endUserMetadata"
|
|
2639
2643
|
]);
|
|
2640
2644
|
function _setSpanAttributes(span2, kind, attributes) {
|
|
2641
|
-
|
|
2645
|
+
if (kind?.toUpperCase() === "LLM") {
|
|
2646
|
+
span2.setAttribute("neatlogs.internal", true);
|
|
2647
|
+
}
|
|
2642
2648
|
span2.setAttribute("openinference.span.kind", kind ?? "CHAIN");
|
|
2643
2649
|
for (const [key, value] of Object.entries(attributes)) {
|
|
2644
2650
|
span2.setAttribute(key, value);
|
|
@@ -2698,8 +2704,12 @@ async function trace(options, fn) {
|
|
|
2698
2704
|
} = options;
|
|
2699
2705
|
const sessionId = sessionIdOption ?? currentSessionId();
|
|
2700
2706
|
const currentSpan = getActiveNeatlogsSpan();
|
|
2701
|
-
const
|
|
2702
|
-
const
|
|
2707
|
+
const rootSpan = getNeatlogsRootSpan();
|
|
2708
|
+
const currentSpanIsRecording = currentSpan?.isRecording() === true;
|
|
2709
|
+
const rootSpanIsRecording = rootSpan?.isRecording() === true;
|
|
2710
|
+
const shouldFallbackToRoot = !currentSpanIsRecording && rootSpanIsRecording;
|
|
2711
|
+
const hasInheritedTraceContext = currentSpan !== void 0 || rootSpan !== void 0;
|
|
2712
|
+
const shouldCreateRootTrace = !!sessionId && !hasInheritedTraceContext && !rootSpanIsRecording;
|
|
2703
2713
|
let templateString;
|
|
2704
2714
|
let isPromptTemplateObj = false;
|
|
2705
2715
|
if (promptTemplate !== void 0) {
|
|
@@ -2735,6 +2745,9 @@ async function trace(options, fn) {
|
|
|
2735
2745
|
}
|
|
2736
2746
|
}
|
|
2737
2747
|
let ctx = getNeatlogsActiveContext();
|
|
2748
|
+
if (shouldFallbackToRoot) {
|
|
2749
|
+
ctx = otelTrace2.setSpan(ctx, rootSpan);
|
|
2750
|
+
}
|
|
2738
2751
|
const variablesJson = promptVariables ? JSON.stringify(promptVariables) : void 0;
|
|
2739
2752
|
const userVariablesJson = userPromptVariables ? JSON.stringify(userPromptVariables) : void 0;
|
|
2740
2753
|
if (variablesJson) {
|
|
@@ -2763,7 +2776,7 @@ async function trace(options, fn) {
|
|
|
2763
2776
|
extraAttributes[key] = value;
|
|
2764
2777
|
}
|
|
2765
2778
|
}
|
|
2766
|
-
const isRootTrace = shouldCreateRootTrace || !
|
|
2779
|
+
const isRootTrace = shouldCreateRootTrace || !hasInheritedTraceContext;
|
|
2767
2780
|
const tracer = getNeatlogsTracer("neatlogs.trace");
|
|
2768
2781
|
const spanCallback = async (span3) => {
|
|
2769
2782
|
_setSpanAttributes(span3, kind, extraAttributes);
|
|
@@ -5946,7 +5959,7 @@ function _resetMastraCache() {
|
|
|
5946
5959
|
}
|
|
5947
5960
|
|
|
5948
5961
|
// src/version.ts
|
|
5949
|
-
var __version__ = "1.1.
|
|
5962
|
+
var __version__ = "1.1.15";
|
|
5950
5963
|
|
|
5951
5964
|
// src/init.ts
|
|
5952
5965
|
var logger13 = getLogger();
|
|
@@ -6363,7 +6376,11 @@ function Span(options) {
|
|
|
6363
6376
|
}
|
|
6364
6377
|
|
|
6365
6378
|
// src/core/propagation.ts
|
|
6366
|
-
import {
|
|
6379
|
+
import {
|
|
6380
|
+
TraceFlags as TraceFlags2,
|
|
6381
|
+
createTraceState,
|
|
6382
|
+
trace as otelTrace4
|
|
6383
|
+
} from "@opentelemetry/api";
|
|
6367
6384
|
function injectTraceContext(carrier) {
|
|
6368
6385
|
const spanContext = getActiveNeatlogsSpan()?.spanContext();
|
|
6369
6386
|
if (!spanContext?.traceId || !spanContext.spanId) {
|
|
@@ -6384,6 +6401,41 @@ function injectTraceContext(carrier) {
|
|
|
6384
6401
|
}
|
|
6385
6402
|
return true;
|
|
6386
6403
|
}
|
|
6404
|
+
function extractTraceContext(carrier, fn) {
|
|
6405
|
+
const spanContext = parseTraceParent(
|
|
6406
|
+
getHeader(carrier, "traceparent"),
|
|
6407
|
+
getHeader(carrier, "tracestate")
|
|
6408
|
+
);
|
|
6409
|
+
if (!spanContext) {
|
|
6410
|
+
return fn();
|
|
6411
|
+
}
|
|
6412
|
+
return withNeatlogsRemoteParent(otelTrace4.wrapSpanContext(spanContext), fn);
|
|
6413
|
+
}
|
|
6414
|
+
function parseTraceParent(traceparent, tracestate) {
|
|
6415
|
+
const match = traceparent?.trim().match(
|
|
6416
|
+
/^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/
|
|
6417
|
+
);
|
|
6418
|
+
if (!match || match[1] === "00000000000000000000000000000000" || match[2] === "0000000000000000") {
|
|
6419
|
+
return void 0;
|
|
6420
|
+
}
|
|
6421
|
+
const flags = Number.parseInt(match[3], 16);
|
|
6422
|
+
return {
|
|
6423
|
+
traceId: match[1],
|
|
6424
|
+
spanId: match[2],
|
|
6425
|
+
traceFlags: flags & TraceFlags2.SAMPLED ? TraceFlags2.SAMPLED : TraceFlags2.NONE,
|
|
6426
|
+
isRemote: true,
|
|
6427
|
+
...tracestate?.trim() ? { traceState: createTraceState(tracestate.trim()) } : {}
|
|
6428
|
+
};
|
|
6429
|
+
}
|
|
6430
|
+
function getHeader(carrier, name) {
|
|
6431
|
+
const getter = carrier.get;
|
|
6432
|
+
if (typeof getter === "function") {
|
|
6433
|
+
const value = getter.call(carrier, name);
|
|
6434
|
+
return typeof value === "string" ? value : void 0;
|
|
6435
|
+
}
|
|
6436
|
+
const record = carrier;
|
|
6437
|
+
return record[name] ?? record[name.toLowerCase()] ?? record[name.toUpperCase()];
|
|
6438
|
+
}
|
|
6387
6439
|
function setHeader(carrier, name, value) {
|
|
6388
6440
|
if ("set" in carrier && typeof carrier.set === "function") {
|
|
6389
6441
|
carrier.set(name, value);
|
|
@@ -6617,7 +6669,7 @@ import { SpanStatusCode as SpanStatusCode5 } from "@opentelemetry/api";
|
|
|
6617
6669
|
|
|
6618
6670
|
// src/core/auto-root.ts
|
|
6619
6671
|
import {
|
|
6620
|
-
trace as
|
|
6672
|
+
trace as otelTrace5
|
|
6621
6673
|
} from "@opentelemetry/api";
|
|
6622
6674
|
var ROOT_KINDS = /* @__PURE__ */ new Set(["workflow", "chain", "agent", "mcp_tool"]);
|
|
6623
6675
|
function autoRootEnabled() {
|
|
@@ -6671,7 +6723,7 @@ function maybeOpenAutoRoot(tracer, kind, baseCtx) {
|
|
|
6671
6723
|
baseCtx
|
|
6672
6724
|
);
|
|
6673
6725
|
stampAutoRootIdentity(root);
|
|
6674
|
-
return { root, ctx:
|
|
6726
|
+
return { root, ctx: otelTrace5.setSpan(baseCtx, root) };
|
|
6675
6727
|
}
|
|
6676
6728
|
function endAutoRoot(root) {
|
|
6677
6729
|
if (!root) return;
|
|
@@ -6701,7 +6753,7 @@ var AutoRootTracer = class {
|
|
|
6701
6753
|
ctx
|
|
6702
6754
|
);
|
|
6703
6755
|
stampAutoRootIdentity(root);
|
|
6704
|
-
const childCtx =
|
|
6756
|
+
const childCtx = otelTrace5.setSpan(ctx, root);
|
|
6705
6757
|
const child = this._tracer.startSpan(name, options, childCtx);
|
|
6706
6758
|
return wrapSpanWithRoot(child, root);
|
|
6707
6759
|
}
|
|
@@ -12311,6 +12363,7 @@ export {
|
|
|
12311
12363
|
createAITelemetry,
|
|
12312
12364
|
createPrompt,
|
|
12313
12365
|
deletePrompt,
|
|
12366
|
+
extractTraceContext,
|
|
12314
12367
|
fetchPrompt,
|
|
12315
12368
|
flush,
|
|
12316
12369
|
getMastraObservability,
|