Skip to content

Commit d1d38df

Browse files
authored
Merge branch 'main' into TID-rule
2 parents 8906ab8 + 9a22212 commit d1d38df

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
## Unreleased
1414

15-
- Enabled the flake8-tidy-import plugins rules for the ruff linter. These rules throw warnings for relative imports in the modules. The banned-api and banned-module-level-imports rules have not been configured yet. They can be configured as per their need in future ([#5019](https://github.com/open-telemetry/opentelemetry-python/pull/5019))
15+
- Enabled the flake8-tidy-import plugins rules for the ruff linter. These rules throw warnings for relative imports in the modules. The banned-api and banned-module-level-imports rules have not been configured yet. They can be configured as per their need in future
16+
([#5019](https://github.com/open-telemetry/opentelemetry-python/pull/5019))
17+
- `opentelemetry-api`: Replace a broad exception in attribute cleaning tests to satisfy pylint in the `lint-opentelemetry-api` CI job
1618
- `opentelemetry-sdk`: Add `create_resource` and `create_propagator`/`configure_propagator` to declarative file configuration, enabling Resource and propagator instantiation from config files without reading env vars
1719
([#4979](https://github.com/open-telemetry/opentelemetry-python/pull/4979))
1820
- `opentelemetry-sdk`: Map Python `CRITICAL` log level to OTel `FATAL` severity text per the specification

opentelemetry-api/src/opentelemetry/attributes/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
)
3838

3939

40+
# TODO: Remove this workaround and revert to the simpler implementation
41+
# once Python 3.9 support is dropped (planned around May 2026).
42+
# This exists only to avoid issues caused by deprecated behavior in 3.9.
43+
def _type_name(t):
44+
return getattr(t, "__name__", getattr(t, "_name", repr(t)))
45+
46+
4047
_logger = logging.getLogger(__name__)
4148

4249

@@ -191,7 +198,7 @@ def _clean_extended_attribute_value( # pylint: disable=too-many-branches
191198
except Exception:
192199
raise TypeError(
193200
f"Invalid type {type(value).__name__} for attribute value. "
194-
f"Expected one of {[valid_type.__name__ for valid_type in _VALID_ANY_VALUE_TYPES]} or a "
201+
f"Expected one of {[_type_name(valid_type) for valid_type in _VALID_ANY_VALUE_TYPES]} or a "
195202
"sequence of those types",
196203
)
197204

opentelemetry-api/tests/attributes/test_attributes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
import copy
1818
import unittest
19+
import unittest.mock
1920
from typing import MutableSequence
2021

2122
from opentelemetry.attributes import (
2223
BoundedAttributes,
2324
_clean_attribute,
2425
_clean_extended_attribute,
26+
_clean_extended_attribute_value,
2527
)
2628

2729

@@ -322,6 +324,14 @@ def __str__(self):
322324
"<DummyWSGIRequest method=GET path=/example/>", cleaned_value
323325
)
324326

327+
def test_invalid_anyvalue_type_raises_typeerror(self):
328+
class BadStr:
329+
def __str__(self):
330+
raise RuntimeError("boom")
331+
332+
with self.assertRaises(TypeError):
333+
_clean_extended_attribute_value(BadStr(), None)
334+
325335
def test_deepcopy(self):
326336
bdict = BoundedAttributes(4, self.base, immutable=False)
327337
bdict.dropped = 10

0 commit comments

Comments
 (0)