1
1
import json
2
2
import logging
3
3
import os
4
+ from contextlib import suppress
4
5
from typing import Any , Dict , List , Optional , Tuple , Union
5
6
6
7
from langchain_core .callbacks .base import BaseCallbackHandler
10
11
from langgraph .checkpoint .sqlite .aio import AsyncSqliteSaver
11
12
from langgraph .errors import EmptyInputError , GraphRecursionError , InvalidUpdateError
12
13
from langgraph .graph .state import CompiledStateGraph
14
+ from openinference .instrumentation .langchain import LangChainInstrumentor
15
+ from opentelemetry import trace
16
+ from opentelemetry .sdk .trace import TracerProvider
17
+ from opentelemetry .sdk .trace .export import BatchSpanProcessor
13
18
from uipath ._cli ._runtime ._contracts import (
14
19
UiPathBaseRuntime ,
15
20
UiPathErrorCategory ,
16
21
UiPathRuntimeResult ,
17
22
)
18
23
19
24
from ..._utils import _instrument_traceable_attributes
20
- from ...tracers import AsyncUiPathTracer
21
- from .._utils ._graph import LangGraphConfig
25
+ from ...tracers import (
26
+ AsyncUiPathTracer ,
27
+ JsonFileExporter ,
28
+ LangchainExporter ,
29
+ SqliteExporter ,
30
+ )
31
+ from ...tracers .LangchainSpanProcessor import LangchainSpanProcessor
22
32
from ._context import LangGraphRuntimeContext
23
33
from ._conversation import map_message
24
34
from ._exception import LangGraphRuntimeError
@@ -50,6 +60,27 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
50
60
"""
51
61
_instrument_traceable_attributes ()
52
62
63
+ with suppress (Exception ):
64
+ provider = TracerProvider ()
65
+ trace .set_tracer_provider (provider )
66
+ provider .add_span_processor (BatchSpanProcessor (LangchainExporter ())) # type: ignore
67
+
68
+ provider .add_span_processor (
69
+ BatchSpanProcessor (
70
+ JsonFileExporter (".uipath/traces.jsonl" , LangchainSpanProcessor ())
71
+ )
72
+ )
73
+
74
+ provider .add_span_processor (
75
+ BatchSpanProcessor (
76
+ SqliteExporter (".uipath/traces.db" , LangchainSpanProcessor ())
77
+ )
78
+ )
79
+
80
+ LangChainInstrumentor ().instrument (
81
+ tracer_provider = trace .get_tracer_provider ()
82
+ )
83
+
53
84
if self .context .state_graph is None :
54
85
return None
55
86
@@ -74,9 +105,9 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
74
105
# Set up tracing if available
75
106
callbacks : List [BaseCallbackHandler ] = []
76
107
77
- if self .context .job_id and self .context .tracing_enabled :
78
- tracer = AsyncUiPathTracer (context = self .context .trace_context )
79
- callbacks = [tracer ]
108
+ # if self.context.job_id and self.context.tracing_enabled:
109
+ # tracer = AsyncUiPathTracer(context=self.context.trace_context)
110
+ # callbacks = [tracer]
80
111
81
112
graph_config : RunnableConfig = {
82
113
"configurable" : {
0 commit comments