@juspay/neurolink 13.15.2 → 13.16.0
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/CHANGELOG.md +3 -3
- package/dist/browser/neurolink.min.js +413 -413
- package/dist/cli/parser.js +36 -1
- package/dist/constants/langfuse.d.ts +2 -0
- package/dist/constants/langfuse.js +2 -0
- package/dist/constants/telemetry.d.ts +2 -0
- package/dist/constants/telemetry.js +2 -0
- package/dist/hitl/hitlManager.js +6 -1
- package/dist/neurolink.js +1 -0
- package/dist/observability/exporterSpanProcessor.d.ts +1 -1
- package/dist/observability/exporterSpanProcessor.js +8 -3
- package/dist/observability/langfuseMasking.d.ts +1 -1
- package/dist/observability/langfuseMasking.js +5 -3
- package/dist/services/server/ai/observability/instrumentation.d.ts +1 -1
- package/dist/services/server/ai/observability/instrumentation.js +8 -3
- package/dist/types/observability.d.ts +2 -0
- package/docs-site/static/search-index.json +4 -3
- package/package.json +2 -1
package/dist/cli/parser.js
CHANGED
|
@@ -12,6 +12,7 @@ import { hideBin } from "yargs/helpers";
|
|
|
12
12
|
import packageJson from "../../package.json" with { type: "json" };
|
|
13
13
|
import { globalSession } from "../session/globalSessionState.js";
|
|
14
14
|
import { logger } from "../utils/logger.js";
|
|
15
|
+
import { suggestClosest } from "../utils/stringDistance.js";
|
|
15
16
|
import { handleError } from "./errorHandler.js";
|
|
16
17
|
import { CLICommandFactory } from "./factories/commandFactory.js";
|
|
17
18
|
import { SetupCommandFactory } from "./factories/setupCommandFactory.js";
|
|
@@ -38,6 +39,40 @@ import { voiceServerCommand } from "./commands/voiceServer.js";
|
|
|
38
39
|
import { DocsCommandFactory } from "./commands/docs.js";
|
|
39
40
|
import { UsageCommandFactory } from "./commands/usage.js";
|
|
40
41
|
import { VoicesCommandFactory } from "./commands/voices.js";
|
|
42
|
+
// yargs passes `.fail()` its usage object, whose getDescriptions() lists the failing command's visible options
|
|
43
|
+
const hasOptionDescriptions = (value) => typeof value.getDescriptions ===
|
|
44
|
+
"function";
|
|
45
|
+
function suggestKnownFlags(msg, usage) {
|
|
46
|
+
const unknown = /Unknown arguments?: (.+)/.exec(msg)?.[1].split(", ");
|
|
47
|
+
if (!unknown || !hasOptionDescriptions(usage)) {
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
const described = usage.getDescriptions();
|
|
51
|
+
if (!described || typeof described !== "object") {
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
const flags = new Map(Object.keys(described).map((key) => [
|
|
55
|
+
key.replace(/-/g, "").toLowerCase(),
|
|
56
|
+
key,
|
|
57
|
+
]));
|
|
58
|
+
// yargs also reports the camelCase twin of an unknown kebab-case flag
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
return unknown
|
|
61
|
+
.map((arg) => {
|
|
62
|
+
const typed = arg.replace(/-/g, "").toLowerCase();
|
|
63
|
+
if (seen.has(typed)) {
|
|
64
|
+
return "";
|
|
65
|
+
}
|
|
66
|
+
seen.add(typed);
|
|
67
|
+
const [closest] = suggestClosest(typed, [...flags.keys()], {
|
|
68
|
+
limit: 1,
|
|
69
|
+
maxDistance: Math.min(3, Math.ceil(typed.length / 3)),
|
|
70
|
+
});
|
|
71
|
+
const flag = closest ? flags.get(closest) : undefined;
|
|
72
|
+
return flag ? `Did you mean --${flag} instead of --${arg}?\n` : "";
|
|
73
|
+
})
|
|
74
|
+
.join("");
|
|
75
|
+
}
|
|
41
76
|
// Enhanced CLI with Professional UX
|
|
42
77
|
export function initializeCliParser() {
|
|
43
78
|
return (yargs(hideBin(process.argv))
|
|
@@ -150,7 +185,7 @@ export function initializeCliParser() {
|
|
|
150
185
|
}
|
|
151
186
|
else if (msg.includes("Unknown argument") ||
|
|
152
187
|
msg.includes("Invalid values")) {
|
|
153
|
-
processedMsg = `Error: ${msg}\
|
|
188
|
+
processedMsg = `Error: ${msg}\n${suggestKnownFlags(msg, yargsInstance)}Use --help to see available options.\n`;
|
|
154
189
|
}
|
|
155
190
|
process.stderr.write(chalk.red(processedMsg));
|
|
156
191
|
}
|
|
@@ -39,6 +39,8 @@ export declare const MAX_BYTES_PER_REQUEST = 3500000;
|
|
|
39
39
|
export declare const FULLY_MASKED = "<fully masked>";
|
|
40
40
|
/** @description Span attributes holding trace and observation input or output, which the Langfuse exporter's mask and `redactIO` apply to. */
|
|
41
41
|
export declare const CONTENT_KEYS: Set<string>;
|
|
42
|
+
/** @description Span attribute marking a span started inside a `setLangfuseContext({ redactIO: true })` scope; the Langfuse exporter leaves its input and output out and does not send the marker. */
|
|
43
|
+
export declare const REDACT_IO_ATTRIBUTE = "neurolink.langfuse.redact_io";
|
|
42
44
|
/** @description Attribute prefixes whose values are metadata entries. */
|
|
43
45
|
export declare const METADATA_PREFIXES: string[];
|
|
44
46
|
/** @description Observation types that hold no model, usage or cost in Langfuse. GenAI model and usage keys on them are left out of the Langfuse export, so a request's generation stays its only priced record. */
|
|
@@ -48,6 +48,8 @@ export const CONTENT_KEYS = new Set([
|
|
|
48
48
|
"langfuse.trace.input",
|
|
49
49
|
"langfuse.trace.output",
|
|
50
50
|
]);
|
|
51
|
+
/** @description Span attribute marking a span started inside a `setLangfuseContext({ redactIO: true })` scope; the Langfuse exporter leaves its input and output out and does not send the marker. */
|
|
52
|
+
export const REDACT_IO_ATTRIBUTE = "neurolink.langfuse.redact_io";
|
|
51
53
|
/** @description Attribute prefixes whose values are metadata entries. */
|
|
52
54
|
export const METADATA_PREFIXES = [
|
|
53
55
|
"langfuse.observation.metadata.",
|
|
@@ -16,6 +16,8 @@ export declare const TRUNCATION_NOTE_ALLOWANCE_CHARS = 48;
|
|
|
16
16
|
export declare const TRACE_METADATA_CONTEXT_KEY = "neurolink.trace.metadata";
|
|
17
17
|
/** @description Name of the OpenTelemetry context key that carries the trace tag of the prompt `setLangfuseContext` was last given. */
|
|
18
18
|
export declare const PROMPT_TAG_CONTEXT_KEY = "neurolink.trace.promptTag";
|
|
19
|
+
/** @description Name of the OpenTelemetry context key set when an enclosing `setLangfuseContext` asked for `redactIO`. */
|
|
20
|
+
export declare const REDACT_IO_CONTEXT_KEY = "neurolink.trace.redactIO";
|
|
19
21
|
/** @description Log prefix for NeuroLink's OpenTelemetry setup. */
|
|
20
22
|
export declare const OTEL_LOG_PREFIX = "[OpenTelemetry]";
|
|
21
23
|
/** @description Most open and most ended spans the exporter span processor remembers for re-parenting; the oldest are forgotten first. */
|
|
@@ -30,6 +30,8 @@ export const TRUNCATION_NOTE_ALLOWANCE_CHARS = 48;
|
|
|
30
30
|
export const TRACE_METADATA_CONTEXT_KEY = "neurolink.trace.metadata";
|
|
31
31
|
/** @description Name of the OpenTelemetry context key that carries the trace tag of the prompt `setLangfuseContext` was last given. */
|
|
32
32
|
export const PROMPT_TAG_CONTEXT_KEY = "neurolink.trace.promptTag";
|
|
33
|
+
/** @description Name of the OpenTelemetry context key set when an enclosing `setLangfuseContext` asked for `redactIO`. */
|
|
34
|
+
export const REDACT_IO_CONTEXT_KEY = "neurolink.trace.redactIO";
|
|
33
35
|
/** @description Log prefix for NeuroLink's OpenTelemetry setup. */
|
|
34
36
|
export const OTEL_LOG_PREFIX = "[OpenTelemetry]";
|
|
35
37
|
/** @description Most open and most ended spans the exporter span processor remembers for re-parenting; the oldest are forgotten first. */
|
package/dist/hitl/hitlManager.js
CHANGED
|
@@ -9,6 +9,7 @@ import { EventEmitter } from "events";
|
|
|
9
9
|
import { randomUUID } from "crypto";
|
|
10
10
|
import { HITLCancelledError, HITLTimeoutError, HITLConfigurationError, } from "./hitlErrors.js";
|
|
11
11
|
import { logger } from "../utils/logger.js";
|
|
12
|
+
import { suggestClosest } from "../utils/stringDistance.js";
|
|
12
13
|
// Default configuration constants
|
|
13
14
|
const DEFAULT_TIMEOUT = 30000; // 30 seconds
|
|
14
15
|
// Shared with NeuroLink's HITL init logs so they report the policy applied here
|
|
@@ -77,7 +78,11 @@ export class HITLManager extends EventEmitter {
|
|
|
77
78
|
for (const key of Object.keys(config)) {
|
|
78
79
|
if (!KNOWN_CONFIG_KEYS.has(key) && !this.warnedUnknownKeys.has(key)) {
|
|
79
80
|
this.warnedUnknownKeys.add(key);
|
|
80
|
-
|
|
81
|
+
const [closest] = suggestClosest(key, [...KNOWN_CONFIG_KEYS], {
|
|
82
|
+
limit: 1,
|
|
83
|
+
});
|
|
84
|
+
const didYouMean = closest ? ` Did you mean "${closest}"?` : "";
|
|
85
|
+
logger.alwaysStderr(`[HITL] Unknown config key "${key}" is ignored and has no effect.${didYouMean} Supported keys: ${[...KNOWN_CONFIG_KEYS].join(", ")}. See docs/features/enterprise-hitl.md`);
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
// Apply defaults for optional fields
|
package/dist/neurolink.js
CHANGED
|
@@ -19,7 +19,7 @@ export declare class ExporterSpanProcessor implements OtelSpanProcessor {
|
|
|
19
19
|
*/
|
|
20
20
|
constructor(registry: ExporterRegistry, shutsDownExporters?: boolean);
|
|
21
21
|
/**
|
|
22
|
-
* @description Copies the propagated Langfuse trace attributes (user, session, trace name, tags, metadata) from the parent context onto the new span and remembers it until it ends.
|
|
22
|
+
* @description Copies the propagated Langfuse trace attributes (user, session, trace name, tags, metadata) from the parent context onto the new span, marks it for input and output redaction when a `setLangfuseContext` scope asked for `redactIO`, and remembers it until it ends.
|
|
23
23
|
* @param span {Span} - Span that just started.
|
|
24
24
|
* @param parentContext {Context} - Context the span was started in.
|
|
25
25
|
* @returns {void} Nothing.
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { getPropagatedAttributesFromContext } from "@langfuse/core";
|
|
2
|
-
import { SpanStatusCode } from "@opentelemetry/api";
|
|
3
|
-
import {
|
|
2
|
+
import { createContextKey, SpanStatusCode, } from "@opentelemetry/api";
|
|
3
|
+
import { REDACT_IO_ATTRIBUTE } from "../constants/langfuse.js";
|
|
4
|
+
import { INTERNAL_SPAN_ATTRIBUTE, MAX_REMEMBERED_SPANS, PROXY_TRACER_SCOPE, REDACT_IO_CONTEXT_KEY, } from "../constants/telemetry.js";
|
|
4
5
|
import { SpanStatus, SpanType } from "../types/index.js";
|
|
5
6
|
import { logger } from "../utils/logger.js";
|
|
6
7
|
import { getExporterRegistry } from "./exporterRegistry.js";
|
|
7
8
|
const LANGFUSE_OBSERVATION_TYPE = "langfuse.observation.type";
|
|
8
9
|
const GEN_AI_OBSERVATION_TYPE = "gen_ai.observation.type";
|
|
9
10
|
const GEN_AI_OPERATION = "gen_ai.operation.name";
|
|
11
|
+
const REDACT_IO_KEY = createContextKey(REDACT_IO_CONTEXT_KEY);
|
|
10
12
|
const OBSERVATION_SPAN_TYPES = {
|
|
11
13
|
agent: SpanType.AGENT_RUN,
|
|
12
14
|
tool: SpanType.TOOL_CALL,
|
|
@@ -128,13 +130,16 @@ export class ExporterSpanProcessor {
|
|
|
128
130
|
this.shutsDownExporters = shutsDownExporters;
|
|
129
131
|
}
|
|
130
132
|
/**
|
|
131
|
-
* @description Copies the propagated Langfuse trace attributes (user, session, trace name, tags, metadata) from the parent context onto the new span and remembers it until it ends.
|
|
133
|
+
* @description Copies the propagated Langfuse trace attributes (user, session, trace name, tags, metadata) from the parent context onto the new span, marks it for input and output redaction when a `setLangfuseContext` scope asked for `redactIO`, and remembers it until it ends.
|
|
132
134
|
* @param span {Span} - Span that just started.
|
|
133
135
|
* @param parentContext {Context} - Context the span was started in.
|
|
134
136
|
* @returns {void} Nothing.
|
|
135
137
|
*/
|
|
136
138
|
onStart(span, parentContext) {
|
|
137
139
|
try {
|
|
140
|
+
if (parentContext.getValue(REDACT_IO_KEY) === true) {
|
|
141
|
+
span.setAttribute(REDACT_IO_ATTRIBUTE, true);
|
|
142
|
+
}
|
|
138
143
|
span.setAttributes(getPropagatedAttributesFromContext(parentContext));
|
|
139
144
|
this.open.set(span.spanContext().spanId, span);
|
|
140
145
|
this.hold(parentIdOf(span));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LangfuseAttributePolicy, SpanAttributes } from "../types/index.js";
|
|
2
2
|
/**
|
|
3
|
-
* @description Applies the Langfuse exporter's policy to a span's attributes as they are sent to Langfuse: fills environment and release when the span has none, removes input and output when `redactIO` is set,
|
|
3
|
+
* @description Applies the Langfuse exporter's policy to a span's attributes as they are sent to Langfuse: fills environment and release when the span has none, removes input and output when `redactIO` is set or the span was started in a `setLangfuseContext({ redactIO: true })` scope, masks input, output and metadata when a mask is configured, and drops the `neurolink.langfuse.redact_io` marker. Nothing else is touched: other attributes, events and the status message go to Langfuse as they are, and no other exporter sees the policy.
|
|
4
4
|
* @param attributes {SpanAttributes} - Attributes of the span being exported.
|
|
5
5
|
* @param policy {LangfuseAttributePolicy} - Environment, release, redaction and mask settings.
|
|
6
6
|
* @returns {SpanAttributes} A new attribute record; the input is not modified.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CONTENT_KEYS, FULLY_MASKED, METADATA_PREFIXES, } from "../constants/langfuse.js";
|
|
1
|
+
import { CONTENT_KEYS, FULLY_MASKED, METADATA_PREFIXES, REDACT_IO_ATTRIBUTE, } from "../constants/langfuse.js";
|
|
2
2
|
function parseContent(value) {
|
|
3
3
|
const text = typeof value === "string" ? value : JSON.stringify(value);
|
|
4
4
|
try {
|
|
@@ -18,7 +18,7 @@ function maskValue(value, mask) {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* @description Applies the Langfuse exporter's policy to a span's attributes as they are sent to Langfuse: fills environment and release when the span has none, removes input and output when `redactIO` is set,
|
|
21
|
+
* @description Applies the Langfuse exporter's policy to a span's attributes as they are sent to Langfuse: fills environment and release when the span has none, removes input and output when `redactIO` is set or the span was started in a `setLangfuseContext({ redactIO: true })` scope, masks input, output and metadata when a mask is configured, and drops the `neurolink.langfuse.redact_io` marker. Nothing else is touched: other attributes, events and the status message go to Langfuse as they are, and no other exporter sees the policy.
|
|
22
22
|
* @param attributes {SpanAttributes} - Attributes of the span being exported.
|
|
23
23
|
* @param policy {LangfuseAttributePolicy} - Environment, release, redaction and mask settings.
|
|
24
24
|
* @returns {SpanAttributes} A new attribute record; the input is not modified.
|
|
@@ -29,9 +29,11 @@ export function protectAttributes(attributes, policy) {
|
|
|
29
29
|
...(policy.release && { "langfuse.release": policy.release }),
|
|
30
30
|
...attributes,
|
|
31
31
|
};
|
|
32
|
+
const redactIO = policy.redactIO || attributes[REDACT_IO_ATTRIBUTE] === true;
|
|
33
|
+
delete result[REDACT_IO_ATTRIBUTE];
|
|
32
34
|
for (const key of Object.keys(result)) {
|
|
33
35
|
if (CONTENT_KEYS.has(key)) {
|
|
34
|
-
if (
|
|
36
|
+
if (redactIO) {
|
|
35
37
|
delete result[key];
|
|
36
38
|
}
|
|
37
39
|
else if (policy.mask) {
|
|
@@ -53,7 +53,7 @@ export declare function getLangfuseHealthStatus(): {
|
|
|
53
53
|
*/
|
|
54
54
|
export declare function traceMetadataFromContext(ctx: Context): Record<string, SpanContent>;
|
|
55
55
|
/**
|
|
56
|
-
* @description Runs `fn` with trace attributes propagated to every span it creates. `conversationId` and `requestId` become metadata; empty values are dropped. `prompt` adds the trace tag `prompt:<name>@<version>` (`@fallback` for a fallback, no suffix without a version) and `promptName`, `promptVersion` and `promptLabel` metadata, and links generations to the prompt version unless it is a fallback; it replaces an enclosing prompt's tag, metadata and link. Metadata values of up to 200 characters once stringified are on every observation; longer values and arrays are recorded in full on the trace only, written by the trace root.
|
|
56
|
+
* @description Runs `fn` with trace attributes propagated to every span it creates. `conversationId` and `requestId` become metadata; empty values are dropped. `prompt` adds the trace tag `prompt:<name>@<version>` (`@fallback` for a fallback, no suffix without a version) and `promptName`, `promptVersion` and `promptLabel` metadata, and links generations to the prompt version unless it is a fallback; it replaces an enclosing prompt's tag, metadata and link. `redactIO: true` leaves input and output out of the Langfuse export for every observation started inside, nested scopes included; `false` cannot undo it. Metadata values of up to 200 characters once stringified are on every observation; longer values and arrays are recorded in full on the trace only, written by the trace root.
|
|
57
57
|
* @param params {NeurolinkTraceContext} - User, session, trace name, tags, metadata and prompt for the trace.
|
|
58
58
|
* @param fn {() => T} - Work to run inside the propagated context.
|
|
59
59
|
* @returns {T} Whatever `fn` returns.
|
|
@@ -6,7 +6,7 @@ import { resourceFromAttributes, } from "@opentelemetry/resources";
|
|
|
6
6
|
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
7
7
|
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION, } from "@opentelemetry/semantic-conventions";
|
|
8
8
|
import { DEFAULT_BASE_URL, DEFAULT_FLUSH_BUDGET_MS, DEFAULT_PROMPT_CACHE_TTL_MS, DEFAULT_PROMPT_TIMEOUT_MS, MAX_CACHED_PROMPTS, PROMPT_METADATA_KEYS, } from "../../../../constants/langfuse.js";
|
|
9
|
-
import { OTEL_LOG_PREFIX, PROMPT_TAG_CONTEXT_KEY, TRACE_METADATA_CONTEXT_KEY, } from "../../../../constants/telemetry.js";
|
|
9
|
+
import { OTEL_LOG_PREFIX, PROMPT_TAG_CONTEXT_KEY, REDACT_IO_CONTEXT_KEY, TRACE_METADATA_CONTEXT_KEY, } from "../../../../constants/telemetry.js";
|
|
10
10
|
import { getExporterRegistry } from "../../../../observability/exporterRegistry.js";
|
|
11
11
|
import { ExporterSpanProcessor } from "../../../../observability/exporterSpanProcessor.js";
|
|
12
12
|
import { LangfuseExporter } from "../../../../observability/exporters/langfuseExporter.js";
|
|
@@ -19,6 +19,7 @@ const MAX_PROPAGATED_CHARS = 200;
|
|
|
19
19
|
const LANGFUSE_EXPORTER_NAME = "langfuse";
|
|
20
20
|
const TRACE_METADATA_KEY = createContextKey(TRACE_METADATA_CONTEXT_KEY);
|
|
21
21
|
const PROMPT_TAG_KEY = createContextKey(PROMPT_TAG_CONTEXT_KEY);
|
|
22
|
+
const REDACT_IO_KEY = createContextKey(REDACT_IO_CONTEXT_KEY);
|
|
22
23
|
const CONTEXT_PROBE_KEY = createContextKey("neurolink.context-manager-probe");
|
|
23
24
|
// `false`, `0`, `off` or `no` skips the flush at process exit; the released build had none.
|
|
24
25
|
const EXIT_FLUSH_SWITCH = "NEUROLINK_TELEMETRY_EXIT_FLUSH";
|
|
@@ -448,7 +449,7 @@ const promptTagOf = ({ name, version, isFallback, }) => {
|
|
|
448
449
|
: `prompt:${name}`;
|
|
449
450
|
};
|
|
450
451
|
/**
|
|
451
|
-
* @description Runs `fn` with trace attributes propagated to every span it creates. `conversationId` and `requestId` become metadata; empty values are dropped. `prompt` adds the trace tag `prompt:<name>@<version>` (`@fallback` for a fallback, no suffix without a version) and `promptName`, `promptVersion` and `promptLabel` metadata, and links generations to the prompt version unless it is a fallback; it replaces an enclosing prompt's tag, metadata and link. Metadata values of up to 200 characters once stringified are on every observation; longer values and arrays are recorded in full on the trace only, written by the trace root.
|
|
452
|
+
* @description Runs `fn` with trace attributes propagated to every span it creates. `conversationId` and `requestId` become metadata; empty values are dropped. `prompt` adds the trace tag `prompt:<name>@<version>` (`@fallback` for a fallback, no suffix without a version) and `promptName`, `promptVersion` and `promptLabel` metadata, and links generations to the prompt version unless it is a fallback; it replaces an enclosing prompt's tag, metadata and link. `redactIO: true` leaves input and output out of the Langfuse export for every observation started inside, nested scopes included; `false` cannot undo it. Metadata values of up to 200 characters once stringified are on every observation; longer values and arrays are recorded in full on the trace only, written by the trace root.
|
|
452
453
|
* @param params {NeurolinkTraceContext} - User, session, trace name, tags, metadata and prompt for the trace.
|
|
453
454
|
* @param fn {() => T} - Work to run inside the propagated context.
|
|
454
455
|
* @returns {T} Whatever `fn` returns.
|
|
@@ -487,7 +488,11 @@ export function setLangfuseContext(params, fn) {
|
|
|
487
488
|
...traceMetadataFromContext(scoped),
|
|
488
489
|
...full,
|
|
489
490
|
});
|
|
490
|
-
|
|
491
|
+
// Only `true` is stored, so an inner `redactIO: false` never clears an outer scope's redaction
|
|
492
|
+
const scope = params.redactIO
|
|
493
|
+
? withMetadata.setValue(REDACT_IO_KEY, true)
|
|
494
|
+
: withMetadata;
|
|
495
|
+
return context.with(scope, () => propagateAttributes({
|
|
491
496
|
userId: params.userId || undefined,
|
|
492
497
|
sessionId: params.sessionId || undefined,
|
|
493
498
|
traceName: params.traceName || undefined,
|
|
@@ -112,6 +112,8 @@ export type NeurolinkTraceContext = {
|
|
|
112
112
|
observationName?: string | null;
|
|
113
113
|
/** Langfuse prompt the call ran with, such as a `getLangfusePrompt` result; recorded as a `prompt:` trace tag and `promptName`, `promptVersion` and `promptLabel` metadata, replacing an enclosing prompt's tag and metadata. */
|
|
114
114
|
prompt?: LangfusePromptRef;
|
|
115
|
+
/** `true` leaves input and output out of what is sent to Langfuse for every observation started in this scope, nested scopes included, as the exporter's `redactIO` does for all traces. `false` cannot undo an enclosing scope's or the exporter's `redactIO`. */
|
|
116
|
+
redactIO?: boolean;
|
|
115
117
|
};
|
|
116
118
|
/**
|
|
117
119
|
* @description A Langfuse prompt version a trace was produced with. Generations are linked to it when it has a `version` and is not a fallback.
|
|
@@ -3519,13 +3519,14 @@
|
|
|
3519
3519
|
{"objectID":"c3139194cb90b179cd9656356b659b38ab57c2b36ff72a0ae85ba1d83fb78aee","title":"Setup","url":"/docs/features/observability#setup","content":"Setup","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Setup","lvl3":""}},
|
|
3520
3520
|
{"objectID":"f5b277d3ae78e90affc7f614bbe8f4ea0e076874c57d77d204bd0764d0952622","title":"Environment variables","url":"/docs/features/observability#environment-variables","content":"| Variable | Purpose |\n| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| LANGFUSE_PUBLIC_KEY | Langfuse public key (required to auto-enable) |\n| LANGFUSE_SECRET_KEY | Langfuse secret key (required to auto-enable) |\n| LANGFUSE_BASE_URL | Langfuse host; defaults to Langfuse Cloud","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Environment variables","lvl3":""}},
|
|
3521
3521
|
{"objectID":"304f3b3f1d3d11c91945e49e4ae3f60d2b9a826b87a3948f18fd137a16b38c45","title":"Disable or override","url":"/docs/features/observability#disable-or-override","content":"Every field is optional. publicKey, secretKey, baseUrl, environment and release fall back to the variables above; the others have the defaults below. The type is NeurolinkLangfuseConfig.\n\n| Field | Meaning |\n| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| enabled | false turns Langfuse off although keys are set (from untyped config, the strings \"false\", \"0\", \"off\" and \"no\" do too); any other value, or leaving it out, leaves it on.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Disable or override","lvl3":""}},
|
|
3522
|
-
{"objectID":"d5c2e109ca689299bbc1e1068341dfd6ba1294b1ee3c11cebe6489977865892e","title":"Per-call context","url":"/docs/features/observability#per-call-context","content":"Pass context on generate, stream and decide. The values are attached to every span the call creates, including tool calls and fallback attempts, so one call is one trace.\n\n| Field | Recorded as |\n| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |\n| userId | Trace user |\n| sessionId | Trace session |\n| tags | Trace tags |\n| traceName | Trace name |\n| conversationId | Metadata key conversationId |\n| requestId | Metadata key requestId |\n| metadata | Metadata; values up to 200 characters are on every observation, longer values and arrays are recorded in full on the trace only |\n| observationName | Name of the root observation of this call; default generate or stream; not propagated to child observations or used as the trace name |","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Per-call context","lvl3":""}},
|
|
3523
|
-
{"objectID":"d262ba0787c1b57c76e303845fc9c6f447a3a2f747a880270f15c61fcc1863bb","title":"setLangfuseContext","url":"/docs/features/observability#setlangfusecontext","content":"Wrap your own code to attach the same attributes to everything inside it, including spans you create yourself.\n\nsetLangfuseContext(params: NeurolinkTraceContext, fn) returns whatever fn returns. It is a thin wrapper over Langfuse's propagateAttributes.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"setLangfuseContext","lvl3":""}},
|
|
3522
|
+
{"objectID":"d5c2e109ca689299bbc1e1068341dfd6ba1294b1ee3c11cebe6489977865892e","title":"Per-call context","url":"/docs/features/observability#per-call-context","content":"Pass context on generate, stream and decide. The values are attached to every span the call creates, including tool calls and fallback attempts, so one call is one trace.\n\n| Field | Recorded as |\n| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |\n| userId | Trace user |\n| sessionId | Trace session |\n| tags | Trace tags |\n| traceName | Trace name |\n| conversationId | Metadata key conversationId |\n| requestId | Metadata key requestId |\n| metadata | Metadata; values up to 200 characters are on every observation, longer values and arrays are recorded in full on the trace only |\n| observationName | Name of the root observation of this call; default generate or stream; not propagated to child observations or used as the trace name |\n| redactIO | true leaves this call's input and output out of what is sent to Langfuse; see Redacting a call or scope |","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Per-call context","lvl3":""}},
|
|
3523
|
+
{"objectID":"d262ba0787c1b57c76e303845fc9c6f447a3a2f747a880270f15c61fcc1863bb","title":"setLangfuseContext","url":"/docs/features/observability#setlangfusecontext","content":"Wrap your own code to attach the same attributes to everything inside it, including spans you create yourself.\n\nsetLangfuseContext(params: NeurolinkTraceContext, fn) returns whatever fn returns. It is a thin wrapper over Langfuse's propagateAttributes. It takes the fields in the table above except observationName, plus prompt.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"setLangfuseContext","lvl3":""}},
|
|
3524
3524
|
{"objectID":"ebe52665a13e8e28856b65cd1d82bb2709538cb3fdd9b2ab6e54cd7061a8fb0d","title":"Langfuse prompts","url":"/docs/features/observability#langfuse-prompts","content":"getLangfusePrompt(name, options) fetches a text prompt from Langfuse Prompt Management with the keys and host tracing uses (observability.langfuse, then LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, LANGFUSE_BASE_URL). Pass the result as prompt to setLangfuseContext and Langfuse links the generations inside to that prompt version.\n\n| Option | Default | Effect |\n| ------------ | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| label | production | Deployment label to fetch |\n| fallback | required | Text returned when the prompt cannot be fetched as a text prompt |\n| cacheTtlMs | 60000 | How long a prompt is served from the cache before it is refreshed in the background; the call that fetches an entry sets it for every caller of that name and label |\n| timeoutMs | 2000 | How long one fetch waits for Langfuse |\n\nIt never throws. Prompts are cached per project, host, name and label, up to 500 entries (the least recently fetched is dropped first), and each call gets its own copy; concurrent callers share one request, and an expired entry is returned at once while it refreshes.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Langfuse prompts","lvl3":""}},
|
|
3525
3525
|
{"objectID":"542eff7388511fe18f61b3de966dff32a0a0ccfa5c95df170298790e0233739d","title":"Naming","url":"/docs/features/observability#naming","content":"The observations below (generate, stream, decide, attempts, steps and tools) carry no product name in their span names, attribute keys or metadata keys. Names never carry per-execution values: the model and provider are fields, the step number is metadata. The product name remains in the plain spans listed under Other spans and in the proxy root's neurolink.user_id, neurolink.session_id and neurolink.conversation_id attributes.\n\n| Observation | Name | Langfuse type | Parent |\n| -------------------------- | ------------------------------------- | ------------- | ---------------------- |\n| generate / stream call | generate / stream | agent | none (trace root) |\n| Fallback attempt | generate.attempt / stream.attempt | span | root |\n| Agent loop step | step (step_index metadata) | span | the attempt span |\n| One model request | generate / stream | generation | its step |\n| Tool execution | the tool's name, e.g. get_weather | tool | the step that ran it |\n| decide | decide | generation | caller or root |\n\nA model request is named after the API the caller used (NeuroLink.generate or provider.generate gives generate, NeuroLink.stream or provider.stream gives stream). Its model is the observation's model field (the model the provider reported, falling back to the requested one) and the provider id is the provider metadata key.\n\nThe trace name is context.traceName when given, otherwise the operation name (generate, stream). An outer setLangfuseContext takes precedence over per-call context for user, session and trace name.\n\nEmbeddings, transcribe, TTS and media tracing are not yet recorded. The root also sets trace-level input and output; a generate or stream nested inside another turn does not.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Naming","lvl3":""}},
|
|
3526
3526
|
{"objectID":"bec7707961c02d5123e4dceed9e13f5f5311e2f47783dd81fc290b467f50ff7a","title":"Other spans","url":"/docs/features/observability#other-spans","content":"Spans from the RAG, workflow, file, memory, context and evaluation code are exported as plain span records with their name, timing, status and their own attributes. They keep their neurolink.* names: neurolink.rag.search, neurolink.rag.rerank, neurolink.rag.chunk, neurolink.workflow.* (run, run.streaming, response.condition, judge.score, ensemble.execute, layers.execute), neurolink.file.process, neurolink.file.video.process, neurolink.context.compact, neurolink.memory.summarize and neurolink.evaluation.ragas.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Other spans","lvl3":""}},
|
|
3527
3527
|
{"objectID":"ceb0e84f71b6a9deb6a57e236efa009236e933eb892ad569d59e36ba873292f3","title":"Steps and chat format","url":"/docs/features/observability#steps-and-chat-format","content":"Each iteration of the agent loop gets one step span with its one-based index in the step_index metadata. It parents that iteration's generation and the tool observations the model requested in it, so a multi-tool turn reads as step 1 (call, tools), step 2 (call, tools), and so on.\n\nGeneration input is a chat message array with the system message first. Generation output is an assistant message array: content, plus reasoning and tool_calls ({ id, type: \"function\", function: { name, arguments } }) when present. Langfuse renders both as a conversation.\n\nGeneration details:\nUsage includes input, output, total, cache read, cache creation and reasoning tokens, whatever naming the provider uses.\nCost is computed from NeuroLink's pricing table and recorded as costDetails.total.\nModel parameters are temperature, max tokens, top-p and thinking level.\nTime to first token is recorded as the generation's completion start time for streams.\nLevel is WARNING for a length or content-filter finish, an aborted call, an early break out of a stream, or an empty output, and ERROR when the call throws.\nStreams end their spans when the stream finishes, is abandoned or is aborted.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Steps and chat format","lvl3":""}},
|
|
3528
|
-
{"objectID":"7dbc08e9d130f6a8e970396c854cb6afb0be27558cdbaa21122d1df517e4006a","title":"Masking sensitive data","url":"/docs/features/observability#masking-sensitive-data","content":"mask runs on the input, output and metadata sent to Langfuse. It receives { data } and returns the value to send.\n\nmask and redactIO act on what NeuroLink sends to Langfuse, and on nothing else. They cover the trace and observation input and output (langfuse.observation.input, langfuse.observation.output, langfuse.trace.input, langfuse.trace.output); redactIO: true leaves those out of the request, and mask rewrites them instead. mask also runs on trace and observation metadata, whether or not the metadata is an object. If it throws, the value is replaced by <fully masked>.\n\nEverything else goes to Langfuse as it was recorded: the status message, exception.message, error.message, a tool's tool.error.message and a provider retry's retry.error, tool-call attributes, the proxy.body attribute of proxy body events, event attributes, and the prompt and completion attributes another library's GenAI instrumentation writes on spans that are exported with NeuroLink's. The policy does not reach any other sink either: an exporter you register with registerExporter, the spans NeuroLink sends to OTEL_EXPORTER_OTLP_ENDPOINT, and getSpans() receive the values as they were recorded. If one of them must not see content, take it out
|
|
3528
|
+
{"objectID":"7dbc08e9d130f6a8e970396c854cb6afb0be27558cdbaa21122d1df517e4006a","title":"Masking sensitive data","url":"/docs/features/observability#masking-sensitive-data","content":"mask runs on the input, output and metadata sent to Langfuse. It receives { data } and returns the value to send.\n\nmask and redactIO act on what NeuroLink sends to Langfuse, and on nothing else. They cover the trace and observation input and output (langfuse.observation.input, langfuse.observation.output, langfuse.trace.input, langfuse.trace.output); redactIO: true leaves those out of the request, and mask rewrites them instead. mask also runs on trace and observation metadata, whether or not the metadata is an object. If it throws, the value is replaced by <fully masked>.\n\nEverything else goes to Langfuse as it was recorded: the status message, exception.message, error.message, a tool's tool.error.message and a provider retry's retry.error, tool-call attributes, the proxy.body attribute of proxy body events, event attributes, and the prompt and completion attributes another library's GenAI instrumentation writes on spans that are exported with NeuroLink's. The policy does not reach any other sink either: an exporter you register with registerExporter, the spans NeuroLink sends to OTEL_EXPORTER_OTLP_ENDPOINT, and getSpans() receive the values as they were recorded. If one of them must not see content, take it out in that sink's own processing. NEUROLINK_RECORD_INPUTS=false keeps the inputs NeuroLink records (prompts, messages, tool arguments) out of the spans Langfuse, registerExporter exporters and OTEL_EXPORTER_OTLP_ENDPOINT receive. It does not filter the prompt attributes another library's instrumentation writes, or the stream records getSpans() returns, which still carry the prompt; output and error text are recorded either way.\n\nNeuroLink adds no credential masking of its own to error text. A failed call's status message, error.message, tool.error.message, retry.error and exception text are recorded as the provider returned them, in every sink, as the released build did, so an error that echoes a key reaches the sinks with the key.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Masking sensitive data","lvl3":""}},
|
|
3529
|
+
{"objectID":"f53dc64dd277933d89cc2fb8a6430c75fc283d5299a132602a62927d54b9a523","title":"Redacting a call or scope","url":"/docs/features/observability#redacting-a-call-or-scope","content":"The exporter's redactIO applies to every trace. To leave input and output out of some calls only, such as those that carry end-user content, pass redactIO: true in a call's context, or wrap the code in setLangfuseContext:\n\nEvery observation started inside the call or scope, nested scopes included, is sent to Langfuse without input and output. Observations started outside it keep theirs, including spans that were already open when it began, such as a trace root your code created, so a context.redactIO on a nested generate covers that call only. It covers the same attributes as the exporter's redactIO, and redactIO: false cannot undo an enclosing scope's or the exporter's redactIO. The scope is applied by NeuroLink's span processor, so it works with the exporter pipeline (createExporterSpanProcessor) and not with a LangfuseSpanProcessor you add yourself.\n\nSpans started inside carry the attribute neurolink.langfuse.redact_io: true. The Langfuse request drops it along with the input and output; an exporter registered with registerExporter and the spans sent to OTEL_EXPORTER_OTLP_ENDPOINT receive it with the content as recorded, so a sink of your own can redact the same spans. The records getSpans() returns are built separately and do not carry it.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Redacting a call or scope","lvl3":""}},
|
|
3529
3530
|
{"objectID":"bc90fcd87977756303a1a998fc869c12bbd8ef1f1b88e4f17746e4bd4463d15f","title":"Langfuse exporter behaviour","url":"/docs/features/observability#langfuse-exporter-behaviour","content":"Endpoint. POST {baseUrl}/api/public/otel/v1/traces as OTLP/HTTP JSON. Requests are cut at 500 spans or 3.5 MB.\nObservation types. Agent, generation, tool, step, attempt and the other observation types reach Langfuse with their native type, model, parameters, usage, cost and first-token time.\nIdentity. User, session, trace name, tags and trace metadata are set on every observation, not only the root.\nEnvironment and release. The config field, then LANGFUSE_TRACING_ENVIRONMENT / LANGFUSE_RELEASE; they fill spans that do not carry them already. The OTLP resource's deployment.environment and service.version also read LANGFUSE_ENVIRONMENT, PUBLIC_APP_ENVIRONMENT and PUBLIC_APP_VERSION; Langfuse traces do not.\nBatching. Spans are sent when flushAt spans are queued, every flushInterval seconds, on flushOpenTelemetry() and on shutdown. exportMode: \"immediate\" sends each span as it ends.\nFailures. A request that fails with 429, 5xx or a network error is retried with exponential backoff, or after the Retry-After a 429 or 503 names, up to 60 seconds and never past a flush's budget. Other 4xx responses are not retried. Spans Langfuse reports as rejected (partialSuccess) are logged once as a warning and not re-sent; a success whose body is not an object, or whose rejected count is not a whole number between zero and the spans sent, counts as all delivered. At most 4 export requests are in flight at once. Spans that end meanwhile wait, up to 10,000 of them; when Langfuse stops answering, the oldest waiting spans are dropped, counted in failedSpans and in the errors of healthCheck(), and warned about once a minute. Spans that end during shutdown are sent within the flush budget or counted as dropped. A 401 or 403 is not retried; it is logged as an error (\"Langfuse credentials rejected\") with the spans dropped at most once a minute, once more when the credentials are accepted again, and for any remainder at shutdown, and a refused batch gets no Dropped N of M spans warning.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Langfuse exporter behaviour","lvl3":""}},
|
|
3530
3531
|
{"objectID":"07d102a2518a59d4afc8618d87ee066c3c7e36fefe22ee00772e172d8055a720","title":"Metrics","url":"/docs/features/observability#metrics","content":"NeuroLink also records OpenTelemetry metrics, on one meter named neurolink-ai. They are recorded only when OTEL_EXPORTER_OTLP_ENDPOINT is set, when NEUROLINK_TELEMETRY_ENABLED=true, or when a global MeterProvider is registered (your application's, or NeuroLink's own); a global TracerProvider alone, NeuroLink's included, does not turn them on. They are written to the global MeterProvider. NeuroLink registers one, exporting to $OTEL_EXPORTER_OTLP_ENDPOINT/v1/metrics every 15 seconds, only when it owns the tracer provider and the endpoint is set; beside a host provider they go to the MeterProvider your application registered, and nowhere when it registered none.\n\n| Metric | Kind | Labels | Recorded for |\n| ----------------------------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| ai_requests_total | counter | provider, model | each generate() that finishes in BaseProvider.finalizeNativeGenerate (the native generate path of providers such as Anthropic, SageMaker and the OpenAI Chat Completions family), and each proxied request whose usage the proxy captured |\n| ai_request_duration_ms | histogram,","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Metrics","lvl3":""}},
|
|
3531
3532
|
{"objectID":"ba32010e859f5101a6247151e93a3db0fdaa79d0afe2d47c1492c74a0e04f5f5","title":"External OpenTelemetry provider","url":"/docs/features/observability#external-opentelemetry-provider","content":"If your application registers its own global TracerProvider before tracing starts, NeuroLink creates no provider. OTEL_EXPORTER_OTLP_ENDPOINT is then ignored: NeuroLink logs one warning and exports no traces or metrics to it, so add an OTLP exporter, or any other vendor's span processor, to your own providers. neurolink.getTelemetryStatus().openTelemetry then reports usingExternalProvider: true (its enabled stays whether tracing is initialized, as before), and neurolink telemetry status and neurolink observability status print the endpoint as ignored. NeuroLink's metrics are recorded on the MeterProvider your application registers. For Langfuse choose one of two recipes.\n\nThe host provider must register a context manager, which NodeTracerProvider.register() and NodeSDK do. Without one OpenTelemetry cannot carry context between calls, so setLangfuseContext user, session and metadata never reach NeuroLink's spans and child spans lose their parents; NeuroLink logs a warning when it finds none. Shutting the host provider down shuts the shared exporters down, as createExporterSpanProcessor() always did. If the host rebuilds its provider, pass createExporterSpanProcessor(undefined, { shutdownExporters: false }): that processor only flushes the exporters on shutdown, so a rebuilt provider that adds one again keeps exporting.\n\n(a) Exporter pipeline (recommended). Add createExporterSpanProcessor() to your provider and give NeuroLink the Langfuse keys, either through new NeuroLink({ observability: { langfuse } }) or the LANGFUSE_PUBLIC_KEY / LANGFUSE_SECRET_KEY environment variables. NeuroLink registers its LangfuseExporter on the shared exporter registry, which the processor reads, so mask, batching, chunking and retry from the section above all apply. Register the processor before the first NeuroLink call; spans that end before the exporter is registered are not exported.\n\n(b) LangfuseSpanProcessor.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"External OpenTelemetry provider","lvl3":""}},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juspay/neurolink",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.16.0",
|
|
4
4
|
"packageManager": "pnpm@10.34.9+sha512.f49b5a8ea0fdedb44bb3c0c1d6575092a53c2950d95b7ad15df11f17974877a2de3a01c07e934e9b28ce716e51c09a94962c7306d09be2e1e4b18a8c8762fd32",
|
|
5
5
|
"description": "The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002/call) for routing, tool selection and context budgeting. MCP-native (4 transports), voice TTS/STT/realtime, RAG, agents, memory, compaction, 9 observability exporters. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · TypeSafe Jev and more.",
|
|
6
6
|
"author": {
|
|
@@ -390,6 +390,7 @@
|
|
|
390
390
|
"test:native-failure-events": "pnpm exec tsx test/continuous-test-suite-native-failure-events.ts",
|
|
391
391
|
"test:native-audio-model-aware": "pnpm exec tsx test/continuous-test-suite-native-audio-model-aware.ts",
|
|
392
392
|
"test:cli-json-output": "pnpm exec tsx test/continuous-test-suite-cli-json-output.ts",
|
|
393
|
+
"test:cli-unknown-option": "pnpm exec tsx test/continuous-test-suite-cli-unknown-option.ts",
|
|
393
394
|
"test:logging-guidelines": "pnpm exec tsx test/continuous-test-suite-logging-guidelines.ts",
|
|
394
395
|
"test:proxy-polyfills": "pnpm exec tsx test/continuous-test-suite-proxy-polyfills.ts",
|
|
395
396
|
"test:mcp:startup-readiness": "pnpm exec tsx test/continuous-test-suite-mcp-startup-readiness.ts",
|