Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath-langchain"
version = "0.10.23"
version = "0.10.24"
description = "Python SDK that enables developers to build and deploy LangGraph agents to the UiPath Cloud Platform"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
8 changes: 7 additions & 1 deletion src/uipath_langchain/_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from ._environment import get_execution_folder_path
from ._otel import set_span_attribute
from ._otel import (
get_current_span_and_trace_ids,
set_current_span_error,
set_span_attribute,
)
from ._request_mixin import UiPathRequestMixin

__all__ = [
"UiPathRequestMixin",
"get_current_span_and_trace_ids",
"get_execution_folder_path",
"set_current_span_error",
"set_span_attribute",
]
28 changes: 28 additions & 0 deletions src/uipath_langchain/_utils/_otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
from typing import Any


def get_current_span_and_trace_ids() -> tuple[str, str]:
"""Return the current OTel span and trace IDs as hex strings."""
try:
from opentelemetry import trace

span = trace.get_current_span()
context = span.get_span_context()
if not context.is_valid:
return "", ""
return f"{context.span_id:016x}", f"{context.trace_id:032x}"
except ImportError:
return "", ""


def set_span_attribute(name: str, value: Any) -> None:
"""Set an attribute on the current OTel span (no-op if unavailable)."""
try:
Expand All @@ -13,3 +27,17 @@ def set_span_attribute(name: str, value: Any) -> None:
span.set_attribute(name, value)
except ImportError:
pass


def set_current_span_error(error: BaseException) -> None:
"""Record an exception and mark the current OTel span as errored."""
try:
from opentelemetry import trace
from opentelemetry.trace import StatusCode

span = trace.get_current_span()
if span.is_recording():
span.record_exception(error)
span.set_status(StatusCode.ERROR, str(error))
except ImportError:
pass
Loading
Loading