Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
28901b2
Initial changes..
DylanRussell May 21, 2026
55af143
Make lots of changes
DylanRussell May 27, 2026
f9a9600
Merge branch 'main' into extended_attributes
DylanRussell May 27, 2026
aee7365
Fix tests, run precommit
DylanRussell May 27, 2026
66d3d12
Fix more tests
DylanRussell May 27, 2026
30df0bd
Run precommit
DylanRussell May 27, 2026
ca0a0e4
Fix more tests
DylanRussell May 27, 2026
d73d251
Refactor clean attributes code and tests..
DylanRussell May 29, 2026
98fb897
Add more test coverage.. Still need to get the type checker passing.
DylanRussell May 29, 2026
99ae2f7
Refactor BoundedAttributes again.. Fix lots of tests
DylanRussell Jun 1, 2026
a26a6ef
Fix lint issues
DylanRussell Jun 1, 2026
52fe1df
Fix lint issues, spellcheck issues, add changelog
DylanRussell Jun 1, 2026
e6b09c9
Fix typo
DylanRussell Jun 1, 2026
796121d
Fix __iter__
DylanRussell Jun 2, 2026
1f9c0a7
Remove log warning.. add msg to TypeError
DylanRussell Jun 2, 2026
bde6f6b
Clean up BoundedAttributes
DylanRussell Jun 2, 2026
faeeefe
Remove encoding of Bytes. Fix tests..
DylanRussell Jun 2, 2026
f35002d
Revert lock file
DylanRussell Jun 2, 2026
bfebcac
Fix busted tests
DylanRussell Jun 2, 2026
588ffef
Add commnet retrigger CI
DylanRussell Jun 2, 2026
eb12236
Minor fixes..
DylanRussell Jun 2, 2026
ff58266
Merge branch 'main' into extended_attributes
DylanRussell Jun 3, 2026
22bb59e
Clarify immutability
DylanRussell Jun 3, 2026
cbf83b4
Minor fixes
DylanRussell Jun 3, 2026
b4219fe
Merge branch 'main' into extended_attributes
DylanRussell Jun 5, 2026
4c8ab76
Merge branch 'main' into extended_attributes
DylanRussell Jun 8, 2026
48cf4c0
Add changelog
DylanRussell Jun 9, 2026
d661309
Merge branch 'main' into extended_attributes
DylanRussell Jun 10, 2026
9fbb161
Try to decode bytes to string using utf-8, fallback to return bytes
DylanRussell Jun 10, 2026
a123d32
Add @overload and @deprecated to the init with extended_attributes
DylanRussell Jun 10, 2026
862d843
Typo
DylanRussell Jun 10, 2026
a64f733
Fix @overload. Delete weird type and very stale .pyi file
DylanRussell Jun 11, 2026
64f7736
Try and fail to fix docs issue
DylanRussell Jun 11, 2026
bbf0401
Refactor clean attribute value and associated tests after discussion …
DylanRussell Jun 11, 2026
a3c42e0
Try to fix docs issue
DylanRussell Jun 15, 2026
a0e7f0d
Merge branch 'main' into extended_attributes
DylanRussell Jun 15, 2026
4b8b1f2
Address comments
DylanRussell Jun 15, 2026
0d6ab9c
Revert changes to logging code
DylanRussell Jun 15, 2026
1343ac5
Add TODOs, update changelog
DylanRussell Jun 15, 2026
6858898
Minor changes to changelog and envvar wording.
DylanRussell Jun 15, 2026
26529fc
Merge branch 'main' into extended_attributes
DylanRussell Jun 16, 2026
b6c84dc
Use json.dumps to hash attributes. Respond to some comments..
DylanRussell Jun 16, 2026
8da5736
Update test to capture mutable types..
DylanRussell Jun 16, 2026
38f075c
Fix lint
DylanRussell Jun 16, 2026
3ebc09f
Merge branch 'main' into extended_attributes
DylanRussell Jun 17, 2026
ba41e8d
FIx precommit. bunch of minor cleanup
DylanRussell Jun 17, 2026
d90d193
Clarify params
DylanRussell Jun 17, 2026
c298055
Merge branch 'main' into extended_attributes
DylanRussell Jun 18, 2026
61f27c0
Merge branch 'main' into extended_attributes
DylanRussell Jun 18, 2026
36b9980
Missing import
DylanRussell Jun 18, 2026
1a05554
Minor changes..
DylanRussell Jun 18, 2026
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
1 change: 1 addition & 0 deletions .changelog/5266.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`opentelemetry-api`, `opentelemetry-sdk`: add support for extended attribute values everywhere.
2 changes: 2 additions & 0 deletions .changelog/5266.changed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The public `opentelemetry.util.types.AttributeValue` type in package `opentelemetry-api` is being expanded to include `None`, heterogeneous sequences of primitive types (and nested sequences) as opposed to only homogeneous primitive sequences, and Mappings of strings to any primitive types or sequences/mappings (which themselves must only contain primitive types or sequences/mappings validated the same way).
If a `bytes` type is found as an AttributeValue, it will no longer be utf-8 decoded to a string, instead it will be passed along as is in accordance with the OTEL spec, since `bytes` is a valid type in the OTLP proto.
21 changes: 10 additions & 11 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@

