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
This commit is contained in:
Rogério Chaves 2024-12-30 18:59:01 +01:00 committed by GitHub
commit 2ce33d41a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 3201 deletions

View file

@ -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

File diff suppressed because it is too large Load diff