Skip to content

Commit 8063f84

Browse files
feat(tracing)!: remove trace-level input/output setters (#1935)
Remove the deprecated Langfuse.set_current_trace_io() and span.set_trace_io(), the langfuse.trace.input/output attributes, and their media handling. On Langfuse v4 a trace's input and output come from its root observation: set them with update() on the root span or update_current_span(). Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
1 parent b406eb2 commit 8063f84

8 files changed

Lines changed: 16 additions & 126 deletions

File tree

‎langfuse/_client/attributes.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class LangfuseOtelSpanAttributes:
3232
TRACE_TAGS = "langfuse.trace.tags"
3333
TRACE_PUBLIC = "langfuse.trace.public"
3434
TRACE_METADATA = "langfuse.trace.metadata"
35-
TRACE_INPUT = "langfuse.trace.input"
36-
TRACE_OUTPUT = "langfuse.trace.output"
3735

3836
# Langfuse-observation attributes
3937
OBSERVATION_TYPE = "langfuse.observation.type"
@@ -76,13 +74,9 @@ class LangfuseOtelSpanAttributes:
7674

7775
def create_trace_attributes(
7876
*,
79-
input: Optional[Any] = None,
80-
output: Optional[Any] = None,
8177
public: Optional[bool] = None,
8278
) -> dict:
8379
attributes = {
84-
LangfuseOtelSpanAttributes.TRACE_INPUT: _serialize(input),
85-
LangfuseOtelSpanAttributes.TRACE_OUTPUT: _serialize(output),
8680
LangfuseOtelSpanAttributes.TRACE_PUBLIC: public,
8781
}
8882

‎langfuse/_client/client.py‎

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
_agnosticcontextmanager,
3939
)
4040
from packaging.version import Version
41-
from typing_extensions import deprecated
4241