settings.configure()

# Provide AnyValue in opentelemetry.attributes module's namespace so the
# "AnyValue" forward reference in opentelemetry.util.types._ExtendedAttributes
# resolves when sphinx_autodoc_typehints calls typing.get_type_hints() on
# BoundedAttributes (whose __globals__ is the attributes module). Docs-only.
import opentelemetry.attributes # noqa: E402
from opentelemetry.util.types import AnyValue as _AnyValue # noqa: E402
# Docs-only: resolves the "AnyValue" forward reference wherever
# get_type_hints() evaluates it. AnyValue is a recursive alias, so
# modules that import it only under TYPE_CHECKING hit a NameError.
# TODO: https://github.com/open-telemetry/opentelemetry-python/issues/5304
# this can be removed by importing AnyValue at runtime in the
# modules that annotate with it
import builtins # noqa: E402

opentelemetry.attributes.AnyValue = _AnyValue
from opentelemetry.util.types import AnyValue # noqa: E402

builtins.AnyValue = AnyValue


source_dirs = [
Expand Down Expand Up @@ -186,10 +189,6 @@
"py:class",
"AnyValue",
),
(
"py:class",
"_ExtendedAttributes",
),
("py:class", "Token"),
# ``from os import PathLike`` renders as the bare name ``PathLike`` in the
# file exporter type hints, which sphinx cannot resolve to os.PathLike.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
)
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
from opentelemetry.util.types import _ExtendedAttributes
from opentelemetry.util.types import Attributes

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -109,7 +109,7 @@ def _encode_trace_id(trace_id: int) -> bytes:


def _encode_attributes(
attributes: _ExtendedAttributes | None,
attributes: Attributes,
) -> list[JSONKeyValue]:
if not attributes:
return []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _encode_log(readable_log_record: ReadableLogRecord) -> JSONLogRecord:
body=_encode_value(readable_log_record.log_record.body),
severity_text=readable_log_record.log_record.severity_text,
attributes=_encode_attributes(
cast(Attributes, readable_log_record.log_record.attributes),
cast(Attributes, readable_log_record.log_record.attributes)
),
dropped_attributes_count=readable_log_record.dropped_attributes,
severity_number=getattr(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)
from opentelemetry.sdk.trace import Resource
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
from opentelemetry.util.types import _ExtendedAttributes
from opentelemetry.util.types import Attributes

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -89,9 +89,7 @@ def _encode_trace_id(trace_id: int) -> bytes:
return trace_id.to_bytes(length=16, byteorder="big", signed=False)


def _encode_attributes(
attributes: _ExtendedAttributes | None,
) -> list[PB2KeyValue]:
def _encode_attributes(attributes: Attributes) -> list[PB2KeyValue]:
if not attributes:
return []
pb2_attributes = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, channel):


@patch(
"opentelemetry.exporter.otlp.proto.grpc.trace_exporter.OTLPSpanExporter._stub",
"opentelemetry.exporter.otlp.proto.grpc.trace_exporter.TraceServiceStub",
new=MockTraceServiceStub,
)
def test_simple_span_processor(benchmark):
Expand All @@ -51,7 +51,7 @@ def create_spans_to_be_exported():


@patch(
"opentelemetry.exporter.otlp.proto.grpc.trace_exporter.OTLPSpanExporter._stub",
"opentelemetry.exporter.otlp.proto.grpc.trace_exporter.TraceServiceStub",
new=MockTraceServiceStub,
)
def test_batch_span_processor(benchmark):
Expand Down
16 changes: 8 additions & 8 deletions opentelemetry-api/src/opentelemetry/_events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from opentelemetry.trace.span import TraceFlags
from opentelemetry.util._once import Once
from opentelemetry.util._providers import _load_provider
from opentelemetry.util.types import AnyValue, _ExtendedAttributes
from opentelemetry.util.types import AnyValue, Attributes

_logger = getLogger(__name__)

