MCPcopy
hub / github.com/microsoft/agent-lightning / sanitize_attributes

Function sanitize_attributes

agentlightning/utils/otel.py:481–494  ·  view source on GitHub ↗

Sanitize a dictionary of attributes to be a valid OpenTelemetry attributes. Args: attributes: A dictionary of attributes to sanitize. force: Whether to force sanitization even when the value is not JSON serializable.

(attributes: Dict[str, Any], force: bool = True)

Source from the content-addressed store, hash-verified

479
480
481def sanitize_attributes(attributes: Dict[str, Any], force: bool = True) -> Attributes:
482 """Sanitize a dictionary of attributes to be a valid OpenTelemetry attributes.
483
484 Args:
485 attributes: A dictionary of attributes to sanitize.
486 force: Whether to force sanitization even when the value is not JSON serializable.
487 """
488 result: Attributes = {}
489 for k, v in attributes.items():
490 try:
491 result[k] = sanitize_attribute_value(v, force=force)
492 except ValueError as exc:
493 raise ValueError(f"Failed to sanitize attribute '{k}': {exc}") from exc
494 return result
495
496
497def sanitize_list_attribute_sanity(maybe_list: List[Any]) -> AttributeValue:

Callers 15

convert_call_to_spanMethod · 0.90
emit_objectFunction · 0.90
emit_exceptionFunction · 0.90
emit_annotationFunction · 0.90
__enter__Method · 0.90
set_inputMethod · 0.90
set_outputMethod · 0.90
__call__Method · 0.90
_record_auto_inputsMethod · 0.90
_record_auto_outputsMethod · 0.90
emit_messageFunction · 0.90

Calls 1

sanitize_attribute_valueFunction · 0.85