@langfuse/tracing 4.6.0 → 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.d.cts CHANGED
@@ -101,36 +101,22 @@ type LangfuseEmbeddingAttributes = LangfuseGenerationAttributes;
101
101
  */
102
102
  type LangfuseObservationAttributes = LangfuseSpanAttributes & LangfuseGenerationAttributes & LangfuseEventAttributes & LangfuseAgentAttributes & LangfuseToolAttributes & LangfuseChainAttributes & LangfuseRetrieverAttributes & LangfuseEvaluatorAttributes & LangfuseGuardrailAttributes;
103
103
  /**
104
- * Attributes for Langfuse traces.
104
+ * Attributes for setting trace-level input and output only.
105
105
  *
106
- * Traces are the top-level containers that group related observations together.
107
- * They represent a complete workflow, request, or user interaction.
106
+ * This is a restricted type used by the deprecated setTraceIO methods,
107
+ * which only allow setting input and output on traces for backward
108
+ * compatibility with legacy Langfuse platform features.
109
+ *
110
+ * @deprecated This type is for backward compatibility with legacy platform features
111
+ * that still rely on trace-level input/output. Use propagateAttributes for other trace attributes.
108
112
  *
109
113
  * @public
110
114
  */
111
115
  type LangfuseTraceAttributes = {
112
- /** Human-readable name for the trace */
113
- name?: string;
114
- /** Identifier for the user associated with this trace */
115
- userId?: string;
116
- /** Session identifier for grouping related traces */
117
- sessionId?: string;
118
- /** Version identifier for the code/application */
119
- version?: string;
120
- /** Release identifier for deployment tracking */
121
- release?: string;
122
116
  /** Input data that initiated the trace */
123
117
  input?: unknown;
124
118
  /** Final output data from the trace */
125
119
  output?: unknown;
126
- /** Additional metadata for the trace */
127
- metadata?: unknown;
128
- /** Tags for categorizing and filtering traces */
129
- tags?: string[];
130
- /** Whether this trace should be publicly visible */
131
- public?: boolean;
132
- /** Environment where the trace was captured */
133
- environment?: string;
134
120
  };
135
121
 
136
122
  /**
@@ -157,9 +143,6 @@ type LangfuseTraceAttributes = {
157
143
  * // Function accepting any observation type
158
144
  * function logObservation(obs: LangfuseObservation) {
159
145
  * console.log(`Observation ${obs.id} in trace ${obs.traceId}`);
160
- *
161
- * // All observations have common methods
162
- * obs.updateTrace({ tags: ['logged'] });
163
146
  * obs.end();
164
147
  * }
165
148
  *
@@ -209,7 +192,7 @@ type LangfuseObservationParams = {
209
192
  *
210
193
  * ## Common Methods
211
194
  * - `end()`: Marks the observation as complete with optional timestamp
212
- * - `updateTrace()`: Sets trace-level attributes like user ID, session ID, tags
195
+ * - `setTraceIO()`: Sets trace-level input/output (deprecated, for legacy platform features)
213
196
  * - `startObservation()`: Creates child observations with inherited context
214
197
  *
215
198
  * @example
@@ -222,13 +205,6 @@ type LangfuseObservationParams = {
222
205
  * console.log(`Trace ID: ${observation.traceId}`);
223
206
  * console.log(`Type: ${observation.type}`);
224
207
  *
225
- * // Common methods available on all observations
226
- * observation.updateTrace({
227
- * userId: 'user-123',
228
- * sessionId: 'session-456',
229
- * tags: ['production', 'api-v2']
230
- * });
231
- *
232
208
  * // Create child observations
233
209
  * const child = observation.startObservation('child-operation', {
234
210
  * input: { step: 'processing' }
@@ -261,9 +237,45 @@ declare abstract class LangfuseBaseObservation {
261
237
  end(endTime?: TimeInput): void;
262
238
  updateOtelSpanAttributes(attributes: LangfuseObservationAttributes): void;
263
239
  /**
264
- * Updates the parent trace with new attributes.
240
+ * Set trace-level input and output for the trace this observation belongs to.
241
+ *
242
+ * @deprecated This is a legacy method for backward compatibility with Langfuse platform
243
+ * features that still rely on trace-level input/output (e.g., legacy LLM-as-a-judge
244
+ * evaluators). It will be removed in a future major version.
245
+ *
246
+ * For setting other trace attributes (userId, sessionId, metadata, tags, version),
247
+ * use {@link propagateAttributes} instead.
248
+ *
249
+ * @param attributes - Input and output data to associate with the trace
250
+ * @returns The observation instance for method chaining
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * const span = startObservation('my-operation');
255
+ * span.setTraceIO({
256
+ * input: { query: 'user question' },
257
+ * output: { response: 'assistant answer' }
258
+ * });
259
+ * ```
260
+ */
261
+ setTraceIO(attributes: LangfuseTraceAttributes): this;
262
+ /**
263
+ * Make the trace this observation belongs to publicly accessible via its URL.
264
+ *
265
+ * When a trace is published, anyone with the trace link can view the full trace
266
+ * without needing to be logged in to Langfuse. This action cannot be undone
267
+ * programmatically - once any span in a trace is published, the entire trace
268
+ * becomes public.
269
+ *
270
+ * @returns The observation instance for method chaining
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * const span = startObservation('my-operation');
275
+ * span.setTraceAsPublic();
276
+ * ```
265
277
  */
