Skip to content

Commit b863e9c

Browse files
committed
feat(llmobs): user processor can add metadata to span
1 parent a14402e commit b863e9c

File tree

4 files changed

+587
-5
lines changed

4 files changed

+587
-5
lines changed

ddtrace/llmobs/_llmobs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def span_processor(span: LLMObsSpan) -> Optional[LLMObsSpan]:
203203

204204
input: List[Message] = field(default_factory=list)
205205
output: List[Message] = field(default_factory=list)
206+
metadata: Dict[str, Any] = field(default_factory=dict)
206207
_tags: Dict[str, str] = field(default_factory=dict)
207208

208209
def get_tag(self, key: str) -> Optional[str]:
@@ -409,6 +410,8 @@ def _llmobs_span_event(self, span: Span) -> Optional[LLMObsSpanEvent]:
409410
meta["output"]["messages"] = llmobs_span.output
410411
elif output_type == "value":
411412
meta["output"]["value"] = llmobs_span.output[0].get("content", "")
413+
if llmobs_span.metadata:
414+
meta["metadata"].update(llmobs_span.metadata)
412415

413416
if not meta["input"]:
414417
meta.pop("input")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
LLMObs: This update introduces the ability for users to add custom metadata to LLMObs spans
5+
by setting a `metadata` attribute on the `LLMObsSpan` object passed to their registered
6+
span processors.

0 commit comments

Comments
 (0)