-
Notifications
You must be signed in to change notification settings - Fork 303
fix(propagation): coerce propagated metadata values #1709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,7 +95,7 @@ | |
| *, | ||
| user_id: Optional[str] = None, | ||
| session_id: Optional[str] = None, | ||
| metadata: Optional[Dict[str, str]] = None, | ||
| metadata: Optional[Dict[str, Any]] = None, | ||
| version: Optional[str] = None, | ||
| tags: Optional[List[str]] = None, | ||
| trace_name: Optional[str] = None, | ||
|
|
@@ -125,10 +125,11 @@ | |
| Must be US-ASCII string, ≤200 characters. Use this to group related traces | ||
| within a user session (e.g., a conversation thread, multi-turn interaction). | ||
| metadata: Additional key-value metadata to propagate to all spans. | ||
| - Keys and values must be US-ASCII strings | ||
| - All values must be ≤200 characters | ||
| - Keys must be US-ASCII strings | ||
| - Values are coerced to strings | ||
| - Coerced values must be ≤200 characters | ||
| - Use for dimensions like internal correlating identifiers | ||
| - AVOID: large payloads, sensitive data, non-string values (will be dropped with warning) | ||
| - AVOID: large payloads or sensitive data | ||
| version: Version identfier for parts of your application that are independently versioned, e.g. agents | ||
| tags: List of tags to categorize the group of observations | ||
| trace_name: Name to assign to the trace. Must be US-ASCII string, ≤200 characters. | ||
|
|
@@ -204,9 +205,10 @@ | |
| ``` | ||
|
|
||
| Note: | ||
| - **Validation**: All attribute values (user_id, session_id, metadata values) | ||
| must be strings ≤200 characters. Invalid values will be dropped with a | ||
| warning logged. Ensure values meet constraints before calling. | ||
| - **Validation**: Attribute values (user_id, session_id, version, tags, | ||
| trace_name) must be strings ≤200 characters. Metadata values are | ||
| coerced to strings before the 200 character limit is applied. Invalid | ||
| values will be dropped with a warning logged. | ||
| - **OpenTelemetry**: This uses OpenTelemetry context propagation under the hood, | ||
| making it compatible with other OTel-instrumented libraries. | ||
|
|
||
|
|
@@ -229,7 +231,7 @@ | |
| *, | ||
| user_id: Optional[str] = None, | ||
| session_id: Optional[str] = None, | ||
| metadata: Optional[Dict[str, str]] = None, | ||
| metadata: Optional[Dict[str, Any]] = None, | ||
| version: Optional[str] = None, | ||
| tags: Optional[List[str]] = None, | ||
| trace_name: Optional[str] = None, | ||
|
|
@@ -247,7 +249,7 @@ | |
| "trace_name": trace_name, | ||
| } | ||
|
|
||
| propagated_metadata_attributes: Dict[str, Optional[Dict[str, str]]] = { | ||
| propagated_metadata_attributes: Dict[str, Optional[Dict[str, Any]]] = { | ||
| "metadata": metadata, | ||
| } | ||
|
|
||
|
|
@@ -285,9 +287,11 @@ | |
|
|
||
| validated_metadata: Dict[str, str] = {} | ||
|
|
||
| for key, value in metadata_value.items(): | ||
| if _validate_string_value(value=value, key=f"{metadata_key}.{key}"): | ||
| validated_metadata[key] = value | ||
| coerced_value = value if isinstance(value, str) else str(value) | ||
|
|
||
| if _validate_string_value(value=coerced_value, key=f"{metadata_key}.{key}"): | ||
| validated_metadata[key] = coerced_value | ||
|
Check failure on line 294 in langfuse/_client/propagation.py
|
||
|
Comment on lines
290
to
+294
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 The new metadata coercion at line 291 ( Extended reasoning...Bug 1:
|
||
|
|
||
| if validated_metadata: | ||
| context = _set_propagated_attribute( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When callers build propagated metadata with optional fields such as
{"tenant": None}, this line now coerces the value to the literal string"None"and propagateslangfuse.trace.metadata.tenantto every child span. Before this change those non-string values were dropped, and the SDK's metadata serialization helpers omitNone, so optional/absent metadata now becomes a misleading filterable value instead of remaining absent; skipNonebefore string coercion.Useful? React with 👍 / 👎.