266
- updateTrace(attributes: LangfuseTraceAttributes): this;
278
+ setTraceAsPublic(): this;
267
279
  /**
268
280
  * Creates a new child observation within this observation's context with full type safety.
269
281
  *
@@ -1358,32 +1370,20 @@ declare class LangfuseEvent extends LangfuseBaseObservation {
1358
1370
  }
1359
1371
 
1360
1372
  /**
1361
- * Creates OpenTelemetry attributes from Langfuse trace attributes.
1373
+ * Creates OpenTelemetry attributes from Langfuse trace IO attributes.
1362
1374
  *
1363
- * Converts user-friendly trace attributes into the internal OpenTelemetry
1375
+ * Converts trace input/output into the internal OpenTelemetry
1364
1376
  * attribute format required by the span processor.
1365
1377
  *
1366
- * @param attributes - Langfuse trace attributes to convert
1378
+ * @param attributes - Langfuse trace IO attributes to convert
1367
1379
  * @returns OpenTelemetry attributes object with non-null values
1368
1380
  *
1369
- * @example
1370
- * ```typescript
1371
- * import { createTraceAttributes } from '@langfuse/tracing';
1372
- *
1373
- * const otelAttributes = createTraceAttributes({
1374
- * name: 'user-checkout-flow',
1375
- * userId: 'user-123',
1376
- * sessionId: 'session-456',
1377
- * tags: ['checkout', 'payment'],
1378
- * metadata: { version: '2.1.0' }
1379
- * });
1380
- *
1381
- * span.setAttributes(otelAttributes);
1382
- * ```
1381
+ * @deprecated This is for backward compatibility with legacy platform features
1382
+ * that still rely on trace-level input/output. Use propagateAttributes for other trace attributes.
1383
1383
  *
1384
- * @public
1384
+ * @internal
1385
1385
  */
1386
- declare function createTraceAttributes({ name, userId, sessionId, version, release, input, output, metadata, tags, environment, public: isPublic, }?: LangfuseTraceAttributes): Attributes;
1386
+ declare function createTraceAttributes({ input, output, }?: LangfuseTraceAttributes): Attributes;
1387
1387
  declare function createObservationAttributes(type: LangfuseObservationType, attributes: LangfuseObservationAttributes): Attributes;
1388
1388
 
