From 2fb096809840cfcfe18b295b325262c36f23d2df Mon Sep 17 00:00:00 2001 From: WatchTree-19 <119982314+WatchTree-19@users.noreply.github.com> Date: Thu, 7 May 2026 15:46:54 +0100 Subject: [PATCH 1/2] sdk: tighten ReadableSpan.attributes to non-Optional Mapping (#4569) --- opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 18fced7061..98e515e73a 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -497,7 +497,12 @@ def status(self) -> trace_api.Status: return self._status @property - def attributes(self) -> types.Attributes: + def attributes(self) -> Mapping[str, types.AttributeValue]: + # The implementation always returns a MappingProxyType, never None, + # because `self._attributes or {}` falls back to an empty dict. + # Tightening the return annotation fixes type-checker complaints + # like `Object of type "None" is not subscriptable` when callers + # do `span.attributes["key"]`. See issue #4569. return MappingProxyType(self._attributes or {}) @property From 97d0d2a49d5dd4db8c094ee13e1f67bfbd6fbc9d Mon Sep 17 00:00:00 2001 From: WatchTree-19 <119982314+WatchTree-19@users.noreply.github.com> Date: Fri, 8 May 2026 14:45:33 +0100 Subject: [PATCH 2/2] changelog: add entry for ReadableSpan.attributes annotation tightening (#5183) --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index abf32976e9..ec2ae0169a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- `opentelemetry-sdk`: tighten `ReadableSpan.attributes` annotation to non-Optional `Mapping` so callers don't need `assert ... is not None` boilerplate; runtime guarantee was already in place via `MappingProxyType(self._attributes or {})` + ([#5183](https://github.com/open-telemetry/opentelemetry-python/pull/5183)) +- Apply fixes for `UP` ruff rule + ([#5133](https://github.com/open-telemetry/opentelemetry-python/pull/5133)) +- Switch to SPDX license headers and add CI enforcement + ([#5177](https://github.com/open-telemetry/opentelemetry-python/pull/5177)) - `opentelemetry-api`: Enforce W3C Baggage size limits on outbound propagation in `W3CBaggagePropagator.inject()`. Previously only inbound extraction enforced limits; now inject also caps entries at 180, individual pairs at 4096 bytes, and total header at 8192 bytes per the W3C Baggage spec. The extract path max_pairs limit now counts all size-valid entries rather than only successfully parsed ones. ([#5163](https://github.com/open-telemetry/opentelemetry-python/pull/5163)) - `opentelemetry-sdk`: add `additional_properties` support to generated config models via custom `datamodel-codegen` template, enabling plugin/custom component names to flow through typed dataclasses @@ -42,6 +48,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#5135](https://github.com/open-telemetry/opentelemetry-python/pull/5135)) - ci: wait for tracecontext server readiness instead of a fixed sleep in `scripts/tracecontext-integration-test.sh` ([#5149](https://github.com/open-telemetry/opentelemetry-python/pull/5149)) +- `opentelemetry-api`: update `EnvironmentGetter` and `EnvironmentSetter` to use normalized environment variable names + ([#5119](https://github.com/open-telemetry/opentelemetry-python/pull/5119)) +- `opentelemetry-sdk`: only load entrypoints for resource detectors if they are configured via `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS` + ([#5145](https://github.com/open-telemetry/opentelemetry-python/pull/5145)) +- `opentelemetry-exporter-otlp-json-common`: add 'opentelemetry-exporter-otlp-json-common' package for OTLP JSON exporters + ([#4996](https://github.com/open-telemetry/opentelemetry-python/pull/4996)) +- `opentelemetry-exporter-otlp-proto-grpc`: make retryable gRPC error codes configurable for gRPC exporters + ([#4917](https://github.com/open-telemetry/opentelemetry-python/pull/4917)) ## Version 1.41.0/0.62b0 (2026-04-09)