4342
from langfuse._client.attributes import (
4443
LangfuseOtelSpanAttributes,
@@ -213,7 +212,7 @@ class Langfuse:
213212
release (Optional[str]): Release version/hash of your application. Used for grouping analytics by release.
214213
media_upload_thread_count (Optional[int]): Number of background threads for handling media uploads. Defaults to 1. Can also be set via LANGFUSE_MEDIA_UPLOAD_THREAD_COUNT environment variable.
215214
sample_rate (Optional[float]): Sampling rate for traces (0.0 to 1.0). Defaults to 1.0 (100% of traces are sampled). Can also be set via LANGFUSE_SAMPLE_RATE environment variable.
216-
mask (Optional[MaskFunction]): Function to mask sensitive data synchronously when Langfuse SDK attributes are created. This applies only to data set through Langfuse SDK APIs such as `start_observation()`, `update()`, and `set_trace_io()`.
215+
mask (Optional[MaskFunction]): Function to mask sensitive data synchronously when Langfuse SDK attributes are created. This applies only to data set through Langfuse SDK APIs such as `start_observation()` and `update()`.
217216
mask_otel_spans (Optional[MaskOtelSpansFunction]): Synchronous export-stage hook for masking raw OpenTelemetry span attributes before this Langfuse client sends them to Langfuse. Use this for spans created by third-party OpenTelemetry instrumentations, or when you need to inspect final span attributes after export filtering and Langfuse media handling. It does not modify spans already exported through other OpenTelemetry exporters.
218217
219218
The hook receives one OpenTelemetry export batch. A batch is not guaranteed to contain a complete trace, request, or Langfuse observation tree. The hook usually runs on the OpenTelemetry batch span processor worker thread; during `flush()` and shutdown it may run on the caller thread. Keep it synchronous, deterministic, and fast.
@@ -1534,55 +1533,6 @@ def update_current_span(
15341533
status_message=status_message,
15351534
)
15361535

1537-
@deprecated(
1538-
"Trace-level input/output is deprecated. "
1539-
"For trace attributes (user_id, session_id, tags, etc.), use propagate_attributes() instead. "
1540-
"This method will be removed in a future major version."
1541-
)
1542-
def set_current_trace_io(
1543-
self,
1544-
*,
1545-
input: Optional[Any] = None,
1546-
output: Optional[Any] = None,
1547-
) -> None:
1548-
"""Set trace-level input and output for the current span's trace.
1549-
1550-
.. deprecated::
1551-
This is a legacy method for backward compatibility with Langfuse platform
1552-
features that still rely on trace-level input/output (e.g., legacy LLM-as-a-judge
1553-
evaluators). It will be removed in a future major version.
1554-
1555-
For setting other trace attributes (user_id, session_id, metadata, tags, version),
1556-
use :func:`langfuse.propagate_attributes` (top-level import) instead.
1557-
1558-
Args:
1559-
input: Input data to associate with the trace.
1560-
output: Output data to associate with the trace.
1561-
"""
1562-
if not self._tracing_enabled:
1563-
langfuse_logger.debug(
1564-
"Operation skipped: set_current_trace_io - Tracing is disabled or client is in no-op mode."
1565-
)
1566-
return
1567-
1568-
current_otel_span = self._get_current_otel_span()
1569-
1570-
if current_otel_span is not None and current_otel_span.is_recording():
1571-
span_class = self._get_span_class(
1572-
self._get_observation_type_from_otel_span(current_otel_span)
1573-
)
1574-
span = span_class(
1575-
otel_span=current_otel_span,
1576-
langfuse_client=self,
1577-
environment=self._environment,
1578-
release=self._release,
1579-
)
1580-
1581-
span.set_trace_io(
1582-
input=input,
1583-
output=output,
1584-
)
1585-
15861536
def set_current_trace_as_public(self) -> None:
15871537
"""Make the current trace publicly accessible via its URL.
15881538

‎langfuse/_client/span.py‎

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
if TYPE_CHECKING:
3737
from langfuse._client.client import Langfuse
3838

39-
from typing_extensions import deprecated
4039

4140
from langfuse._client.attributes import (
4241
LangfuseOtelSpanAttributes,
@@ -226,53 +225,6 @@ def end(self, *, end_time: Optional[int] = None) -> "LangfuseObservationWrapper"
226225

227226
return self
228227

229-
@deprecated(
230-
"Trace-level input/output is deprecated. "
231-
"For trace attributes (user_id, session_id, tags, etc.), use propagate_attributes() instead. "
232-
"This method will be removed in a future major version."
233-
)
234-
def set_trace_io(
235-
self,
236-
*,
237-
input: Optional[Any] = None,
238-
output: Optional[Any] = None,
239-
) -> "LangfuseObservationWrapper":
240-
"""Set trace-level input and output for the trace this span belongs to.
241-
242-
.. deprecated::
243-
This is a legacy method for backward compatibility with Langfuse platform
244-
features that still rely on trace-level input/output (e.g., legacy LLM-as-a-judge
245-
evaluators). It will be removed in a future major version.
246-
247-
For setting other trace attributes (user_id, session_id, metadata, tags, version),
248-
use :func:`langfuse.propagate_attributes` (top-level import) instead.
249-
250-
Args:
251-
input: Input data to associate with the trace.
252-
output: Output data to associate with the trace.
253-
254-
Returns:
255-
The span instance for method chaining.
256-
"""
257-
if not self._otel_span.is_recording():
258-
return self
259-
260-
media_processed_input = self._process_media_and_apply_mask(
261-
data=input, field="input", span=self._otel_span
262-
)
263-
media_processed_output = self._process_media_and_apply_mask(
264-
data=output, field="output", span=self._otel_span
265-
)
266-
267-
attributes = create_trace_attributes(
268-
input=media_processed_input,
269-
output=media_processed_output,
270-
)
271-
272-
self._otel_span.set_attributes(attributes)
273-
274-
return self
275-
276228
def set_trace_as_public(self) -> "LangfuseObservationWrapper":
277229
"""Make this trace publicly accessible via its URL.
278230

‎langfuse/_client/span_exporter.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
_INPUT_MEDIA_ATTRIBUTE_KEYS = frozenset(
2929
{
30-
LangfuseOtelSpanAttributes.TRACE_INPUT,
3130
LangfuseOtelSpanAttributes.OBSERVATION_INPUT,
3231
"ai.prompt.messages",
3332
"ai.prompt",
@@ -54,7 +53,6 @@
5453

5554
_OUTPUT_MEDIA_ATTRIBUTE_KEYS = frozenset(
5655
{
57-
LangfuseOtelSpanAttributes.TRACE_OUTPUT,
5856
LangfuseOtelSpanAttributes.OBSERVATION_OUTPUT,
5957
"ai.response.text",
6058
"ai.result.text",

‎tests/e2e/test_core_sdk.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -549,14 +549,14 @@ def test_create_update_current_trace():
549549

550550
trace_name = create_uuid()
551551

552-
# Create initial span with trace properties using propagate_attributes and set_current_trace_io
552+
# Create initial span with trace properties using propagate_attributes
553553
with langfuse.start_as_current_observation(name="test-span-current") as span:
554554
with propagate_attributes(
555555
trace_name=trace_name,
556556
user_id="test",
557557
metadata={"key": "value"},
558558
):
559-
langfuse.set_current_trace_io(input="test_input")
559+
langfuse.update_current_span(input="test_input")
560560
langfuse.set_current_trace_as_public()
561561
# Get trace ID for later reference
562562
trace_id = span.trace_id
@@ -989,7 +989,7 @@ def test_create_trace_and_generation():
989989
# Create parent span and set trace properties
990990
with langfuse.start_as_current_observation(name=trace_name) as parent_span:
991991
with propagate_attributes(trace_name=trace_name, session_id="test-session-id"):
992-
parent_span.set_trace_io(input={"key": "value"})
992+
parent_span.update(input={"key": "value"})
993993

994994
# Create a generation as child
995995
generation = parent_span.start_observation(
@@ -1812,23 +1812,23 @@ def test_fetch_traces():
18121812
# First trace
18131813
with langfuse.start_as_current_observation(name="test1") as span:
18141814
with propagate_attributes(trace_name=name, session_id="session-1"):
1815-
span.set_trace_io(input={"key": "value"}, output="output-value")
1815+
span.update(input={"key": "value"}, output="output-value")
18161816
trace_ids.append(span.trace_id)
18171817

18181818
sleep(1) # Ensure traces have different timestamps
18191819

18201820
# Second trace
18211821
with langfuse.start_as_current_observation(name="test2") as span:
18221822
with propagate_attributes(trace_name=name, session_id="session-1"):
1823-
span.set_trace_io(input={"key": "value"}, output="output-value")
1823+
span.update(input={"key": "value"}, output="output-value")
18241824
trace_ids.append(span.trace_id)
18251825

18261826
sleep(1) # Ensure traces have different timestamps
18271827

18281828
# Third trace
18291829
with langfuse.start_as_current_observation(name="test3") as span:
18301830
with propagate_attributes(trace_name=name, session_id="session-1"):
1831-
span.set_trace_io(input={"key": "value"}, output="output-value")
1831+
span.update(input={"key": "value"}, output="output-value")
18321832
trace_ids.append(span.trace_id)
18331833

18341834
# Ensure data is sent
@@ -2088,11 +2088,11 @@ def mask_func(data):
20882088
# Create a root span with trace properties
20892089
with langfuse.start_as_current_observation(name="test-span") as root_span:
20902090
with propagate_attributes(trace_name="test_trace"):
2091-
root_span.set_trace_io(input={"sensitive": "data"})
2091+
root_span.update(input={"sensitive": "data"})
20922092
# Get trace ID for later use
20932093
trace_id = root_span.trace_id
20942094
# Add output to the trace
2095-
root_span.set_trace_io(output={"more": "sensitive"})
2095+
root_span.update(output={"more": "sensitive"})
20962096

20972097
# Create a generation as child
20982098
gen = root_span.start_observation(
@@ -2136,11 +2136,11 @@ def mask_func(data):
21362136
# Create a root span with trace properties
21372137
with langfuse.start_as_current_observation(name="test-span") as root_span:
21382138
with propagate_attributes(trace_name="test_trace"):
2139-
root_span.set_trace_io(input={"should_raise": "data"})
2139+
root_span.update(input={"should_raise": "data"})
21402140
# Get trace ID for later use
21412141
trace_id = root_span.trace_id
21422142
# Add output to the trace
2143-
root_span.set_trace_io(output={"should_raise": "sensitive"})
2143+
root_span.update(output={"should_raise": "sensitive"})
21442144

21452145
# Ensure data is sent
21462146
langfuse.flush()

‎tests/e2e/test_decorators.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,10 +1071,10 @@ def test_media():
10711071

10721072
media = LangfuseMedia(content_bytes=pdf_bytes, content_type="application/pdf")
10731073

1074-
@observe()
1074+
@observe(capture_input=False, capture_output=False)
10751075
def main():
10761076
sleep(1)
1077-
langfuse.set_current_trace_io(
1077+
langfuse.update_current_span(
10781078
input={
10791079
"context": {
10801080
"nested": media,

‎tests/unit/test_mask_otel_spans.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ def test_export_stage_media_processes_string_sequence_attributes():
293293
@pytest.mark.parametrize(
294294
("attribute_key", "expected_field"),
295295
[
296-
("langfuse.trace.input", "input"),
297296
("langfuse.observation.input", "input"),
298297
("ai.prompt.messages", "input"),
299298
("gcp.vertex.agent.tool_call_args", "input"),
@@ -302,7 +301,6 @@ def test_export_stage_media_processes_string_sequence_attributes():
302301
("gen_ai.input.messages", "input"),
303302
("gen_ai.prompt.0.content", "input"),
304303
("llm.input_messages.0.message.content", "input"),
305-
("langfuse.trace.output", "output"),
306304
("langfuse.observation.output", "output"),
307305
("ai.response.toolCalls", "output"),
308306
("gcp.vertex.agent.tool_response", "output"),

‎tests/unit/test_otel.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,16 +498,16 @@ def test_generation_name_update(self, langfuse_client, memory_exporter):
498498

499499
def test_trace_update(self, langfuse_client, memory_exporter):
500500
"""Test updating trace level attributes."""
501-
# Create a span and set trace attributes using propagate_attributes and set_trace_io
502-
with langfuse_client.start_as_current_observation(name="trace-span") as span:
501+
# Create a span and set trace attributes using propagate_attributes
502+
with langfuse_client.start_as_current_observation(name="trace-span"):
503503
with propagate_attributes(
504504
trace_name="updated-trace-name",
505505
user_id="test-user",
506506
session_id="test-session",
507507
tags=["tag1", "tag2"],
508508
metadata={"trace-meta": "data"},
509509
):
510-
span.set_trace_io(input={"trace-input": "value"})
510+
pass
511511

512512
# Get the span data
513513
spans = self.get_spans_by_name(memory_exporter, "trace-span")
@@ -526,12 +526,10 @@ def test_trace_update(self, langfuse_client, memory_exporter):
526526
else:
527527
tags = list(attributes[LangfuseOtelSpanAttributes.TRACE_TAGS])
528528

529-
input_data = json.loads(attributes[LangfuseOtelSpanAttributes.TRACE_INPUT])
530529
metadata = attributes[f"{LangfuseOtelSpanAttributes.TRACE_METADATA}.trace-meta"]
531530

532531
# Check attribute values
533532
assert sorted(tags) == sorted(["tag1", "tag2"])
534-
assert input_data == {"trace-input": "value"}
535533
assert metadata == "data"
536534

537535
def test_complex_scenario(self, langfuse_client, memory_exporter):

0 commit comments

Comments
 (0)