1389
1389
  /**
@@ -1568,30 +1568,57 @@ declare function startActiveObservation<F extends (span: LangfuseSpan) => unknow
1568
1568
  asType?: "span";
1569
1569
  }): ReturnType<F>;
1570
1570
  /**
1571
- * Updates the currently active trace with new attributes.
1571
+ * Set trace-level input and output for the currently active trace.
1572
+ *
1573
+ * This function finds the currently active OpenTelemetry span and sets
1574
+ * trace-level input/output on it. If no active span is found, a warning is logged.
1572
1575
  *
1573
- * This function finds the currently active OpenTelemetry span and updates
1574
- * it with trace-level attributes. If no active span is found, a warning is logged.
1576
+ * @deprecated This is a legacy function for backward compatibility with Langfuse platform
1577
+ * features that still rely on trace-level input/output (e.g., legacy LLM-as-a-judge
1578
+ * evaluators). It will be removed in a future major version.
1575
1579
  *
1576
- * @param attributes - Trace attributes to set
1580
+ * For setting other trace attributes (userId, sessionId, metadata, tags, version),
1581
+ * use {@link propagateAttributes} instead.
1582
+ *
1583
+ * @param attributes - Input and output data to associate with the trace
1577
1584
  *
1578
1585
  * @example
1579
1586
  * ```typescript
1580
- * import { updateActiveTrace } from '@langfuse/tracing';
1587
+ * import { setActiveTraceIO } from '@langfuse/tracing';
1581
1588
  *
1582
1589
  * // Inside an active span context
1583
- * updateActiveTrace({
1584
- * name: 'user-workflow',
1585
- * userId: '123',
1586
- * sessionId: 'session-456',
1587
- * tags: ['production', 'critical'],
1588
- * public: true
1590
+ * setActiveTraceIO({
1591
+ * input: { query: 'user question' },
1592
+ * output: { response: 'assistant answer' }
1593
+ * });
1594
+ * ```
1595
+ *
1596
+ * @public
1597
+ */
1598
+ declare function setActiveTraceIO(attributes: LangfuseTraceAttributes): void;
1599
+ /**
1600
+ * Make the trace of the currently active span publicly accessible via its URL.
1601
+ *
1602
+ * When a trace is published, anyone with the trace link can view the full trace
1603
+ * without needing to be logged in to Langfuse. This action cannot be undone
1604
+ * programmatically - once any span in a trace is published, the entire trace
1605
+ * becomes public.
1606
+ *
1607
+ * If called outside of an active span context, the operation is skipped with a warning.
1608
+ *
1609
+ * @example
1610
+ * ```typescript
1611
+ * import { setActiveTraceAsPublic, startActiveObservation } from '@langfuse/tracing';
1612
+ *
1613
+ * startActiveObservation('my-operation', () => {
1614
+ * // Make this trace publicly accessible
1615
+ * setActiveTraceAsPublic();
1589
1616
  * });
1590
1617
  * ```
1591
1618
  *
1592
1619
  * @public
1593
1620
  */
1594
- declare function updateActiveTrace(attributes: LangfuseTraceAttributes): void;
1621
+ declare function setActiveTraceAsPublic(): void;
1595
1622
  /**
1596
1623
  * Updates the currently active observation with new attributes.
1597
1624
  *
@@ -1719,7 +1746,7 @@ declare function updateActiveTrace(attributes: LangfuseTraceAttributes): void;
1719
1746
  * ```
1720
1747
  *
1721
1748
  * @see {@link startActiveObservation} - For creating active observation contexts
1722
- * @see {@link updateActiveTrace} - For updating trace-level attributes
1749
+ * @see {@link setActiveTraceIO} - For setting trace-level input/output (deprecated)
1723
1750
  *
1724
1751
  * @public
1725
1752
  */
@@ -2087,4 +2114,4 @@ declare function getActiveTraceId(): string | undefined;
2087
2114
  */
2088
2115
  declare function getActiveSpanId(): string | undefined;
2089
2116
 
2090
- export { LangfuseAgent, LangfuseChain, LangfuseEmbedding, LangfuseEvaluator, LangfuseEvent, type LangfuseEventAttributes, LangfuseGeneration, type LangfuseGenerationAttributes, LangfuseGuardrail, type LangfuseObservation, type LangfuseObservationAttributes, type LangfuseObservationType, LangfuseRetriever, LangfuseSpan, type LangfuseSpanAttributes, LangfuseTool, type LangfuseTraceAttributes, type ObservationLevel, type ObserveOptions, type StartActiveObservationContext, type StartActiveObservationOpts, type StartObservationOptions, type StartObservationOpts, createObservationAttributes, createTraceAttributes, createTraceId, getActiveSpanId, getActiveTraceId, getLangfuseTracer, getLangfuseTracerProvider, observe, setLangfuseTracerProvider, startActiveObservation, startObservation, updateActiveObservation, updateActiveTrace };
2117
+ export { LangfuseAgent, LangfuseChain, LangfuseEmbedding, LangfuseEvaluator, LangfuseEvent, type LangfuseEventAttributes, LangfuseGeneration, type LangfuseGenerationAttributes, LangfuseGuardrail, type LangfuseObservation, type LangfuseObservationAttributes, type LangfuseObservationType, LangfuseRetriever, LangfuseSpan, type LangfuseSpanAttributes, LangfuseTool, type LangfuseTraceAttributes, type ObservationLevel, type ObserveOptions, type StartActiveObservationContext, type StartActiveObservationOpts, type StartObservationOptions, type StartObservationOpts, createObservationAttributes, createTraceAttributes, createTraceId, getActiveSpanId, getActiveTraceId, getLangfuseTracer, getLangfuseTracerProvider, observe, setActiveTraceAsPublic, setActiveTraceIO, setLangfuseTracerProvider, startActiveObservation, startObservation, updateActiveObservation };
package/dist/index.d.ts CHANGED
@@ -101,36 +101,22 @@ type LangfuseEmbeddingAttributes = LangfuseGenerationAttributes;
101
101
  */
