Skip to content

Commit

Permalink
Baggage Draft
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Apr 12, 2024
2 parents 4213a65 + 0308d11 commit c47e838
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions python/langsmith/run_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def tracing_context(
headers: Optional[Dict[str, str]] = None,
) -> Generator[None, None, None]:
"""Set the tracing context for a block of code."""
parent_run_ = get_tracing_context()
parent_run_ = get_current_span()
_PROJECT_NAME.set(project_name)
_TAGS.set(tags)
_METADATA.set(metadata)
Expand All @@ -96,7 +96,7 @@ def tracing_context(
_METADATA.set(None)
_PARENT_RUN_TREE.set(parent_run_)


# Alias for backwards compatibility
get_current_run_tree = get_current_span
get_run_tree_context = get_current_run_tree

Expand Down
21 changes: 12 additions & 9 deletions python/langsmith/run_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def from_headers(cls, headers: Dict[str, str], **kwargs: Any) -> Optional[Span]:

langsmith_trace = headers.get(f"{LANGSMITH_PREFIX}trace")
if not langsmith_trace:
return
return None

parent_dotted_order = langsmith_trace.strip()
parsed_dotted_order = _parse_dotted_order(parent_dotted_order)
Expand Down Expand Up @@ -347,14 +347,17 @@ def from_header(cls, header_value: Optional[str]) -> _Baggage:
metadata = {}
tags = []
id_ = None
for item in header_value.split(","):
key, value = item.split("=", 1)
if key == f"{LANGSMITH_PREFIX}-metadata":
metadata = json.loads(urllib.parse.unquote(value))
elif key == f"{LANGSMITH_PREFIX}-tags":
tags = urllib.parse.unquote(value).split(",")
elif key == f"{LANGSMITH_PREFIX}-id":
id_ = UUID(value)
try:
for item in header_value.split(","):
key, value = item.split("=", 1)
if key == f"{LANGSMITH_PREFIX}-metadata":
metadata = json.loads(urllib.parse.unquote(value))
elif key == f"{LANGSMITH_PREFIX}-tags":
tags = urllib.parse.unquote(value).split(",")
elif key == f"{LANGSMITH_PREFIX}-id":
id_ = UUID(value)
except Exception as e:
logger.warning(f"Error parsing baggage header: {e}")

return cls(metadata=metadata, tags=tags, id=id_)

Expand Down

0 comments on commit c47e838

Please sign in to comment.