diff --git a/tests/test_span_attribute_invariants.py b/tests/test_span_attribute_invariants.py new file mode 100644 index 0000000000..b54e4d3027 --- /dev/null +++ b/tests/test_span_attribute_invariants.py @@ -0,0 +1,17 @@ +import pytest + +def validate_span_attribute(key: str, value) -> bool: + if not isinstance(key, str) or not key.strip(): + return False + if not isinstance(value, (str, int, float, bool, bytes)): + return False + return True + +def test_valid_span_attributes(): + assert validate_span_attribute("http.status_code", 200) is True + assert validate_span_attribute("db.system", "postgresql") is True + assert validate_span_attribute("ai.request.duration_ms", 142.5) is True + +def test_invalid_span_attributes(): + assert validate_span_attribute("", 200) is False + assert validate_span_attribute("custom.key", [1, 2, 3]) is False