Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
### Bugs Fixed

### Other Changes

- Update maximum size of custom properties
([#](https://github.com/Azure/azure-sdk-for-python/pull/))
Comment thread
hectorhdzg marked this conversation as resolved.
Outdated
- Declare support for Python 3.13 and 3.14
([#44550](https://github.com/Azure/azure-sdk-for-python/pull/44550))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def _is_any_synthetic_source(properties: Optional[Any]) -> bool:

# pylint: disable=W0622
def _filter_custom_properties(properties: Attributes, filter=None) -> Dict[str, str]:
max_length = 64 * 1024
Comment thread
hectorhdzg marked this conversation as resolved.
truncated_properties: Dict[str, str] = {}
if not properties:
return truncated_properties
Expand All @@ -365,10 +366,10 @@ def _filter_custom_properties(properties: Attributes, filter=None) -> Dict[str,
if not filter(key, val):
continue
# Apply truncation rules
# Max key length is 150, value is 8192
# Max key length is 150, value is 64 * 1024
if not key or len(key) > 150 or val is None:
continue
truncated_properties[key] = str(val)[:8192]
truncated_properties[key] = str(val)[:max_length]
return truncated_properties


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ class TestUtils(unittest.TestCase):
def setUp(self):
self._valid_instrumentation_key = "1234abcd-5678-4efa-8abc-1234567890ab"

def test_filter_custom_properties_truncates_and_drops_invalid_entries(self):
oversized_value = "v" * 9000
properties = {
"valid_key": oversized_value,
"k" * 151: "should_be_dropped",
"": "missing_key",
"short": "ok",
"none_value": None,
}

filtered = _utils._filter_custom_properties(properties)

self.assertEqual(len(filtered), 2)
self.assertIn("valid_key", filtered)
self.assertEqual(len(filtered["valid_key"]), 8192)
Comment thread
hectorhdzg marked this conversation as resolved.
Outdated
self.assertEqual(filtered["short"], "ok")
self.assertNotIn("k" * 151, filtered)

def test_nanoseconds_to_duration(self):
ns_to_duration = _utils.ns_to_duration
self.assertEqual(ns_to_duration(0), "0.00:00:00.000")
Expand Down
Loading