@langfuse/tracing 4.6.1 → 5.0.0-beta.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/dist/index.cjs +75 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +94 -67
- package/dist/index.d.ts +94 -67
- package/dist/index.mjs +69 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -27,7 +27,7 @@ __export(index_exports, {
|
|
|
27
27
|
LangfuseEvent: () => LangfuseEvent,
|
|
28
28
|
LangfuseGeneration: () => LangfuseGeneration,
|
|
29
29
|
LangfuseGuardrail: () => LangfuseGuardrail,
|
|
30
|
-
LangfuseOtelSpanAttributes: () =>
|
|
30
|
+
LangfuseOtelSpanAttributes: () => import_core6.LangfuseOtelSpanAttributes,
|
|
31
31
|
LangfuseRetriever: () => LangfuseRetriever,
|
|
32
32
|
LangfuseSpan: () => LangfuseSpan,
|
|
33
33
|
LangfuseTool: () => LangfuseTool,
|
|
@@ -39,44 +39,27 @@ __export(index_exports, {
|
|
|
39
39
|
getLangfuseTracer: () => getLangfuseTracer,
|
|
40
40
|
getLangfuseTracerProvider: () => getLangfuseTracerProvider,
|
|
41
41
|
observe: () => observe,
|
|
42
|
-
propagateAttributes: () =>
|
|
42
|
+
propagateAttributes: () => import_core5.propagateAttributes,
|
|
43
|
+
setActiveTraceAsPublic: () => setActiveTraceAsPublic,
|
|
44
|
+
setActiveTraceIO: () => setActiveTraceIO,
|
|
43
45
|
setLangfuseTracerProvider: () => setLangfuseTracerProvider,
|
|
44
46
|
startActiveObservation: () => startActiveObservation,
|
|
45
47
|
startObservation: () => startObservation,
|
|
46
|
-
updateActiveObservation: () => updateActiveObservation
|
|
47
|
-
updateActiveTrace: () => updateActiveTrace
|
|
48
|
+
updateActiveObservation: () => updateActiveObservation
|
|
48
49
|
});
|
|
49
50
|
module.exports = __toCommonJS(index_exports);
|
|
50
|
-
var
|
|
51
|
+
var import_core4 = require("@langfuse/core");
|
|
51
52
|
var import_api2 = require("@opentelemetry/api");
|
|
52
53
|
|
|
53
54
|
// src/attributes.ts
|
|
54
55
|
var import_core = require("@langfuse/core");
|
|
55
56
|
function createTraceAttributes({
|
|
56
|
-
name,
|
|
57
|
-
userId,
|
|
58
|
-
sessionId,
|
|
59
|
-
version,
|
|
60
|
-
release,
|
|
61
57
|
input,
|
|
62
|
-
output
|
|
63
|
-
metadata,
|
|
64
|
-
tags,
|
|
65
|
-
environment,
|
|
66
|
-
public: isPublic
|
|
58
|
+
output
|
|
67
59
|
} = {}) {
|
|
68
60
|
const attributes = {
|
|
69
|
-
[import_core.LangfuseOtelSpanAttributes.TRACE_NAME]: name,
|
|
70
|
-
[import_core.LangfuseOtelSpanAttributes.TRACE_USER_ID]: userId,
|
|
71
|
-
[import_core.LangfuseOtelSpanAttributes.TRACE_SESSION_ID]: sessionId,
|
|
72
|
-
[import_core.LangfuseOtelSpanAttributes.VERSION]: version,
|
|
73
|
-
[import_core.LangfuseOtelSpanAttributes.RELEASE]: release,
|
|
74
61
|
[import_core.LangfuseOtelSpanAttributes.TRACE_INPUT]: _serialize(input),
|
|
75
|
-
[import_core.LangfuseOtelSpanAttributes.TRACE_OUTPUT]: _serialize(output)
|
|
76
|
-
[import_core.LangfuseOtelSpanAttributes.TRACE_TAGS]: tags,
|
|
77
|
-
[import_core.LangfuseOtelSpanAttributes.ENVIRONMENT]: environment,
|
|
78
|
-
[import_core.LangfuseOtelSpanAttributes.TRACE_PUBLIC]: isPublic,
|
|
79
|
-
..._flattenAndSerializeMetadata(metadata, "trace")
|
|
62
|
+
[import_core.LangfuseOtelSpanAttributes.TRACE_OUTPUT]: _serialize(output)
|
|
80
63
|
};
|
|
81
64
|
return Object.fromEntries(
|
|
82
65
|
Object.entries(attributes).filter(([_, v]) => v != null)
|
|
@@ -149,6 +132,9 @@ function _flattenAndSerializeMetadata(metadata, type) {
|
|
|
149
132
|
return metadataAttributes;
|
|
150
133
|
}
|
|
151
134
|
|
|
135
|
+
// src/spanWrapper.ts
|
|
136
|
+
var import_core3 = require("@langfuse/core");
|
|
137
|
+
|
|
152
138
|
// src/tracerProvider.ts
|
|
153
139
|
var import_core2 = require("@langfuse/core");
|
|
154
140
|
var import_api = require("@opentelemetry/api");
|
|
@@ -233,12 +219,53 @@ var LangfuseBaseObservation = class {
|
|
|
233
219
|
);
|
|
234
220
|
}
|
|
235
221
|
/**
|
|
236
|
-
*
|
|
222
|
+
* Set trace-level input and output for the trace this observation belongs to.
|
|
223
|
+
*
|
|
224
|
+
* @deprecated This is a legacy method for backward compatibility with Langfuse platform
|
|
225
|
+
* features that still rely on trace-level input/output (e.g., legacy LLM-as-a-judge
|
|
226
|
+
* evaluators). It will be removed in a future major version.
|
|
227
|
+
*
|
|
228
|
+
* For setting other trace attributes (userId, sessionId, metadata, tags, version),
|
|
229
|
+
* use {@link propagateAttributes} instead.
|
|
230
|
+
*
|
|
231
|
+
* @param attributes - Input and output data to associate with the trace
|
|
232
|
+
* @returns The observation instance for method chaining
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* const span = startObservation('my-operation');
|
|
237
|
+
* span.setTraceIO({
|
|
238
|
+
* input: { query: 'user question' },
|
|
239
|
+
* output: { response: 'assistant answer' }
|
|
240
|
+
* });
|
|
241
|
+
* ```
|
|
237
242
|
*/
|
|
238
|
-
|
|
243
|
+
setTraceIO(attributes) {
|
|
239
244
|
this.otelSpan.setAttributes(createTraceAttributes(attributes));
|
|
240
245
|
return this;
|
|
241
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Make the trace this observation belongs to publicly accessible via its URL.
|
|
249
|
+
*
|
|
250
|
+
* When a trace is published, anyone with the trace link can view the full trace
|
|
251
|
+
* without needing to be logged in to Langfuse. This action cannot be undone
|
|
252
|
+
* programmatically - once any span in a trace is published, the entire trace
|
|
253
|
+
* becomes public.
|
|
254
|
+
*
|
|
255
|
+
* @returns The observation instance for method chaining
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* const span = startObservation('my-operation');
|
|
260
|
+
* span.setTraceAsPublic();
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
setTraceAsPublic() {
|
|
264
|
+
this.otelSpan.setAttributes({
|
|
265
|
+
[import_core3.LangfuseOtelSpanAttributes.TRACE_PUBLIC]: true
|
|
266
|
+
});
|
|
267
|
+
return this;
|
|
268
|
+
}
|
|
242
269
|
startObservation(name, attributes, options) {
|
|
243
270
|
const { asType = "span" } = options || {};
|
|
244
271
|
return startObservation(name, attributes, {
|
|
@@ -445,8 +472,8 @@ var LangfuseEvent = class extends LangfuseBaseObservation {
|
|
|
445
472
|
};
|
|
446
473
|
|
|
447
474
|
// src/index.ts
|
|
448
|
-
var import_core4 = require("@langfuse/core");
|
|
449
475
|
var import_core5 = require("@langfuse/core");
|
|
476
|
+
var import_core6 = require("@langfuse/core");
|
|
450
477
|
function createOtelSpan(params) {
|
|
451
478
|
return getLangfuseTracer().startSpan(
|
|
452
479
|
params.name,
|
|
@@ -634,21 +661,33 @@ function startActiveObservation(name, fn, options) {
|
|
|
634
661
|
}
|
|
635
662
|
);
|
|
636
663
|
}
|
|
637
|
-
function
|
|
664
|
+
function setActiveTraceIO(attributes) {
|
|
638
665
|
const span = import_api2.trace.getActiveSpan();
|
|
639
666
|
if (!span) {
|
|
640
|
-
(0,
|
|
641
|
-
"No active OTEL span in context. Skipping trace update."
|
|
667
|
+
(0, import_core4.getGlobalLogger)().warn(
|
|
668
|
+
"No active OTEL span in context. Skipping trace IO update."
|
|
642
669
|
);
|
|
643
670
|
return;
|
|
644
671
|
}
|
|
645
672
|
span.setAttributes(createTraceAttributes(attributes));
|
|
646
673
|
}
|
|
674
|
+
function setActiveTraceAsPublic() {
|
|
675
|
+
const span = import_api2.trace.getActiveSpan();
|
|
676
|
+
if (!span) {
|
|
677
|
+
(0, import_core4.getGlobalLogger)().warn(
|
|
678
|
+
"No active OTEL span in context. Skipping trace publish."
|
|
679
|
+
);
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
span.setAttributes({
|
|
683
|
+
[import_core4.LangfuseOtelSpanAttributes.TRACE_PUBLIC]: true
|
|
684
|
+
});
|
|
685
|
+
}
|
|
647
686
|
function updateActiveObservation(attributes, options) {
|
|
648
687
|
var _a;
|
|
649
688
|
const span = import_api2.trace.getActiveSpan();
|
|
650
689
|
if (!span) {
|
|
651
|
-
(0,
|
|
690
|
+
(0, import_core4.getGlobalLogger)().warn(
|
|
652
691
|
"No active OTEL span in context. Skipping span update."
|
|
653
692
|
);
|
|
654
693
|
return;
|
|
@@ -658,7 +697,7 @@ function updateActiveObservation(attributes, options) {
|
|
|
658
697
|
attributes
|
|
659
698
|
);
|
|
660
699
|
if (!(options == null ? void 0 : options.asType)) {
|
|
661
|
-
otelAttributes[
|
|
700
|
+
otelAttributes[import_core4.LangfuseOtelSpanAttributes.OBSERVATION_TYPE] = void 0;
|
|
662
701
|
}
|
|
663
702
|
span.setAttributes(otelAttributes);
|
|
664
703
|
}
|
|
@@ -791,10 +830,11 @@ function getActiveSpanId() {
|
|
|
791
830
|
getLangfuseTracerProvider,
|
|
792
831
|
observe,
|
|
793
832
|
propagateAttributes,
|
|
833
|
+
setActiveTraceAsPublic,
|
|
834
|
+
setActiveTraceIO,
|
|
794
835
|
setLangfuseTracerProvider,
|
|
795
836
|
startActiveObservation,
|
|
796
837
|
startObservation,
|
|
797
|
-
updateActiveObservation
|
|
798
|
-
updateActiveTrace
|
|
838
|
+
updateActiveObservation
|
|
799
839
|
});
|
|
800
840
|
//# sourceMappingURL=index.cjs.map
|