|
1 | 1 | import json |
2 | 2 | import logging |
3 | | -from typing import Any, Dict, List |
| 3 | +from typing import Any, Dict, List, Optional |
4 | 4 |
|
5 | | -from opentelemetry.sdk.trace.export import ( |
6 | | - SpanExportResult, |
7 | | -) |
| 5 | +from opentelemetry.sdk.trace.export import SpanExportResult |
8 | 6 | from uipath.tracing import LlmOpsHttpExporter |
9 | 7 |
|
10 | 8 | logger = logging.getLogger(__name__) |
@@ -71,6 +69,11 @@ class LangChainExporter(LlmOpsHttpExporter): |
71 | 69 | # Add more mappings as needed |
72 | 70 | } |
73 | 71 |
|
| 72 | + class Status: |
| 73 | + SUCCESS = 1 |
| 74 | + ERROR = 2 |
| 75 | + INTERRUPTED = 3 |
| 76 | + |
74 | 77 | def __init__(self, *args: Any, **kwargs: Any) -> None: |
75 | 78 | super().__init__(*args, **kwargs) |
76 | 79 |
|
@@ -161,13 +164,18 @@ def _map_tool_call_attributes(self, attributes: Dict[str, Any]) -> Dict[str, Any |
161 | 164 |
|
162 | 165 | return result |
163 | 166 |
|
| 167 | + def _determine_status(self, error: Optional[str]) -> int: |
| 168 | + if error: |
| 169 | + if error and error.startswith("GraphInterrupt("): |
| 170 | + return self.Status.INTERRUPTED |
| 171 | + return self.Status.ERROR |
| 172 | + return self.Status.SUCCESS |
| 173 | + |
164 | 174 | def _process_span_attributes(self, span_data: Dict[str, Any]) -> Dict[str, Any]: |
165 | 175 | """Extracts, transforms, and maps attributes for a span.""" |
166 | 176 | if "Attributes" not in span_data: |
167 | 177 | return span_data |
168 | 178 |
|
169 | | - logger.debug(f"Processing span: {span_data}") |
170 | | - |
171 | 179 | attributes_val = span_data["Attributes"] |
172 | 180 | if isinstance(attributes_val, str): |
173 | 181 | try: |
@@ -206,7 +214,11 @@ def _process_span_attributes(self, span_data: Dict[str, Any]) -> Dict[str, Any]: |
206 | 214 |
|
207 | 215 | span_data["Attributes"] = json.dumps(processed_attributes) |
208 | 216 |
|
209 | | - logger.debug(f"Transformed span: {span_data}") |
| 217 | + # Determine status based on error information |
| 218 | + error = attributes.get("error") or attributes.get("exception.message") |
| 219 | + status = self._determine_status(error) |
| 220 | + span_data["Status"] = status |
| 221 | + |
210 | 222 | return span_data |
211 | 223 |
|
212 | 224 | def _send_with_retries( |
|
0 commit comments