Skip to content

Commit

Permalink
fix: metadata as json string in langchain instrumentor (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerHYang authored Mar 11, 2024
1 parent 5bf584b commit 0cb0850
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,7 @@ def _metadata(run: Run) -> Iterator[Tuple[str, str]]:
if not run.extra or not (metadata := run.extra.get("metadata")):
return
assert isinstance(metadata, Mapping), f"expected Mapping, found {type(metadata)}"
# Yield out each metadata key and value
for key, value in metadata.items():
yield f"{METADATA}.{key}", value
yield METADATA, json.dumps(metadata)


@stop_on_exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def test_chain_metadata(

assert (llm_chain_span := spans_by_name.pop("LLMChain")) is not None
assert llm_chain_span.attributes
assert llm_chain_span.attributes.get("metadata.category") == "jokes"
assert llm_chain_span.attributes.get(METADATA) == '{"category": "jokes"}'


@pytest.fixture
Expand Down Expand Up @@ -371,6 +371,7 @@ async def __aiter__(self) -> AsyncIterator[bytes]:
MESSAGE_FUNCTION_CALL_NAME = MessageAttributes.MESSAGE_FUNCTION_CALL_NAME
MESSAGE_ROLE = MessageAttributes.MESSAGE_ROLE
MESSAGE_TOOL_CALLS = MessageAttributes.MESSAGE_TOOL_CALLS
METADATA = SpanAttributes.METADATA
OPENINFERENCE_SPAN_KIND = SpanAttributes.OPENINFERENCE_SPAN_KIND
OUTPUT_MIME_TYPE = SpanAttributes.OUTPUT_MIME_TYPE
OUTPUT_VALUE = SpanAttributes.OUTPUT_VALUE
Expand Down

0 comments on commit 0cb0850

Please sign in to comment.