diff --git a/src/openlayer/lib/integrations/langchain_callback.py b/src/openlayer/lib/integrations/langchain_callback.py index 00060247..b33adb06 100644 --- a/src/openlayer/lib/integrations/langchain_callback.py +++ b/src/openlayer/lib/integrations/langchain_callback.py @@ -189,7 +189,12 @@ def _end_step( and tracer.get_current_step() is None ): trace = self._traces_by_root.pop(run_id) - self._process_and_upload_trace(trace) + if tracer._configured_background_publish_enabled: + tracer._get_background_executor().submit( + self._process_and_upload_trace, trace + ) + else: + self._process_and_upload_trace(trace) def _process_and_upload_trace(self, trace: traces.Trace) -> None: """Process and upload the completed trace (only for standalone root steps).""" @@ -1241,7 +1246,12 @@ def _end_step( # Only upload if: root step + has standalone trace + not part of external trace if is_root_step and has_standalone_trace and not self._has_external_trace: trace = self._traces_by_root.pop(run_id) - self._process_and_upload_async_trace(trace) + if tracer._configured_background_publish_enabled: + tracer._get_background_executor().submit( + self._process_and_upload_async_trace, trace + ) + else: + self._process_and_upload_async_trace(trace) def _process_and_upload_async_trace(self, trace: traces.Trace) -> None: """Process and upload trace for async handler."""