Skip to content

Commit 49aa52c

Browse files
committed
fix: update type hints and docstrings to reflect coercion behavior
- metadata parameter type: Dict[str, str] -> Dict[str, Any] - Docstring: document that non-string values are coerced via str() - Note section: clarify coercion vs dropping behavior
1 parent 3ea00c2 commit 49aa52c

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

langfuse/_client/propagation.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def propagate_attributes(
7676
*,
7777
user_id: Optional[str] = None,
7878
session_id: Optional[str] = None,
79-
metadata: Optional[Dict[str, str]] = None,
79+
metadata: Optional[Dict[str, Any]] = None,
8080
version: Optional[str] = None,
8181
tags: Optional[List[str]] = None,
8282
trace_name: Optional[str] = None,
@@ -106,10 +106,11 @@ def propagate_attributes(
106106
Must be US-ASCII string, ≤200 characters. Use this to group related traces
107107
within a user session (e.g., a conversation thread, multi-turn interaction).
108108
metadata: Additional key-value metadata to propagate to all spans.
109-
- Keys and values must be US-ASCII strings
110-
- All values must be ≤200 characters
109+
- Keys must be US-ASCII strings
110+
- Non-string values are automatically coerced to strings via str()
111+
- All values (after coercion) must be ≤200 characters; oversized values are dropped with a warning
111112
- Use for dimensions like internal correlating identifiers
112-
- AVOID: large payloads, sensitive data, non-string values (will be dropped with warning)
113+
- AVOID: large payloads, sensitive data
113114
version: Version identfier for parts of your application that are independently versioned, e.g. agents
114115
tags: List of tags to categorize the group of observations
115116
trace_name: Name to assign to the trace. Must be US-ASCII string, ≤200 characters.
@@ -185,14 +186,15 @@ def propagate_attributes(
185186
```
186187
187188
Note:
188-
- **Validation**: All attribute values (user_id, session_id, metadata values)
189-
must be strings ≤200 characters. Invalid values will be dropped with a
190-
warning logged. Ensure values meet constraints before calling.
189+
- **Validation**: user_id, session_id, and trace_name must be strings
190+
≤200 characters. Metadata values may be any type and are coerced to
191+
strings via str(); values exceeding 200 characters after coercion
192+
are dropped with a warning.
191193
- **OpenTelemetry**: This uses OpenTelemetry context propagation under the hood,
192194
making it compatible with other OTel-instrumented libraries.
193195
194196
Raises:
195-
No exceptions are raised. Invalid values are logged as warnings and dropped.
197+
No exceptions are raised. Oversized values are logged as warnings and dropped.
196198
"""
197199
return _propagate_attributes(
198200
user_id=user_id,
@@ -210,7 +212,7 @@ def _propagate_attributes(
210212
*,
211213
user_id: Optional[str] = None,
212214
session_id: Optional[str] = None,
213-
metadata: Optional[Dict[str, str]] = None,
215+
metadata: Optional[Dict[str, Any]] = None,
214216
version: Optional[str] = None,
215217
tags: Optional[List[str]] = None,
216218
trace_name: Optional[str] = None,

0 commit comments

Comments
 (0)