102
102
  type LangfuseObservationAttributes = LangfuseSpanAttributes & LangfuseGenerationAttributes & LangfuseEventAttributes & LangfuseAgentAttributes & LangfuseToolAttributes & LangfuseChainAttributes & LangfuseRetrieverAttributes & LangfuseEvaluatorAttributes & LangfuseGuardrailAttributes;
103
103
  /**
104
- * Attributes for Langfuse traces.
104
+ * Attributes for setting trace-level input and output only.
105
105
  *
106
- * Traces are the top-level containers that group related observations together.
107
- * They represent a complete workflow, request, or user interaction.
106
+ * This is a restricted type used by the deprecated setTraceIO methods,
107
+ * which only allow setting input and output on traces for backward
108
+ * compatibility with legacy Langfuse platform features.
109
+ *
110
+ * @deprecated This type is for backward compatibility with legacy platform features
111
+ * that still rely on trace-level input/output. Use propagateAttributes for other trace attributes.
108
112
  *
109
113
  * @public
110
114
  */
111
115
  type LangfuseTraceAttributes = {
112
- /** Human-readable name for the trace */
113
- name?: string;
114
- /** Identifier for the user associated with this trace */
115
- userId?: string;
116
- /** Session identifier for grouping related traces */
117
- sessionId?: string;
118
- /** Version identifier for the code/application */
119
- version?: string;
120
- /** Release identifier for deployment tracking */
121
- release?: string;
122
116
  /** Input data that initiated the trace */
123
117
  input?: unknown;
124
118
  /** Final output data from the trace */
125
119
  output?: unknown;
126
- /** Additional metadata for the trace */
127
- metadata?: unknown;
128
- /** Tags for categorizing and filtering traces */
129
- tags?: string[];
130
- /** Whether this trace should be publicly visible */
131
- public?: boolean;
132
- /** Environment where the trace was captured */
133
- environment?: string;
134
120
  };
135
121
 
136
122
  /**
@@ -157,9 +143,6 @@ type LangfuseTraceAttributes = {
157
143
  * // Function accepting any observation type
158
144
  * function logObservation(obs: LangfuseObservation) {
159
145
  * console.log(`Observation ${obs.id} in trace ${obs.traceId}`);
160
- *
161
- * // All observations have common methods
162
- * obs.updateTrace({ tags: ['logged'] });
163
146
  * obs.end();
164
147
  * }
165
148
  *
@@ -209,7 +192,7 @@ type LangfuseObservationParams = {
209
192
  *
210
193
  * ## Common Methods
211
194
  * - `end()`: Marks the observation as complete with optional timestamp
212
- * - `updateTrace()`: Sets trace-level attributes like user ID, session ID, tags
195
+ * - `setTraceIO()`: Sets trace-level input/output (deprecated, for legacy platform features)
213
196
  * - `startObservation()`: Creates child observations with inherited context
214
197
  *
215
198
  * @example
@@ -222,13 +205,6 @@ type LangfuseObservationParams = {
222
205
  * console.log(`Trace ID: ${observation.traceId}`);
223
206
  * console.log(`Type: ${observation.type}`);
224
207
  *
225
- * // Common methods available on all observations
226
- * observation.updateTrace({
227
- * userId: 'user-123',
228
- * sessionId: 'session-456',
229
- * tags: ['production', 'api-v2']
230
- * });
231
- *
232
208
  * // Create child observations
233
209
  * const child = observation.startObservation('child-operation', {
234
210
  * input: { step: 'processing' }
@@ -261,9 +237,45 @@ declare abstract class LangfuseBaseObservation {
261
237
  end(endTime?: TimeInput): void;
262
238
  updateOtelSpanAttributes(attributes: LangfuseObservationAttributes): void;
263
239
  /**
264
- * Updates the parent trace with new attributes.
240
+ * Set trace-level input and output for the trace this observation belongs to.
241
+ *
242
+ * @deprecated This is a legacy method for backward compatibility with Langfuse platform
243
+ * features that still rely on trace-level input/output (e.g., legacy LLM-as-a-judge
244
+ * evaluators). It will be removed in a future major version.
245
+ *
246
+ * For setting other trace attributes (userId, sessionId, metadata, tags, version),
247
+ * use {@link propagateAttributes} instead.
248
+ *
249
+ * @param attributes - Input and output data to associate with the trace
250
+ * @returns The observation instance for method chaining
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * const span = startObservation('my-operation');
255
+ * span.setTraceIO({
256
+ * input: { query: 'user question' },
257
+ * output: { response: 'assistant answer' }
258
+ * });
259
+ * ```
260
+ */
261
+ setTraceIO(attributes: LangfuseTraceAttributes): this;
262
+ /**
263
+ * Make the trace this observation belongs to publicly accessible via its URL.
264
+ *
265
+ * When a trace is published, anyone with the trace link can view the full trace
266
+ * without needing to be logged in to Langfuse. This action cannot be undone
267
+ * programmatically - once any span in a trace is published, the entire trace
268
+ * becomes public.
269
+ *
270
+ * @returns The observation instance for method chaining
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * const span = startObservation('my-operation');
275
+ * span.setTraceAsPublic();
276
+ * ```
265
277
  */
