|
35 | 35 | _agnosticcontextmanager, |
36 | 36 | ) |
37 | 37 | from packaging.version import Version |
| 38 | +from typing_extensions import deprecated |
38 | 39 |
|
39 | 40 | from langfuse._client.attributes import LangfuseOtelSpanAttributes, _serialize |
40 | 41 | from langfuse._client.constants import ( |
@@ -1633,6 +1634,89 @@ def update_current_span( |
1633 | 1634 | status_message=status_message, |
1634 | 1635 | ) |
1635 | 1636 |
|
| 1637 | + @deprecated( |
| 1638 | + "Trace-level input/output is deprecated. " |
| 1639 | + "For trace attributes (user_id, session_id, tags, etc.), use propagate_attributes() instead. " |
| 1640 | + "This method will be removed in a future major version." |
| 1641 | + ) |
| 1642 | + def set_current_trace_io( |
| 1643 | + self, |
| 1644 | + *, |
| 1645 | + input: Optional[Any] = None, |
| 1646 | + output: Optional[Any] = None, |
| 1647 | + ) -> None: |
| 1648 | + """Set trace-level input and output for the current span's trace. |
| 1649 | +
|
| 1650 | + .. deprecated:: |
| 1651 | + This is a legacy method for backward compatibility with Langfuse platform |
| 1652 | + features that still rely on trace-level input/output (e.g., legacy LLM-as-a-judge |
| 1653 | + evaluators). It will be removed in a future major version. |
| 1654 | +
|
| 1655 | + For setting other trace attributes (user_id, session_id, metadata, tags, version), |
| 1656 | + use :meth:`propagate_attributes` instead. |
| 1657 | +
|
| 1658 | + Args: |
| 1659 | + input: Input data to associate with the trace. |
| 1660 | + output: Output data to associate with the trace. |
| 1661 | + """ |
| 1662 | + if not self._tracing_enabled: |
| 1663 | + langfuse_logger.debug( |
| 1664 | + "Operation skipped: set_current_trace_io - Tracing is disabled or client is in no-op mode." |
| 1665 | + ) |
| 1666 | + return |
| 1667 | + |
| 1668 | + current_otel_span = self._get_current_otel_span() |
| 1669 | + |
| 1670 | + if current_otel_span is not None and current_otel_span.is_recording(): |
| 1671 | + existing_observation_type = current_otel_span.attributes.get( # type: ignore[attr-defined] |
| 1672 | + LangfuseOtelSpanAttributes.OBSERVATION_TYPE, "span" |
| 1673 | + ) |
| 1674 | + # We need to preserve the class to keep the correct observation type |
| 1675 | + span_class = self._get_span_class(existing_observation_type) |
| 1676 | + span = span_class( |
| 1677 | + otel_span=current_otel_span, |
| 1678 | + langfuse_client=self, |
| 1679 | + environment=self._environment, |
| 1680 | + ) |
| 1681 | + |
| 1682 | + span.set_trace_io( |
| 1683 | + input=input, |
| 1684 | + output=output, |
| 1685 | + ) |
| 1686 | + |
| 1687 | + def publish_current_trace(self) -> None: |
| 1688 | + """Make the current trace publicly accessible via its URL. |
| 1689 | +
|
| 1690 | + When a trace is published, anyone with the trace link can view the full trace |
| 1691 | + without needing to be logged in to Langfuse. This action cannot be undone |
| 1692 | + programmatically - once published, the entire trace becomes public. |
| 1693 | +
|
| 1694 | + This is a convenience method that publishes the trace from the currently |
| 1695 | + active span context. Use this when you want to make a trace public from |
| 1696 | + within a traced function without needing direct access to the span object. |
| 1697 | + """ |
| 1698 | + if not self._tracing_enabled: |
| 1699 | + langfuse_logger.debug( |
| 1700 | + "Operation skipped: publish_current_trace - Tracing is disabled or client is in no-op mode." |
| 1701 | + ) |
| 1702 | + return |
| 1703 | + |
| 1704 | + current_otel_span = self._get_current_otel_span() |
| 1705 | + |
| 1706 | + if current_otel_span is not None and current_otel_span.is_recording(): |
| 1707 | + existing_observation_type = current_otel_span.attributes.get( # type: ignore[attr-defined] |
| 1708 | + LangfuseOtelSpanAttributes.OBSERVATION_TYPE, "span" |
| 1709 | + ) |
| 1710 | + # We need to preserve the class to keep the correct observation type |
| 1711 | + span_class = self._get_span_class(existing_observation_type) |
| 1712 | + span = span_class( |
| 1713 | + otel_span=current_otel_span, |
| 1714 | + langfuse_client=self, |
| 1715 | + environment=self._environment, |
| 1716 | + ) |
| 1717 | + |
| 1718 | + span.publish_trace() |
| 1719 | + |
1636 | 1720 | def create_event( |
1637 | 1721 | self, |
1638 | 1722 | *, |
|
0 commit comments