From 2ce33d41a82ff90daddeff21da8b0a5e5df779dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Chaves?= Date: Mon, 30 Dec 2024 18:59:01 +0100 Subject: [PATCH] fix(LangWatch): make current trace available for custom code to hook on to, allow to override input/output, fix icon (#5484) * Call __enter__ to make current langwatch trace available globally so users can more easily add more context to it, like final input and output. This means also skipping setting the root_span input and output if already set * Update LangWatch logo --- .../langflow/services/tracing/langwatch.py | 10 +- .../src/icons/Langwatch/langwatch.jsx | 3206 +---------------- 2 files changed, 15 insertions(+), 3201 deletions(-) diff --git a/src/backend/base/langflow/services/tracing/langwatch.py b/src/backend/base/langflow/services/tracing/langwatch.py index ac2bca054..1c8376c78 100644 --- a/src/backend/base/langflow/services/tracing/langwatch.py +++ b/src/backend/base/langflow/services/tracing/langwatch.py @@ -38,6 +38,7 @@ class LangWatchTracer(BaseTracer): self.trace = self._client.trace( trace_id=str(self.trace_id), ) + self.trace.__enter__() self.spans: dict[str, ContextSpan] = {} name_without_id = " - ".join(trace_name.split(" - ")[0:-1]) @@ -126,8 +127,8 @@ class LangWatchTracer(BaseTracer): if not self._ready: return self.trace.root_span.end( - input=self._convert_to_langwatch_types(inputs), - output=self._convert_to_langwatch_types(outputs), + input=self._convert_to_langwatch_types(inputs) if self.trace.root_span.input is None else None, + output=self._convert_to_langwatch_types(outputs) if self.trace.root_span.output is None else None, error=error, ) @@ -135,7 +136,10 @@ class LangWatchTracer(BaseTracer): self.trace.update(metadata=(self.trace.metadata or {}) | {"labels": [f"Flow: {metadata['flow_name']}"]}) if self.trace.api_key or self._client.api_key: - self.trace.deferred_send_spans() + try: + self.trace.__exit__(None, None, None) + except ValueError: # ignoring token was created in a different Context errors + return def _convert_to_langwatch_types(self, io_dict: dict[str, Any] | None): from langwatch.utils import autoconvert_typed_values diff --git a/src/frontend/src/icons/Langwatch/langwatch.jsx b/src/frontend/src/icons/Langwatch/langwatch.jsx index 1ac26f439..d2ab07d5a 100644 --- a/src/frontend/src/icons/Langwatch/langwatch.jsx +++ b/src/frontend/src/icons/Langwatch/langwatch.jsx @@ -7,3204 +7,14 @@ const SvgLangwatch = (props) => ( viewBox="0 0 38 52" {...props} > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + ); export default SvgLangwatch;