266
- updateTrace(attributes: LangfuseTraceAttributes): this;
278
+ setTraceAsPublic(): this;
267
279
  /**
268
280
  * Creates a new child observation within this observation's context with full type safety.
269
281
  *
@@ -1358,32 +1370,20 @@ declare class LangfuseEvent extends LangfuseBaseObservation {
1358
1370
  }
1359
1371
 
1360
1372
  /**
1361
- * Creates OpenTelemetry attributes from Langfuse trace attributes.
1373
+ * Creates OpenTelemetry attributes from Langfuse trace IO attributes.
1362
1374
  *
1363
- * Converts user-friendly trace attributes into the internal OpenTelemetry
1375
+ * Converts trace input/output into the internal OpenTelemetry
1364
1376
  * attribute format required by the span processor.
1365
1377
  *
1366
- * @param attributes - Langfuse trace attributes to convert
1378
+ * @param attributes - Langfuse trace IO attributes to convert
1367
1379
  * @returns OpenTelemetry attributes object with non-null values
1368
1380
  *
1369
- * @example
1370
- * ```typescript
1371
- * import { createTraceAttributes } from '@langfuse/tracing';
1372
- *
1373
- * const otelAttributes = createTraceAttributes({
1374
- * name: 'user-checkout-flow',
1375
- * userId: 'user-123',
1376
- * sessionId: 'session-456',
1377
- * tags: ['checkout', 'payment'],
1378
- * metadata: { version: '2.1.0' }
1379
- * });
1380
- *
1381
- * span.setAttributes(otelAttributes);
1382
- * ```
1381
+ * @deprecated This is for backward compatibility with legacy platform features
1382
+ * that still rely on trace-level input/output. Use propagateAttributes for other trace attributes.
1383
1383
  *
1384
- * @public
1384
+ * @internal
1385
1385
  */
1386
- declare function createTraceAttributes({ name, userId, sessionId, version, release, input, output, metadata, tags, environment, public: isPublic, }?: LangfuseTraceAttributes): Attributes;
1386
+ declare function createTraceAttributes({ input, output, }?: LangfuseTraceAttributes): Attributes;
1387
1387
  declare function createObservationAttributes(type: LangfuseObservationType, attributes: LangfuseObservationAttributes): Attributes;
1388
1388
 