Expand All @@ -37,7 +37,7 @@ def __init__(
trace_flags: TraceFlags | None = None,
body: AnyValue | None = None,
severity_number: SeverityNumber | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
):
attributes = attributes or {}
event_attributes = {
Expand Down Expand Up @@ -66,7 +66,7 @@ def __init__(
name: str,
version: str | None = None,
schema_url: str | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
):
self._name = name
self._version = version
Expand Down Expand Up @@ -97,7 +97,7 @@ def __init__(
name: str,
version: str | None = None,
schema_url: str | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
):
super().__init__(
name=name,
Expand Down Expand Up @@ -138,7 +138,7 @@ def get_event_logger(
name: str,
version: str | None = None,
schema_url: str | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
) -> EventLogger:
"""Returns an EventLoggerProvider for use."""

Expand All @@ -153,7 +153,7 @@ def get_event_logger(
name: str,
version: str | None = None,
schema_url: str | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
) -> EventLogger:
return NoOpEventLogger(
name, version=version, schema_url=schema_url, attributes=attributes
Expand All @@ -170,7 +170,7 @@ def get_event_logger(
name: str,
version: str | None = None,
schema_url: str | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
) -> EventLogger:
if _EVENT_LOGGER_PROVIDER:
return _EVENT_LOGGER_PROVIDER.get_event_logger(
Expand Down Expand Up @@ -244,7 +244,7 @@ def get_event_logger(
name: str,
version: str | None = None,
schema_url: str | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
event_logger_provider: EventLoggerProvider | None = None,
) -> EventLogger:
if event_logger_provider is None:
Expand Down
32 changes: 16 additions & 16 deletions opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from opentelemetry.trace.span import TraceFlags
from opentelemetry.util._once import Once
from opentelemetry.util._providers import _load_provider
from opentelemetry.util.types import AnyValue, _ExtendedAttributes
from opentelemetry.util.types import AnyValue, Attributes

_logger = getLogger(__name__)

Expand All @@ -63,7 +63,7 @@ def __init__(
severity_text: str | None = None,
severity_number: SeverityNumber | None = None,
body: AnyValue = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
event_name: str | None = None,
exception: BaseException | None = None,
) -> None: ...
Expand All @@ -83,7 +83,7 @@ def __init__(
severity_text: str | None = None,
severity_number: SeverityNumber | None = None,
body: AnyValue = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
) -> None: ...

def __init__(
Expand All @@ -98,7 +98,7 @@ def __init__(
severity_text: str | None = None,
severity_number: SeverityNumber | None = None,
body: AnyValue = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
event_name: str | None = None,
exception: BaseException | None = None,
) -> None:
Expand Down Expand Up @@ -129,7 +129,7 @@ def __init__(
name: str,
version: str | None = None,
schema_url: str | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
) -> None:
super().__init__()
self._name = name
Expand All @@ -147,7 +147,7 @@ def emit(
severity_number: SeverityNumber | None = None,
severity_text: str | None = None,
body: AnyValue | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
event_name: str | None = None,
exception: BaseException | None = None,
) -> None: ...
Expand All @@ -169,7 +169,7 @@ def emit(
severity_number: SeverityNumber | None = None,
severity_text: str | None = None,
body: AnyValue | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
event_name: str | None = None,
exception: BaseException | None = None,
) -> None:
Expand All @@ -192,7 +192,7 @@ def emit(
severity_number: SeverityNumber | None = None,
severity_text: str | None = None,
body: AnyValue | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
event_name: str | None = None,
exception: BaseException | None = None,
) -> None: ...
Expand All @@ -213,7 +213,7 @@ def emit(
severity_number: SeverityNumber | None = None,
severity_text: str | None = None,
body: AnyValue | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
event_name: str | None = None,
exception: BaseException | None = None,
) -> None:
Expand All @@ -226,7 +226,7 @@ def __init__( # pylint: disable=super-init-not-called
name: str,
version: str | None = None,
schema_url: str | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
):
self._name = name
self._version = version
Expand Down Expand Up @@ -260,7 +260,7 @@ def emit(
severity_number: SeverityNumber | None = None,
severity_text: str | None = None,
body: AnyValue | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
event_name: str | None = None,
exception: BaseException | None = None,
) -> None: ...
Expand All @@ -281,7 +281,7 @@ def emit(
severity_number: SeverityNumber | None = None,
severity_text: str | None = None,
body: AnyValue | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
event_name: str | None = None,
exception: BaseException | None = None,
) -> None:
Expand Down Expand Up @@ -312,7 +312,7 @@ def get_logger(
name: str,
version: str | None = None,
schema_url: str | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
) -> Logger:
"""Returns a `Logger` for use by the given instrumentation library.

Expand Down Expand Up @@ -351,7 +351,7 @@ def get_logger(
name: str,
version: str | None = None,
schema_url: str | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
) -> Logger:
"""Returns a NoOpLogger."""
return NoOpLogger(
Expand All @@ -365,7 +365,7 @@ def get_logger(
name: str,
version: str | None = None,
schema_url: str | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
) -> Logger:
if _LOGGER_PROVIDER:
return _LOGGER_PROVIDER.get_logger(
Expand Down Expand Up @@ -428,7 +428,7 @@ def get_logger(
instrumenting_library_version: str = "",
logger_provider: LoggerProvider | None = None,
schema_url: str | None = None,
attributes: _ExtendedAttributes | None = None,
attributes: Attributes = None,
) -> Logger:
"""Returns a `Logger` for use within a python process.

Expand Down
Loading
Loading