Skip to content

Commit 16feb0f

Browse files
chore(closes OPEN-9632): langChain callback handler adding latency
1 parent 8e82464 commit 16feb0f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/openlayer/lib/integrations/langchain_callback.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ def _end_step(
189189
and tracer.get_current_step() is None
190190
):
191191
trace = self._traces_by_root.pop(run_id)
192-
self._process_and_upload_trace(trace)
192+
if tracer._configured_background_publish_enabled:
193+
tracer._get_background_executor().submit(
194+
self._process_and_upload_trace, trace
195+
)
196+
else:
197+
self._process_and_upload_trace(trace)
193198

194199
def _process_and_upload_trace(self, trace: traces.Trace) -> None:
195200
"""Process and upload the completed trace (only for standalone root steps)."""
@@ -1241,7 +1246,12 @@ def _end_step(
12411246
# Only upload if: root step + has standalone trace + not part of external trace
12421247
if is_root_step and has_standalone_trace and not self._has_external_trace:
12431248
trace = self._traces_by_root.pop(run_id)
1244-
self._process_and_upload_async_trace(trace)
1249+
if tracer._configured_background_publish_enabled:
1250+
tracer._get_background_executor().submit(
1251+
self._process_and_upload_async_trace, trace
1252+
)
1253+
else:
1254+
self._process_and_upload_async_trace(trace)
12451255

12461256
def _process_and_upload_async_trace(self, trace: traces.Trace) -> None:
12471257
"""Process and upload trace for async handler."""

0 commit comments

Comments
 (0)