1389
1389
  /**
@@ -1568,30 +1568,57 @@ declare function startActiveObservation<F extends (span: LangfuseSpan) => unknow
1568
1568
  asType?: "span";
1569
1569
  }): ReturnType<F>;
1570
1570
  /**
1571
- * Updates the currently active trace with new attributes.
1571
+ * Set trace-level input and output for the currently active trace.
1572
+ *
1573
+ * This function finds the currently active OpenTelemetry span and sets
1574
+ * trace-level input/output on it. If no active span is found, a warning is logged.
1572
1575
  *
1573
- * This function finds the currently active OpenTelemetry span and updates
1574
- * it with trace-level attributes. If no active span is found, a warning is logged.
1576
+ * @deprecated This is a legacy function for backward compatibility with Langfuse platform
1577
+ * features that still rely on trace-level input/output (e.g., legacy LLM-as-a-judge
1578
+ * evaluators). It will be removed in a future major version.
1575
1579
  *
1576
- * @param attributes - Trace attributes to set
1580
+ * For setting other trace attributes (userId, sessionId, metadata, tags, version),
1581
+ * use {@link propagateAttributes} instead.
1582
+ *
1583
+ * @param attributes - Input and output data to associate with the trace
1577
1584
  *
1578
1585
  * @example
1579
1586
  * ```typescript
1580
- * import { updateActiveTrace } from '@langfuse/tracing';
1587
+ * import { setActiveTraceIO } from '@langfuse/tracing';
1581
1588
  *
1582
1589
  * // Inside an active span context
1583
- * updateActiveTrace({
1584
- * name: 'user-workflow',
1585
- * userId: '123',
1586
- * sessionId: 'session-456',
1587
- * tags: ['production', 'critical'],
1588
- * public: true
1590
+ * setActiveTraceIO({
1591
+ * input: { query: 'user question' },
1592
+ * output: { response: 'assistant answer' }
1593
+ * });
1594
+ * ```
1595
+ *
1596
+ * @public
1597
+ */
1598
+ declare function setActiveTraceIO(attributes: LangfuseTraceAttributes): void;
1599
+ /**
1600
+ * Make the trace of the currently active span publicly accessible via its URL.
1601
+ *
1602
+ * When a trace is published, anyone with the trace link can view the full trace
1603
+ * without needing to be logged in to Langfuse. This action cannot be undone
1604
+ * programmatically - once any span in a trace is published, the entire trace
1605
+ * becomes public.
1606
+ *
1607
+ * If called outside of an active span context, the operation is skipped with a warning.
1608
+ *
1609
+ * @example
1610
+ * ```typescript
1611
+ * import { setActiveTraceAsPublic, startActiveObservation } from '@langfuse/tracing';
1612
+ *
1613
+ * startActiveObservation('my-operation', () => {
1614
+ * // Make this trace publicly accessible
1615
+ * setActiveTraceAsPublic();
1589
1616
  * });
1590
1617
  * ```
1591
1618
  *
1592
1619
  * @public
1593
1620
  */
1594
- declare function updateActiveTrace(attributes: LangfuseTraceAttributes): void;
1621
+ declare function setActiveTraceAsPublic(): void;
1595
1622
  /**
1596
1623
  * Updates the currently active observation with new attributes.
1597
1624
  *
@@ -1719,7 +1746,7 @@ declare function updateActiveTrace(attributes: LangfuseTraceAttributes): void;
1719
1746
  * ```
1720
1747
  *
1721
1748
  * @see {@link startActiveObservation} - For creating active observation contexts
1722
- * @see {@link updateActiveTrace} - For updating trace-level attributes
1749
+ * @see {@link setActiveTraceIO} - For setting trace-level input/output (deprecated)
1723
1750
  *
1724
1751
  * @public
1725
1752
  */
@@ -2087,4 +2114,4 @@ declare function getActiveTraceId(): string | undefined;
2087
2114
  */
2088
2115
  declare function getActiveSpanId(): string | undefined;
2089
2116
 
