@anvia/langfuse 0.3.8 → 0.4.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/README.md +26 -22
- package/dist/index.d.ts +4 -1
- package/dist/index.js +518 -145
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -63,6 +63,8 @@ explicit options always win.
|
|
|
63
63
|
| `environment` | `LANGFUSE_TRACING_ENVIRONMENT`| Tag attached to every trace. |
|
|
64
64
|
| `release` | `LANGFUSE_RELEASE` | Tag attached to every trace. |
|
|
65
65
|
| `serviceName` | `LANGFUSE_SERVICE_NAME` | Recorded on the root observation and as the OTel `service.name` resource attribute. |
|
|
66
|
+
| `captureMode` | — | `"safe"` (default) records instructions/messages plus request summaries; `"full"` includes documents, tool definitions, schemas, and additional parameters. |
|
|
67
|
+
| `captureMaxBytes` | — | Maximum encoded size per captured value; defaults to 262,144 bytes and must be at least 96. |
|
|
66
68
|
|
|
67
69
|
```ts
|
|
68
70
|
const tracing = langfuse.create({
|
|
@@ -73,24 +75,26 @@ const tracing = langfuse.create({
|
|
|
73
75
|
|
|
74
76
|
## Observation metadata
|
|
75
77
|
|
|
76
|
-
The adapter records
|
|
77
|
-
|
|
78
|
+
The adapter records structured model and runtime data while keeping
|
|
79
|
+
the default capture surface bounded:
|
|
78
80
|
|
|
79
|
-
- **Generation observations** carry
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
`
|
|
81
|
+
- **Generation observations** carry system instructions, model messages,
|
|
82
|
+
the resolved model, and `modelInfo`. Full capture also includes the
|
|
83
|
+
sanitized `providerRequest`.
|
|
84
|
+
`completionStartTime` and `firstDeltaMs` provide native time-to-first-token data.
|
|
85
|
+
- **Usage details** use mutually exclusive `input`, `output`, cache, and
|
|
86
|
+
reasoning buckets so Langfuse can infer cost without double counting.
|
|
83
87
|
- **Generation observations** receive a `generation.update({ output: { delta } })`
|
|
84
88
|
call for every streaming delta (`text_delta`, `reasoning_delta`,
|
|
85
89
|
`tool_call`), so the Langfuse UI reflects partial output as the
|
|
86
90
|
model produces it.
|
|
87
|
-
- **Tool observations** carry
|
|
88
|
-
|
|
91
|
+
- **Tool observations** carry arguments on start and structured results on
|
|
92
|
+
end. Definitions and tool metadata are included when `captureMode: "full"`.
|
|
89
93
|
- **Root run observation** carries `serviceName` and the configured
|
|
90
94
|
`metadata` from `AgentRunStartArgs`.
|
|
91
95
|
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
Binary and base64 bodies are replaced with omission markers. Oversized
|
|
97
|
+
values are replaced with deterministic bounded previews.
|
|
94
98
|
|
|
95
99
|
## Eval Scores
|
|
96
100
|
|
|
@@ -231,8 +235,8 @@ trace?.addEvent("validation.passed");
|
|
|
231
235
|
trace?.addAttributes({ quality: "high" });
|
|
232
236
|
```
|
|
233
237
|
|
|
234
|
-
`addEvent` creates
|
|
235
|
-
root
|
|
238
|
+
`addEvent` creates an instantaneous Langfuse `event` observation under the active
|
|
239
|
+
root. `addAttributes` updates the root
|
|
236
240
|
observation's metadata. Both calls bubble up to Langfuse via the
|
|
237
241
|
existing OpenTelemetry span processor.
|
|
238
242
|
|
|
@@ -369,13 +373,12 @@ const prompts = createLangfusePromptClient(tracing);
|
|
|
369
373
|
const prompt = await prompts.getPrompt("support.system");
|
|
370
374
|
console.log(prompt.prompt, prompt.version);
|
|
371
375
|
|
|
372
|
-
await
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
});
|
|
376
|
+
await agent
|
|
377
|
+
.prompt("hi")
|
|
378
|
+
.withTrace({
|
|
379
|
+
promptRef: { name: "support.system", version: prompt.version },
|
|
380
|
+
})
|
|
381
|
+
.send();
|
|
379
382
|
```
|
|
380
383
|
|
|
381
384
|
`promptRef` is also accepted on `trace.metadata` (keys
|
|
@@ -424,9 +427,10 @@ const tracing = langfuse.create({
|
|
|
424
427
|
});
|
|
425
428
|
```
|
|
426
429
|
|
|
427
|
-
- `redactInputs` redacts
|
|
428
|
-
arguments.
|
|
429
|
-
- `redactOutputs` redacts generation output
|
|
430
|
+
- `redactInputs` redacts system instructions, root inputs, chat history,
|
|
431
|
+
tool arguments, request metadata, and nested-agent inputs.
|
|
432
|
+
- `redactOutputs` redacts streaming/final generation output, errors,
|
|
433
|
+
tool results, transcripts, and nested-agent outputs.
|
|
430
434
|
- `"deep"` recurses into nested objects and arrays (in addition to
|
|
431
435
|
top-level strings).
|
|
432
436
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { AgentObserver } from '@anvia/core/observability';
|
|
|
3
3
|
import { EvalReporter, EvalSuiteResult, RunEvalSuiteOptions } from '@anvia/core/evals';
|
|
4
4
|
|
|
5
5
|
type LangfuseRedactionMode = boolean | "deep";
|
|
6
|
+
type LangfuseCaptureMode = "safe" | "full";
|
|
6
7
|
type LangfuseRedactionOptions$1 = {
|
|
7
8
|
patterns?: RedactorPattern$1[];
|
|
8
9
|
replacement?: string;
|
|
@@ -22,6 +23,8 @@ type LangfuseTracingOptions = {
|
|
|
22
23
|
scoreBatchSize?: number | undefined;
|
|
23
24
|
scoreFlushIntervalMs?: number | undefined;
|
|
24
25
|
scoreMaxRetries?: number | undefined;
|
|
26
|
+
captureMode?: LangfuseCaptureMode | undefined;
|
|
27
|
+
captureMaxBytes?: number | undefined;
|
|
25
28
|
redactInputs?: LangfuseRedactionMode | undefined;
|
|
26
29
|
redactOutputs?: LangfuseRedactionMode | undefined;
|
|
27
30
|
redaction?: LangfuseRedactionOptions$1 | undefined;
|
|
@@ -193,4 +196,4 @@ declare const langfuse: {
|
|
|
193
196
|
create(options?: LangfuseTracingOptions): LangfuseTracing;
|
|
194
197
|
};
|
|
195
198
|
|
|
196
|
-
export { DEFAULT_PATTERNS, type LangfuseChatMessage, type LangfuseDataset, type LangfuseDatasetClient, type LangfuseDatasetClientOptions, type LangfuseDatasetItem, type LangfuseEvalReporterOptions, type LangfusePrompt, type LangfusePromptClient, type LangfusePromptClientOptions, type LangfusePromptGetOptions, type LangfuseRedactionMode, type LangfuseRedactionOptions, type LangfuseRunExperimentOptions, type LangfuseRunExperimentResult, type LangfuseRunItemError, type LangfuseRunItemResult, type LangfuseScoreArgs, type LangfuseScoreDataType, LangfuseScoreError, type LangfuseTraceHandle, type LangfuseTracing, type LangfuseTracingOptions, type PiiRedactor, type RedactorPattern, type RunEvalAsExperimentOptions, type RunEvalAsExperimentResult, createLangfuseDatasetClient, createLangfuseEvalReporter, createLangfusePromptClient, createPiiRedactor, langfuse, runEvalAsExperiment };
|
|
199
|
+
export { DEFAULT_PATTERNS, type LangfuseCaptureMode, type LangfuseChatMessage, type LangfuseDataset, type LangfuseDatasetClient, type LangfuseDatasetClientOptions, type LangfuseDatasetItem, type LangfuseEvalReporterOptions, type LangfusePrompt, type LangfusePromptClient, type LangfusePromptClientOptions, type LangfusePromptGetOptions, type LangfuseRedactionMode, type LangfuseRedactionOptions, type LangfuseRunExperimentOptions, type LangfuseRunExperimentResult, type LangfuseRunItemError, type LangfuseRunItemResult, type LangfuseScoreArgs, type LangfuseScoreDataType, LangfuseScoreError, type LangfuseTraceHandle, type LangfuseTracing, type LangfuseTracingOptions, type PiiRedactor, type RedactorPattern, type RunEvalAsExperimentOptions, type RunEvalAsExperimentResult, createLangfuseDatasetClient, createLangfuseEvalReporter, createLangfusePromptClient, createPiiRedactor, langfuse, runEvalAsExperiment };
|