2090
- export { LangfuseAgent, LangfuseChain, LangfuseEmbedding, LangfuseEvaluator, LangfuseEvent, type LangfuseEventAttributes, LangfuseGeneration, type LangfuseGenerationAttributes, LangfuseGuardrail, type LangfuseObservation, type LangfuseObservationAttributes, type LangfuseObservationType, LangfuseRetriever, LangfuseSpan, type LangfuseSpanAttributes, LangfuseTool, type LangfuseTraceAttributes, type ObservationLevel, type ObserveOptions, type StartActiveObservationContext, type StartActiveObservationOpts, type StartObservationOptions, type StartObservationOpts, createObservationAttributes, createTraceAttributes, createTraceId, getActiveSpanId, getActiveTraceId, getLangfuseTracer, getLangfuseTracerProvider, observe, setLangfuseTracerProvider, startActiveObservation, startObservation, updateActiveObservation, updateActiveTrace };
2117
+ export { LangfuseAgent, LangfuseChain, LangfuseEmbedding, LangfuseEvaluator, LangfuseEvent, type LangfuseEventAttributes, LangfuseGeneration, type LangfuseGenerationAttributes, LangfuseGuardrail, type LangfuseObservation, type LangfuseObservationAttributes, type LangfuseObservationType, LangfuseRetriever, LangfuseSpan, type LangfuseSpanAttributes, LangfuseTool, type LangfuseTraceAttributes, type ObservationLevel, type ObserveOptions, type StartActiveObservationContext, type StartActiveObservationOpts, type StartObservationOptions, type StartObservationOpts, createObservationAttributes, createTraceAttributes, createTraceId, getActiveSpanId, getActiveTraceId, getLangfuseTracer, getLangfuseTracerProvider, observe, setActiveTraceAsPublic, setActiveTraceIO, setLangfuseTracerProvider, startActiveObservation, startObservation, updateActiveObservation };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import { getGlobalLogger as getGlobalLogger2, LangfuseOtelSpanAttributes as LangfuseOtelSpanAttributes2 } from "@langfuse/core";
2
+ import { getGlobalLogger as getGlobalLogger2, LangfuseOtelSpanAttributes as LangfuseOtelSpanAttributes3 } from "@langfuse/core";
3
3
  import {
4
4
  trace as trace2,
5
5
  context,
@@ -9,30 +9,12 @@ import {
9
9
  // src/attributes.ts
10
10
  import { LangfuseOtelSpanAttributes } from "@langfuse/core";
11
11
  function createTraceAttributes({
12
- name,
13
- userId,
14
- sessionId,
15
- version,
16
- release,
17
12
  input,
18
- output,
19
- metadata,
20
- tags,
21
- environment,
22
- public: isPublic
13
+ output
23
14
  } = {}) {
24
15
  const attributes = {
25
- [LangfuseOtelSpanAttributes.TRACE_NAME]: name,
26
- [LangfuseOtelSpanAttributes.TRACE_USER_ID]: userId,
27
- [LangfuseOtelSpanAttributes.TRACE_SESSION_ID]: sessionId,
28
- [LangfuseOtelSpanAttributes.VERSION]: version,
29
- [LangfuseOtelSpanAttributes.RELEASE]: release,
30
16
  [LangfuseOtelSpanAttributes.TRACE_INPUT]: _serialize(input),
31
- [LangfuseOtelSpanAttributes.TRACE_OUTPUT]: _serialize(output),
32
- [LangfuseOtelSpanAttributes.TRACE_TAGS]: tags,
33
- [LangfuseOtelSpanAttributes.ENVIRONMENT]: environment,
34
- [LangfuseOtelSpanAttributes.TRACE_PUBLIC]: isPublic,
35
- ..._flattenAndSerializeMetadata(metadata, "trace")
17
+ [LangfuseOtelSpanAttributes.TRACE_OUTPUT]: _serialize(output)
36
18
  };
37
19
  return Object.fromEntries(
38
20
  Object.entries(attributes).filter(([_, v]) => v != null)
@@ -105,6 +87,9 @@ function _flattenAndSerializeMetadata(metadata, type) {
105
87
  return metadataAttributes;
106
88
  }
107
89
 
90
+ // src/spanWrapper.ts
91
+ import { LangfuseOtelSpanAttributes as LangfuseOtelSpanAttributes2 } from "@langfuse/core";
92
+
108
93
  // src/tracerProvider.ts
109
94
  import {
110
95
  getGlobalLogger,
@@ -193,12 +178,53 @@ var LangfuseBaseObservation = class {
193
178
  );
194
179
  }
195
180
  /**
196
- * Updates the parent trace with new attributes.
181
+ * Set trace-level input and output for the trace this observation belongs to.
182
+ *
183
+ * @deprecated This is a legacy method for backward compatibility with Langfuse platform
184
+ * features that still rely on trace-level input/output (e.g., legacy LLM-as-a-judge
185
+ * evaluators). It will be removed in a future major version.
186
+ *
187
+ * For setting other trace attributes (userId, sessionId, metadata, tags, version),
188
+ * use {@link propagateAttributes} instead.
189
+ *
190
+ * @param attributes - Input and output data to associate with the trace
191
+ * @returns The observation instance for method chaining
192
+ *
193
+ * @example
194
+ * ```typescript
195
+ * const span = startObservation('my-operation');
196
+ * span.setTraceIO({
197
+ * input: { query: 'user question' },
198
+ * output: { response: 'assistant answer' }
199
+ * });
200
+ * ```
197
201
  */
198
- updateTrace(attributes) {
202
+ setTraceIO(attributes) {
199
203
  this.otelSpan.setAttributes(createTraceAttributes(attributes));
200
204
  return this;
201
205
  }
206
+ /**
207
+ * Make the trace this observation belongs to publicly accessible via its URL.
208
+ *
209
+ * When a trace is published, anyone with the trace link can view the full trace
210
+ * without needing to be logged in to Langfuse. This action cannot be undone
211
+ * programmatically - once any span in a trace is published, the entire trace
212
+ * becomes public.
213
+ *
214
+ * @returns The observation instance for method chaining
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * const span = startObservation('my-operation');
219
+ * span.setTraceAsPublic();
220
+ * ```
221
+ */
222
+ setTraceAsPublic() {
223
+ this.otelSpan.setAttributes({
224
+ [LangfuseOtelSpanAttributes2.TRACE_PUBLIC]: true
225
+ });
226
+ return this;
227
+ }
202
228
  startObservation(name, attributes, options) {
203
229
  const { asType = "span" } = options || {};
204
230
  return startObservation(name, attributes, {
@@ -408,7 +434,7 @@ var LangfuseEvent = class extends LangfuseBaseObservation {
408
434
  import {
409
435
  propagateAttributes
410
436
  } from "@langfuse/core";
411
- import { LangfuseOtelSpanAttributes as LangfuseOtelSpanAttributes3 } from "@langfuse/core";
437
+ import { LangfuseOtelSpanAttributes as LangfuseOtelSpanAttributes4 } from "@langfuse/core";
412
438
  function createOtelSpan(params) {
413
439
  return getLangfuseTracer().startSpan(
414
440
  params.name,
@@ -596,16 +622,28 @@ function startActiveObservation(name, fn, options) {
596
622
  }
597
623
  );
598
624
  }
599
- function updateActiveTrace(attributes) {
625
+ function setActiveTraceIO(attributes) {
600
626
  const span = trace2.getActiveSpan();
601
627
  if (!span) {
602
628
  getGlobalLogger2().warn(
603
- "No active OTEL span in context. Skipping trace update."
629
+ "No active OTEL span in context. Skipping trace IO update."
604
630
  );
605
631
  return;
606
632
  }
607
633
  span.setAttributes(createTraceAttributes(attributes));
608
634
  }
635
+ function setActiveTraceAsPublic() {
636
+ const span = trace2.getActiveSpan();
637
+ if (!span) {
638
+ getGlobalLogger2().warn(
639
+ "No active OTEL span in context. Skipping trace publish."
640
+ );
641
+ return;
642
+ }
643
+ span.setAttributes({
644
+ [LangfuseOtelSpanAttributes3.TRACE_PUBLIC]: true
645
+ });
646
+ }
609
647
  function updateActiveObservation(attributes, options) {
610
648
  var _a;
611
649
  const span = trace2.getActiveSpan();
@@ -620,7 +658,7 @@ function updateActiveObservation(attributes, options) {
620
658
  attributes
621
659
  );
622
660
  if (!(options == null ? void 0 : options.asType)) {
623
- otelAttributes[LangfuseOtelSpanAttributes2.OBSERVATION_TYPE] = void 0;
661
+ otelAttributes[LangfuseOtelSpanAttributes3.OBSERVATION_TYPE] = void 0;
624
662
  }
625
663
  span.setAttributes(otelAttributes);
626
664
  }
@@ -739,7 +777,7 @@ export {
739
777
  LangfuseEvent,
740
778
  LangfuseGeneration,
741
779
  LangfuseGuardrail,
742
- LangfuseOtelSpanAttributes3 as LangfuseOtelSpanAttributes,
780
+ LangfuseOtelSpanAttributes4 as LangfuseOtelSpanAttributes,
743
781
  LangfuseRetriever,
744
782
  LangfuseSpan,
745
783
  LangfuseTool,
@@ -752,10 +790,11 @@ export {
752
790
  getLangfuseTracerProvider,
753
791
  observe,
754
792
  propagateAttributes,
793
+ setActiveTraceAsPublic,
794
+ setActiveTraceIO,
755
795
  setLangfuseTracerProvider,
756
796
  startActiveObservation,
757
797
  startObservation,
758
- updateActiveObservation,
759
- updateActiveTrace
798
+ updateActiveObservation
760
799
  };
761
800
  //# sourceMappingURL=index.mjs.map