diff --git a/.changelog/5277.changed b/.changelog/5277.changed new file mode 100644 index 00000000000..65f01e79434 --- /dev/null +++ b/.changelog/5277.changed @@ -0,0 +1 @@ +Remove typing aliases deprecated in python 3.9 and replace all usages of `typing.Union` and `typing.Optional` with `|`. diff --git a/codegen/opentelemetry-codegen-json/src/opentelemetry/codegen/json/generator.py b/codegen/opentelemetry-codegen-json/src/opentelemetry/codegen/json/generator.py index 14c4a98ead7..b8be0355246 100644 --- a/codegen/opentelemetry-codegen-json/src/opentelemetry/codegen/json/generator.py +++ b/codegen/opentelemetry-codegen-json/src/opentelemetry/codegen/json/generator.py @@ -879,8 +879,8 @@ def _get_field_type_hint( if field_desc.label == descriptor.FieldDescriptorProto.LABEL_REPEATED: return f"builtins.list[{base_type}]" if field_desc.type == descriptor.FieldDescriptorProto.TYPE_ENUM: - return f"typing.Union[{base_type}, builtins.int, None]" - return f"typing.Optional[{base_type}]" + return f"{base_type} | builtins.int | None" + return f"{base_type} | None" def _resolve_message_type(self, type_name: str, proto_file: str) -> str: """ diff --git a/codegen/opentelemetry-codegen-json/src/opentelemetry/codegen/json/runtime/json_codec.py b/codegen/opentelemetry-codegen-json/src/opentelemetry/codegen/json/runtime/json_codec.py index 0a6c7c71968..72c315d1eaa 100644 --- a/codegen/opentelemetry-codegen-json/src/opentelemetry/codegen/json/runtime/json_codec.py +++ b/codegen/opentelemetry-codegen-json/src/opentelemetry/codegen/json/runtime/json_codec.py @@ -5,6 +5,7 @@ import abc import base64 +import collections.abc import json import math import typing @@ -101,7 +102,7 @@ def encode_float(value: float) -> float | str: def encode_repeated( values: list[T] | None, - map_fn: typing.Callable[[T], typing.Any], + map_fn: collections.abc.Callable[[T], typing.Any], ) -> list[typing.Any]: """ Helper to serialize repeated fields with a mapping function. @@ -207,7 +208,7 @@ def decode_float(value: float | int | str | None, field_name: str) -> float: def decode_repeated( values: list[typing.Any] | None, - item_parser: typing.Callable[[typing.Any], T], + item_parser: collections.abc.Callable[[typing.Any], T], field_name: str, ) -> list[T]: """ diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index 60d26683695..f7fa0b8697d 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -29,7 +29,6 @@ NewType, Optional, TypeVar, - Union, ) from urllib.parse import urlparse diff --git a/opentelemetry-api/src/opentelemetry/_events/__init__.py b/opentelemetry-api/src/opentelemetry/_events/__init__.py index 9c70b90dae8..e9e60f74f6d 100644 --- a/opentelemetry-api/src/opentelemetry/_events/__init__.py +++ b/opentelemetry-api/src/opentelemetry/_events/__init__.py @@ -1,10 +1,12 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +from __future__ import annotations + from abc import ABC, abstractmethod from logging import getLogger from os import environ -from typing import Optional, cast +from typing import cast from typing_extensions import deprecated @@ -32,7 +34,7 @@ def __init__( timestamp: int | None = None, trace_id: int | None = None, span_id: int | None = None, - trace_flags: Optional["TraceFlags"] = None, + trace_flags: TraceFlags | None = None, body: AnyValue | None = None, severity_number: SeverityNumber | None = None, attributes: _ExtendedAttributes | None = None, @@ -72,7 +74,7 @@ def __init__( self._attributes = attributes @abstractmethod - def emit(self, event: "Event") -> None: + def emit(self, event: Event) -> None: """Emits a :class:`Event` representing an event.""" @@ -244,7 +246,7 @@ def get_event_logger( schema_url: str | None = None, attributes: _ExtendedAttributes | None = None, event_logger_provider: EventLoggerProvider | None = None, -) -> "EventLogger": +) -> EventLogger: if event_logger_provider is None: event_logger_provider = get_event_logger_provider() return event_logger_provider.get_event_logger( diff --git a/opentelemetry-api/src/opentelemetry/propagators/_envcarrier.py b/opentelemetry-api/src/opentelemetry/propagators/_envcarrier.py index 6b651488c06..d76452ff625 100644 --- a/opentelemetry-api/src/opentelemetry/propagators/_envcarrier.py +++ b/opentelemetry-api/src/opentelemetry/propagators/_envcarrier.py @@ -3,8 +3,7 @@ import os import re -import typing -from collections.abc import MutableMapping +from collections.abc import Mapping, MutableMapping from opentelemetry.propagators.textmap import Getter, Setter @@ -16,7 +15,7 @@ def _normalize_key(key: str) -> str: return result -class EnvironmentGetter(Getter[typing.Mapping[str, str]]): +class EnvironmentGetter(Getter[Mapping[str, str]]): """Getter implementation for extracting context and baggage from environment variables. EnvironmentGetter creates a normalized lookup from the current environment @@ -39,9 +38,7 @@ def __init__(self): _normalize_key(k): v for k, v in os.environ.items() } - def get( - self, carrier: typing.Mapping[str, str], key: str - ) -> list[str] | None: + def get(self, carrier: Mapping[str, str], key: str) -> list[str] | None: """Get a value from the environment carrier for the given key. Args: @@ -56,7 +53,7 @@ def get( return None return [val] - def keys(self, carrier: typing.Mapping[str, str]) -> list[str]: + def keys(self, carrier: Mapping[str, str]) -> list[str]: """Get all keys from the environment carrier. Args: diff --git a/opentelemetry-api/src/opentelemetry/propagators/composite.py b/opentelemetry-api/src/opentelemetry/propagators/composite.py index f6d864d8180..1d3c3912ee1 100644 --- a/opentelemetry-api/src/opentelemetry/propagators/composite.py +++ b/opentelemetry-api/src/opentelemetry/propagators/composite.py @@ -1,7 +1,7 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +import collections.abc import logging -import typing from typing_extensions import deprecated @@ -20,7 +20,7 @@ class CompositePropagator(textmap.TextMapPropagator): """ def __init__( - self, propagators: typing.Sequence[textmap.TextMapPropagator] + self, propagators: collections.abc.Sequence[textmap.TextMapPropagator] ) -> None: self._propagators = propagators diff --git a/opentelemetry-api/src/opentelemetry/propagators/textmap.py b/opentelemetry-api/src/opentelemetry/propagators/textmap.py index de37e65ce0f..04f5fe86832 100644 --- a/opentelemetry-api/src/opentelemetry/propagators/textmap.py +++ b/opentelemetry-api/src/opentelemetry/propagators/textmap.py @@ -3,6 +3,7 @@ import abc import typing +from collections.abc import Iterable, Mapping, MutableMapping from opentelemetry.context.context import Context @@ -59,9 +60,9 @@ def set(self, carrier: CarrierT, key: str, value: str) -> None: """ -class DefaultGetter(Getter[typing.Mapping[str, CarrierValT]]): +class DefaultGetter(Getter[Mapping[str, CarrierValT]]): def get( - self, carrier: typing.Mapping[str, CarrierValT], key: str + self, carrier: Mapping[str, CarrierValT], key: str ) -> list[str] | None: """Getter implementation to retrieve a value from a dictionary. @@ -74,11 +75,11 @@ def get( val = carrier.get(key, None) if val is None: return None - if isinstance(val, typing.Iterable) and not isinstance(val, str): + if isinstance(val, Iterable) and not isinstance(val, str): return list(val) return [val] - def keys(self, carrier: typing.Mapping[str, CarrierValT]) -> list[str]: + def keys(self, carrier: Mapping[str, CarrierValT]) -> list[str]: """Keys implementation that returns all keys from a dictionary.""" return list(carrier.keys()) @@ -86,10 +87,10 @@ def keys(self, carrier: typing.Mapping[str, CarrierValT]) -> list[str]: default_getter: Getter[CarrierT] = DefaultGetter() # type: ignore -class DefaultSetter(Setter[typing.MutableMapping[str, CarrierValT]]): +class DefaultSetter(Setter[MutableMapping[str, CarrierValT]]): def set( self, - carrier: typing.MutableMapping[str, CarrierValT], + carrier: MutableMapping[str, CarrierValT], key: str, value: CarrierValT, ) -> None: diff --git a/opentelemetry-api/src/opentelemetry/trace/span.py b/opentelemetry-api/src/opentelemetry/trace/span.py index 60befed6028..23a24f16782 100644 --- a/opentelemetry-api/src/opentelemetry/trace/span.py +++ b/opentelemetry-api/src/opentelemetry/trace/span.py @@ -1,12 +1,15 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +from __future__ import annotations + import abc import logging import re import types as python_types import typing import warnings +from collections.abc import Iterator, Mapping, Sequence from opentelemetry.trace.status import Status, StatusCode from opentelemetry.util import types @@ -70,7 +73,7 @@ def end(self, end_time: int | None = None) -> None: """ @abc.abstractmethod - def get_span_context(self) -> "SpanContext": + def get_span_context(self) -> SpanContext: """Gets the span's SpanContext. Get an immutable, serializable identifier for this span that can be @@ -82,7 +85,7 @@ def get_span_context(self) -> "SpanContext": @abc.abstractmethod def set_attributes( - self, attributes: typing.Mapping[str, types.AttributeValue] + self, attributes: Mapping[str, types.AttributeValue] ) -> None: """Sets Attributes. @@ -122,7 +125,7 @@ def add_event( def add_link( # pylint: disable=no-self-use self, - context: "SpanContext", + context: SpanContext, attributes: types.Attributes = None, ) -> None: """Adds a `Link`. @@ -179,7 +182,7 @@ def record_exception( ) -> None: """Records an exception as a span event.""" - def __enter__(self) -> "Span": + def __enter__(self) -> Span: """Invoked when `Span` is used as a context manager. Returns the `Span` itself. @@ -217,7 +220,7 @@ class TraceFlags(int): RANDOM_TRACE_ID = 0x02 @classmethod - def get_default(cls) -> "TraceFlags": + def get_default(cls) -> TraceFlags: return cls(cls.DEFAULT) @property @@ -232,7 +235,7 @@ def random_trace_id(self) -> bool: DEFAULT_TRACE_OPTIONS = TraceFlags.get_default() -class TraceState(typing.Mapping[str, str]): +class TraceState(Mapping[str, str]): """A list of key-value pairs representing vendor-specific trace info. Keys and values are strings of up to 256 printable US-ASCII characters. @@ -245,7 +248,7 @@ class TraceState(typing.Mapping[str, str]): def __init__( self, - entries: typing.Sequence[tuple[str, str]] | None = None, + entries: Sequence[tuple[str, str]] | None = None, ) -> None: self._dict = {} # type: dict[str, str] if entries is None: @@ -274,7 +277,7 @@ def __contains__(self, item: object) -> bool: def __getitem__(self, key: str) -> str: return self._dict[key] - def __iter__(self) -> typing.Iterator[str]: + def __iter__(self) -> Iterator[str]: return iter(self._dict) def __len__(self) -> int: @@ -287,7 +290,7 @@ def __repr__(self) -> str: ] return str(pairs) - def add(self, key: str, value: str) -> "TraceState": + def add(self, key: str, value: str) -> TraceState: """Adds a key-value pair to tracestate. The provided pair should adhere to w3c tracestate identifiers format. @@ -318,7 +321,7 @@ def add(self, key: str, value: str) -> "TraceState": new_state = [(key, value)] + list(self._dict.items()) return TraceState(new_state) - def update(self, key: str, value: str) -> "TraceState": + def update(self, key: str, value: str) -> TraceState: """Updates a key-value pair in tracestate. The provided pair should adhere to w3c tracestate identifiers format. @@ -343,7 +346,7 @@ def update(self, key: str, value: str) -> "TraceState": new_state = [(key, value), *prev_state.items()] return TraceState(new_state) - def delete(self, key: str) -> "TraceState": + def delete(self, key: str) -> TraceState: """Deletes a key-value from tracestate. Args: @@ -374,7 +377,7 @@ def to_header(self) -> str: return ",".join(key + "=" + value for key, value in self._dict.items()) @classmethod - def from_header(cls, header_list: list[str]) -> "TraceState": + def from_header(cls, header_list: list[str]) -> TraceState: """Parses one or more w3c tracestate header into a TraceState. Args: @@ -413,7 +416,7 @@ def from_header(cls, header_list: list[str]) -> "TraceState": return cls(list(pairs.items())) @classmethod - def get_default(cls) -> "TraceState": + def get_default(cls) -> TraceState: return cls() def keys(self) -> typing.KeysView[str]: @@ -450,9 +453,9 @@ def __new__( trace_id: int, span_id: int, is_remote: bool, - trace_flags: typing.Optional["TraceFlags"] = DEFAULT_TRACE_OPTIONS, - trace_state: typing.Optional["TraceState"] = DEFAULT_TRACE_STATE, - ) -> "SpanContext": + trace_flags: TraceFlags | None = DEFAULT_TRACE_OPTIONS, + trace_state: TraceState | None = DEFAULT_TRACE_STATE, + ) -> SpanContext: if trace_flags is None: trace_flags = DEFAULT_TRACE_OPTIONS if trace_state is None: @@ -470,7 +473,7 @@ def __new__( def __getnewargs__( self, - ) -> tuple[int, int, bool, "TraceFlags", "TraceState"]: + ) -> tuple[int, int, bool, TraceFlags, TraceState]: return ( self.trace_id, self.span_id, @@ -492,11 +495,11 @@ def is_remote(self) -> bool: return self[2] # pylint: disable=unsubscriptable-object @property - def trace_flags(self) -> "TraceFlags": + def trace_flags(self) -> TraceFlags: return self[3] # pylint: disable=unsubscriptable-object @property - def trace_state(self) -> "TraceState": + def trace_state(self) -> TraceState: return self[4] # pylint: disable=unsubscriptable-object @property @@ -523,10 +526,10 @@ class NonRecordingSpan(Span): All operations are no-op except context propagation. """ - def __init__(self, context: "SpanContext") -> None: + def __init__(self, context: SpanContext) -> None: self._context = context - def get_span_context(self) -> "SpanContext": + def get_span_context(self) -> SpanContext: return self._context def is_recording(self) -> bool: @@ -536,7 +539,7 @@ def end(self, end_time: int | None = None) -> None: pass def set_attributes( - self, attributes: typing.Mapping[str, types.AttributeValue] + self, attributes: Mapping[str, types.AttributeValue] ) -> None: pass @@ -553,7 +556,7 @@ def add_event( def add_link( self, - context: "SpanContext", + context: SpanContext, attributes: types.Attributes = None, ) -> None: pass diff --git a/opentelemetry-proto-json/src/opentelemetry/proto_json/_json_codec.py b/opentelemetry-proto-json/src/opentelemetry/proto_json/_json_codec.py index 0a6c7c71968..72c315d1eaa 100644 --- a/opentelemetry-proto-json/src/opentelemetry/proto_json/_json_codec.py +++ b/opentelemetry-proto-json/src/opentelemetry/proto_json/_json_codec.py @@ -5,6 +5,7 @@ import abc import base64 +import collections.abc import json import math import typing @@ -101,7 +102,7 @@ def encode_float(value: float) -> float | str: def encode_repeated( values: list[T] | None, - map_fn: typing.Callable[[T], typing.Any], + map_fn: collections.abc.Callable[[T], typing.Any], ) -> list[typing.Any]: """ Helper to serialize repeated fields with a mapping function. @@ -207,7 +208,7 @@ def decode_float(value: float | int | str | None, field_name: str) -> float: def decode_repeated( values: list[typing.Any] | None, - item_parser: typing.Callable[[typing.Any], T], + item_parser: collections.abc.Callable[[typing.Any], T], field_name: str, ) -> list[T]: """ diff --git a/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/logs/v1/logs_service.py b/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/logs/v1/logs_service.py index c385c366083..899c965fa3c 100644 --- a/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/logs/v1/logs_service.py +++ b/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/logs/v1/logs_service.py @@ -65,7 +65,7 @@ class ExportLogsServiceResponse(opentelemetry.proto_json._json_codec.JsonMessage Generated from protobuf message ExportLogsServiceResponse """ - partial_success: typing.Optional[ExportLogsPartialSuccess] = None + partial_success: ExportLogsPartialSuccess | None = None def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -106,8 +106,8 @@ class ExportLogsPartialSuccess(opentelemetry.proto_json._json_codec.JsonMessage) Generated from protobuf message ExportLogsPartialSuccess """ - rejected_log_records: typing.Optional[builtins.int] = 0 - error_message: typing.Optional[builtins.str] = "" + rejected_log_records: builtins.int | None = 0 + error_message: builtins.str | None = "" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ diff --git a/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/metrics/v1/metrics_service.py b/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/metrics/v1/metrics_service.py index 6478bc0e470..6537d1031f4 100644 --- a/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/metrics/v1/metrics_service.py +++ b/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/metrics/v1/metrics_service.py @@ -65,7 +65,7 @@ class ExportMetricsServiceResponse(opentelemetry.proto_json._json_codec.JsonMess Generated from protobuf message ExportMetricsServiceResponse """ - partial_success: typing.Optional[ExportMetricsPartialSuccess] = None + partial_success: ExportMetricsPartialSuccess | None = None def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -106,8 +106,8 @@ class ExportMetricsPartialSuccess(opentelemetry.proto_json._json_codec.JsonMessa Generated from protobuf message ExportMetricsPartialSuccess """ - rejected_data_points: typing.Optional[builtins.int] = 0 - error_message: typing.Optional[builtins.str] = "" + rejected_data_points: builtins.int | None = 0 + error_message: builtins.str | None = "" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ diff --git a/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/profiles/v1development/profiles_service.py b/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/profiles/v1development/profiles_service.py index 6382389aa4e..faaaa6105c1 100644 --- a/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/profiles/v1development/profiles_service.py +++ b/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/profiles/v1development/profiles_service.py @@ -25,7 +25,7 @@ class ExportProfilesServiceRequest(opentelemetry.proto_json._json_codec.JsonMess """ resource_profiles: builtins.list[opentelemetry.proto_json.profiles.v1development.profiles.ResourceProfiles] = dataclasses.field(default_factory=builtins.list) - dictionary: typing.Optional[opentelemetry.proto_json.profiles.v1development.profiles.ProfilesDictionary] = None + dictionary: opentelemetry.proto_json.profiles.v1development.profiles.ProfilesDictionary | None = None def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -70,7 +70,7 @@ class ExportProfilesServiceResponse(opentelemetry.proto_json._json_codec.JsonMes Generated from protobuf message ExportProfilesServiceResponse """ - partial_success: typing.Optional[ExportProfilesPartialSuccess] = None + partial_success: ExportProfilesPartialSuccess | None = None def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -111,8 +111,8 @@ class ExportProfilesPartialSuccess(opentelemetry.proto_json._json_codec.JsonMess Generated from protobuf message ExportProfilesPartialSuccess """ - rejected_profiles: typing.Optional[builtins.int] = 0 - error_message: typing.Optional[builtins.str] = "" + rejected_profiles: builtins.int | None = 0 + error_message: builtins.str | None = "" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ diff --git a/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/trace/v1/trace_service.py b/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/trace/v1/trace_service.py index 7e93f58b931..27d3a1a1e0a 100644 --- a/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/trace/v1/trace_service.py +++ b/opentelemetry-proto-json/src/opentelemetry/proto_json/collector/trace/v1/trace_service.py @@ -65,7 +65,7 @@ class ExportTraceServiceResponse(opentelemetry.proto_json._json_codec.JsonMessag Generated from protobuf message ExportTraceServiceResponse """ - partial_success: typing.Optional[ExportTracePartialSuccess] = None + partial_success: ExportTracePartialSuccess | None = None def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -106,8 +106,8 @@ class ExportTracePartialSuccess(opentelemetry.proto_json._json_codec.JsonMessage Generated from protobuf message ExportTracePartialSuccess """ - rejected_spans: typing.Optional[builtins.int] = 0 - error_message: typing.Optional[builtins.str] = "" + rejected_spans: builtins.int | None = 0 + error_message: builtins.str | None = "" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ diff --git a/opentelemetry-proto-json/src/opentelemetry/proto_json/common/v1/common.py b/opentelemetry-proto-json/src/opentelemetry/proto_json/common/v1/common.py index 173f315b3ea..6942227f98b 100644 --- a/opentelemetry-proto-json/src/opentelemetry/proto_json/common/v1/common.py +++ b/opentelemetry-proto-json/src/opentelemetry/proto_json/common/v1/common.py @@ -23,14 +23,14 @@ class AnyValue(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message AnyValue """ - string_value: typing.Optional[builtins.str] = None - bool_value: typing.Optional[builtins.bool] = None - int_value: typing.Optional[builtins.int] = None - double_value: typing.Optional[builtins.float] = None - array_value: typing.Optional[ArrayValue] = None - kvlist_value: typing.Optional[KeyValueList] = None - bytes_value: typing.Optional[builtins.bytes] = None - string_value_strindex: typing.Optional[builtins.int] = None + string_value: builtins.str | None = None + bool_value: builtins.bool | None = None + int_value: builtins.int | None = None + double_value: builtins.float | None = None + array_value: ArrayValue | None = None + kvlist_value: KeyValueList | None = None + bytes_value: builtins.bytes | None = None + string_value_strindex: builtins.int | None = None def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -184,9 +184,9 @@ class KeyValue(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message KeyValue """ - key: typing.Optional[builtins.str] = "" - value: typing.Optional[AnyValue] = None - key_strindex: typing.Optional[builtins.int] = 0 + key: builtins.str | None = "" + value: AnyValue | None = None + key_strindex: builtins.int | None = 0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -237,10 +237,10 @@ class InstrumentationScope(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message InstrumentationScope """ - name: typing.Optional[builtins.str] = "" - version: typing.Optional[builtins.str] = "" + name: builtins.str | None = "" + version: builtins.str | None = "" attributes: builtins.list[KeyValue] = dataclasses.field(default_factory=builtins.list) - dropped_attributes_count: typing.Optional[builtins.int] = 0 + dropped_attributes_count: builtins.int | None = 0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -296,8 +296,8 @@ class EntityRef(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message EntityRef """ - schema_url: typing.Optional[builtins.str] = "" - type: typing.Optional[builtins.str] = "" + schema_url: builtins.str | None = "" + type: builtins.str | None = "" id_keys: builtins.list[builtins.str] = dataclasses.field(default_factory=builtins.list) description_keys: builtins.list[builtins.str] = dataclasses.field(default_factory=builtins.list) diff --git a/opentelemetry-proto-json/src/opentelemetry/proto_json/logs/v1/logs.py b/opentelemetry-proto-json/src/opentelemetry/proto_json/logs/v1/logs.py index 3a0bdb19c12..e978df472f3 100644 --- a/opentelemetry-proto-json/src/opentelemetry/proto_json/logs/v1/logs.py +++ b/opentelemetry-proto-json/src/opentelemetry/proto_json/logs/v1/logs.py @@ -108,9 +108,9 @@ class ResourceLogs(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message ResourceLogs """ - resource: typing.Optional[opentelemetry.proto_json.resource.v1.resource.Resource] = None + resource: opentelemetry.proto_json.resource.v1.resource.Resource | None = None scope_logs: builtins.list[ScopeLogs] = dataclasses.field(default_factory=builtins.list) - schema_url: typing.Optional[builtins.str] = "" + schema_url: builtins.str | None = "" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -160,9 +160,9 @@ class ScopeLogs(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message ScopeLogs """ - scope: typing.Optional[opentelemetry.proto_json.common.v1.common.InstrumentationScope] = None + scope: opentelemetry.proto_json.common.v1.common.InstrumentationScope | None = None log_records: builtins.list[LogRecord] = dataclasses.field(default_factory=builtins.list) - schema_url: typing.Optional[builtins.str] = "" + schema_url: builtins.str | None = "" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -212,17 +212,17 @@ class LogRecord(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message LogRecord """ - time_unix_nano: typing.Optional[builtins.int] = 0 - observed_time_unix_nano: typing.Optional[builtins.int] = 0 - severity_number: typing.Union[SeverityNumber, builtins.int, None] = 0 - severity_text: typing.Optional[builtins.str] = "" - body: typing.Optional[opentelemetry.proto_json.common.v1.common.AnyValue] = None + time_unix_nano: builtins.int | None = 0 + observed_time_unix_nano: builtins.int | None = 0 + severity_number: SeverityNumber | builtins.int | None = 0 + severity_text: builtins.str | None = "" + body: opentelemetry.proto_json.common.v1.common.AnyValue | None = None attributes: builtins.list[opentelemetry.proto_json.common.v1.common.KeyValue] = dataclasses.field(default_factory=builtins.list) - dropped_attributes_count: typing.Optional[builtins.int] = 0 - flags: typing.Optional[builtins.int] = 0 - trace_id: typing.Optional[builtins.bytes] = b"" - span_id: typing.Optional[builtins.bytes] = b"" - event_name: typing.Optional[builtins.str] = "" + dropped_attributes_count: builtins.int | None = 0 + flags: builtins.int | None = 0 + trace_id: builtins.bytes | None = b"" + span_id: builtins.bytes | None = b"" + event_name: builtins.str | None = "" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ diff --git a/opentelemetry-proto-json/src/opentelemetry/proto_json/metrics/v1/metrics.py b/opentelemetry-proto-json/src/opentelemetry/proto_json/metrics/v1/metrics.py index 02ebfd6c0d1..a5f63651352 100644 --- a/opentelemetry-proto-json/src/opentelemetry/proto_json/metrics/v1/metrics.py +++ b/opentelemetry-proto-json/src/opentelemetry/proto_json/metrics/v1/metrics.py @@ -86,9 +86,9 @@ class ResourceMetrics(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message ResourceMetrics """ - resource: typing.Optional[opentelemetry.proto_json.resource.v1.resource.Resource] = None + resource: opentelemetry.proto_json.resource.v1.resource.Resource | None = None scope_metrics: builtins.list[ScopeMetrics] = dataclasses.field(default_factory=builtins.list) - schema_url: typing.Optional[builtins.str] = "" + schema_url: builtins.str | None = "" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -138,9 +138,9 @@ class ScopeMetrics(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message ScopeMetrics """ - scope: typing.Optional[opentelemetry.proto_json.common.v1.common.InstrumentationScope] = None + scope: opentelemetry.proto_json.common.v1.common.InstrumentationScope | None = None metrics: builtins.list[Metric] = dataclasses.field(default_factory=builtins.list) - schema_url: typing.Optional[builtins.str] = "" + schema_url: builtins.str | None = "" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -190,14 +190,14 @@ class Metric(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message Metric """ - name: typing.Optional[builtins.str] = "" - description: typing.Optional[builtins.str] = "" - unit: typing.Optional[builtins.str] = "" - gauge: typing.Optional[Gauge] = None - sum: typing.Optional[Sum] = None - histogram: typing.Optional[Histogram] = None - exponential_histogram: typing.Optional[ExponentialHistogram] = None - summary: typing.Optional[Summary] = None + name: builtins.str | None = "" + description: builtins.str | None = "" + unit: builtins.str | None = "" + gauge: Gauge | None = None + sum: Sum | None = None + histogram: Histogram | None = None + exponential_histogram: ExponentialHistogram | None = None + summary: Summary | None = None metadata: builtins.list[opentelemetry.proto_json.common.v1.common.KeyValue] = dataclasses.field(default_factory=builtins.list) def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: @@ -316,8 +316,8 @@ class Sum(opentelemetry.proto_json._json_codec.JsonMessage): """ data_points: builtins.list[NumberDataPoint] = dataclasses.field(default_factory=builtins.list) - aggregation_temporality: typing.Union[AggregationTemporality, builtins.int, None] = 0 - is_monotonic: typing.Optional[builtins.bool] = False + aggregation_temporality: AggregationTemporality | builtins.int | None = 0 + is_monotonic: builtins.bool | None = False def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -369,7 +369,7 @@ class Histogram(opentelemetry.proto_json._json_codec.JsonMessage): """ data_points: builtins.list[HistogramDataPoint] = dataclasses.field(default_factory=builtins.list) - aggregation_temporality: typing.Union[AggregationTemporality, builtins.int, None] = 0 + aggregation_temporality: AggregationTemporality | builtins.int | None = 0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -416,7 +416,7 @@ class ExponentialHistogram(opentelemetry.proto_json._json_codec.JsonMessage): """ data_points: builtins.list[ExponentialHistogramDataPoint] = dataclasses.field(default_factory=builtins.list) - aggregation_temporality: typing.Union[AggregationTemporality, builtins.int, None] = 0 + aggregation_temporality: AggregationTemporality | builtins.int | None = 0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -504,12 +504,12 @@ class NumberDataPoint(opentelemetry.proto_json._json_codec.JsonMessage): """ attributes: builtins.list[opentelemetry.proto_json.common.v1.common.KeyValue] = dataclasses.field(default_factory=builtins.list) - start_time_unix_nano: typing.Optional[builtins.int] = 0 - time_unix_nano: typing.Optional[builtins.int] = 0 - as_double: typing.Optional[builtins.float] = None - as_int: typing.Optional[builtins.int] = None + start_time_unix_nano: builtins.int | None = 0 + time_unix_nano: builtins.int | None = 0 + as_double: builtins.float | None = None + as_int: builtins.int | None = None exemplars: builtins.list[Exemplar] = dataclasses.field(default_factory=builtins.list) - flags: typing.Optional[builtins.int] = 0 + flags: builtins.int | None = 0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -576,16 +576,16 @@ class HistogramDataPoint(opentelemetry.proto_json._json_codec.JsonMessage): """ attributes: builtins.list[opentelemetry.proto_json.common.v1.common.KeyValue] = dataclasses.field(default_factory=builtins.list) - start_time_unix_nano: typing.Optional[builtins.int] = 0 - time_unix_nano: typing.Optional[builtins.int] = 0 - count: typing.Optional[builtins.int] = 0 - sum: typing.Optional[builtins.float] = None + start_time_unix_nano: builtins.int | None = 0 + time_unix_nano: builtins.int | None = 0 + count: builtins.int | None = 0 + sum: builtins.float | None = None bucket_counts: builtins.list[builtins.int] = dataclasses.field(default_factory=builtins.list) explicit_bounds: builtins.list[builtins.float] = dataclasses.field(default_factory=builtins.list) exemplars: builtins.list[Exemplar] = dataclasses.field(default_factory=builtins.list) - flags: typing.Optional[builtins.int] = 0 - min: typing.Optional[builtins.float] = None - max: typing.Optional[builtins.float] = None + flags: builtins.int | None = 0 + min: builtins.float | None = None + max: builtins.float | None = None def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -674,7 +674,7 @@ class Buckets(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message Buckets """ - offset: typing.Optional[builtins.int] = 0 + offset: builtins.int | None = 0 bucket_counts: builtins.list[builtins.int] = dataclasses.field(default_factory=builtins.list) def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: @@ -714,19 +714,19 @@ def from_dict(cls, data: builtins.dict[builtins.str, typing.Any]) -> "Exponentia return cls(**_args) attributes: builtins.list[opentelemetry.proto_json.common.v1.common.KeyValue] = dataclasses.field(default_factory=builtins.list) - start_time_unix_nano: typing.Optional[builtins.int] = 0 - time_unix_nano: typing.Optional[builtins.int] = 0 - count: typing.Optional[builtins.int] = 0 - sum: typing.Optional[builtins.float] = None - scale: typing.Optional[builtins.int] = 0 - zero_count: typing.Optional[builtins.int] = 0 - positive: typing.Optional[ExponentialHistogramDataPoint.Buckets] = None - negative: typing.Optional[ExponentialHistogramDataPoint.Buckets] = None - flags: typing.Optional[builtins.int] = 0 + start_time_unix_nano: builtins.int | None = 0 + time_unix_nano: builtins.int | None = 0 + count: builtins.int | None = 0 + sum: builtins.float | None = None + scale: builtins.int | None = 0 + zero_count: builtins.int | None = 0 + positive: ExponentialHistogramDataPoint.Buckets | None = None + negative: ExponentialHistogramDataPoint.Buckets | None = None + flags: builtins.int | None = 0 exemplars: builtins.list[Exemplar] = dataclasses.field(default_factory=builtins.list) - min: typing.Optional[builtins.float] = None - max: typing.Optional[builtins.float] = None - zero_threshold: typing.Optional[builtins.float] = 0.0 + min: builtins.float | None = None + max: builtins.float | None = None + zero_threshold: builtins.float | None = 0.0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -828,8 +828,8 @@ class ValueAtQuantile(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message ValueAtQuantile """ - quantile: typing.Optional[builtins.float] = 0.0 - value: typing.Optional[builtins.float] = 0.0 + quantile: builtins.float | None = 0.0 + value: builtins.float | None = 0.0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -867,12 +867,12 @@ def from_dict(cls, data: builtins.dict[builtins.str, typing.Any]) -> "SummaryDat return cls(**_args) attributes: builtins.list[opentelemetry.proto_json.common.v1.common.KeyValue] = dataclasses.field(default_factory=builtins.list) - start_time_unix_nano: typing.Optional[builtins.int] = 0 - time_unix_nano: typing.Optional[builtins.int] = 0 - count: typing.Optional[builtins.int] = 0 - sum: typing.Optional[builtins.float] = 0.0 + start_time_unix_nano: builtins.int | None = 0 + time_unix_nano: builtins.int | None = 0 + count: builtins.int | None = 0 + sum: builtins.float | None = 0.0 quantile_values: builtins.list[SummaryDataPoint.ValueAtQuantile] = dataclasses.field(default_factory=builtins.list) - flags: typing.Optional[builtins.int] = 0 + flags: builtins.int | None = 0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -939,11 +939,11 @@ class Exemplar(opentelemetry.proto_json._json_codec.JsonMessage): """ filtered_attributes: builtins.list[opentelemetry.proto_json.common.v1.common.KeyValue] = dataclasses.field(default_factory=builtins.list) - time_unix_nano: typing.Optional[builtins.int] = 0 - as_double: typing.Optional[builtins.float] = None - as_int: typing.Optional[builtins.int] = None - span_id: typing.Optional[builtins.bytes] = b"" - trace_id: typing.Optional[builtins.bytes] = b"" + time_unix_nano: builtins.int | None = 0 + as_double: builtins.float | None = None + as_int: builtins.int | None = None + span_id: builtins.bytes | None = b"" + trace_id: builtins.bytes | None = b"" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ diff --git a/opentelemetry-proto-json/src/opentelemetry/proto_json/profiles/v1development/profiles.py b/opentelemetry-proto-json/src/opentelemetry/proto_json/profiles/v1development/profiles.py index 153f5e45873..3d3bd90d22f 100644 --- a/opentelemetry-proto-json/src/opentelemetry/proto_json/profiles/v1development/profiles.py +++ b/opentelemetry-proto-json/src/opentelemetry/proto_json/profiles/v1development/profiles.py @@ -97,7 +97,7 @@ class ProfilesData(opentelemetry.proto_json._json_codec.JsonMessage): """ resource_profiles: builtins.list[ResourceProfiles] = dataclasses.field(default_factory=builtins.list) - dictionary: typing.Optional[ProfilesDictionary] = None + dictionary: ProfilesDictionary | None = None def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -142,9 +142,9 @@ class ResourceProfiles(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message ResourceProfiles """ - resource: typing.Optional[opentelemetry.proto_json.resource.v1.resource.Resource] = None + resource: opentelemetry.proto_json.resource.v1.resource.Resource | None = None scope_profiles: builtins.list[ScopeProfiles] = dataclasses.field(default_factory=builtins.list) - schema_url: typing.Optional[builtins.str] = "" + schema_url: builtins.str | None = "" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -194,9 +194,9 @@ class ScopeProfiles(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message ScopeProfiles """ - scope: typing.Optional[opentelemetry.proto_json.common.v1.common.InstrumentationScope] = None + scope: opentelemetry.proto_json.common.v1.common.InstrumentationScope | None = None profiles: builtins.list[Profile] = dataclasses.field(default_factory=builtins.list) - schema_url: typing.Optional[builtins.str] = "" + schema_url: builtins.str | None = "" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -246,16 +246,16 @@ class Profile(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message Profile """ - sample_type: typing.Optional[ValueType] = None + sample_type: ValueType | None = None samples: builtins.list[Sample] = dataclasses.field(default_factory=builtins.list) - time_unix_nano: typing.Optional[builtins.int] = 0 - duration_nano: typing.Optional[builtins.int] = 0 - period_type: typing.Optional[ValueType] = None - period: typing.Optional[builtins.int] = 0 - profile_id: typing.Optional[builtins.bytes] = b"" - dropped_attributes_count: typing.Optional[builtins.int] = 0 - original_payload_format: typing.Optional[builtins.str] = "" - original_payload: typing.Optional[builtins.bytes] = b"" + time_unix_nano: builtins.int | None = 0 + duration_nano: builtins.int | None = 0 + period_type: ValueType | None = None + period: builtins.int | None = 0 + profile_id: builtins.bytes | None = b"" + dropped_attributes_count: builtins.int | None = 0 + original_payload_format: builtins.str | None = "" + original_payload: builtins.bytes | None = b"" attribute_indices: builtins.list[builtins.int] = dataclasses.field(default_factory=builtins.list) def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: @@ -339,8 +339,8 @@ class Link(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message Link """ - trace_id: typing.Optional[builtins.bytes] = b"" - span_id: typing.Optional[builtins.bytes] = b"" + trace_id: builtins.bytes | None = b"" + span_id: builtins.bytes | None = b"" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -385,8 +385,8 @@ class ValueType(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message ValueType """ - type_strindex: typing.Optional[builtins.int] = 0 - unit_strindex: typing.Optional[builtins.int] = 0 + type_strindex: builtins.int | None = 0 + unit_strindex: builtins.int | None = 0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -433,9 +433,9 @@ class Sample(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message Sample """ - stack_index: typing.Optional[builtins.int] = 0 + stack_index: builtins.int | None = 0 attribute_indices: builtins.list[builtins.int] = dataclasses.field(default_factory=builtins.list) - link_index: typing.Optional[builtins.int] = 0 + link_index: builtins.int | None = 0 values: builtins.list[builtins.int] = dataclasses.field(default_factory=builtins.list) timestamps_unix_nano: builtins.list[builtins.int] = dataclasses.field(default_factory=builtins.list) @@ -496,10 +496,10 @@ class Mapping(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message Mapping """ - memory_start: typing.Optional[builtins.int] = 0 - memory_limit: typing.Optional[builtins.int] = 0 - file_offset: typing.Optional[builtins.int] = 0 - filename_strindex: typing.Optional[builtins.int] = 0 + memory_start: builtins.int | None = 0 + memory_limit: builtins.int | None = 0 + file_offset: builtins.int | None = 0 + filename_strindex: builtins.int | None = 0 attribute_indices: builtins.list[builtins.int] = dataclasses.field(default_factory=builtins.list) def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: @@ -599,8 +599,8 @@ class Location(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message Location """ - mapping_index: typing.Optional[builtins.int] = 0 - address: typing.Optional[builtins.int] = 0 + mapping_index: builtins.int | None = 0 + address: builtins.int | None = 0 lines: builtins.list[Line] = dataclasses.field(default_factory=builtins.list) attribute_indices: builtins.list[builtins.int] = dataclasses.field(default_factory=builtins.list) @@ -656,9 +656,9 @@ class Line(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message Line """ - function_index: typing.Optional[builtins.int] = 0 - line: typing.Optional[builtins.int] = 0 - column: typing.Optional[builtins.int] = 0 + function_index: builtins.int | None = 0 + line: builtins.int | None = 0 + column: builtins.int | None = 0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -708,10 +708,10 @@ class Function(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message Function """ - name_strindex: typing.Optional[builtins.int] = 0 - system_name_strindex: typing.Optional[builtins.int] = 0 - filename_strindex: typing.Optional[builtins.int] = 0 - start_line: typing.Optional[builtins.int] = 0 + name_strindex: builtins.int | None = 0 + system_name_strindex: builtins.int | None = 0 + filename_strindex: builtins.int | None = 0 + start_line: builtins.int | None = 0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -767,9 +767,9 @@ class KeyValueAndUnit(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message KeyValueAndUnit """ - key_strindex: typing.Optional[builtins.int] = 0 - value: typing.Optional[opentelemetry.proto_json.common.v1.common.AnyValue] = None - unit_strindex: typing.Optional[builtins.int] = 0 + key_strindex: builtins.int | None = 0 + value: opentelemetry.proto_json.common.v1.common.AnyValue | None = None + unit_strindex: builtins.int | None = 0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ diff --git a/opentelemetry-proto-json/src/opentelemetry/proto_json/resource/v1/resource.py b/opentelemetry-proto-json/src/opentelemetry/proto_json/resource/v1/resource.py index 664a42ef121..3c76082759f 100644 --- a/opentelemetry-proto-json/src/opentelemetry/proto_json/resource/v1/resource.py +++ b/opentelemetry-proto-json/src/opentelemetry/proto_json/resource/v1/resource.py @@ -25,7 +25,7 @@ class Resource(opentelemetry.proto_json._json_codec.JsonMessage): """ attributes: builtins.list[opentelemetry.proto_json.common.v1.common.KeyValue] = dataclasses.field(default_factory=builtins.list) - dropped_attributes_count: typing.Optional[builtins.int] = 0 + dropped_attributes_count: builtins.int | None = 0 entity_refs: builtins.list[opentelemetry.proto_json.common.v1.common.EntityRef] = dataclasses.field(default_factory=builtins.list) def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: diff --git a/opentelemetry-proto-json/src/opentelemetry/proto_json/trace/v1/trace.py b/opentelemetry-proto-json/src/opentelemetry/proto_json/trace/v1/trace.py index 5afa5a66ac9..16112213715 100644 --- a/opentelemetry-proto-json/src/opentelemetry/proto_json/trace/v1/trace.py +++ b/opentelemetry-proto-json/src/opentelemetry/proto_json/trace/v1/trace.py @@ -78,9 +78,9 @@ class ResourceSpans(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message ResourceSpans """ - resource: typing.Optional[opentelemetry.proto_json.resource.v1.resource.Resource] = None + resource: opentelemetry.proto_json.resource.v1.resource.Resource | None = None scope_spans: builtins.list[ScopeSpans] = dataclasses.field(default_factory=builtins.list) - schema_url: typing.Optional[builtins.str] = "" + schema_url: builtins.str | None = "" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -130,9 +130,9 @@ class ScopeSpans(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message ScopeSpans """ - scope: typing.Optional[opentelemetry.proto_json.common.v1.common.InstrumentationScope] = None + scope: opentelemetry.proto_json.common.v1.common.InstrumentationScope | None = None spans: builtins.list[Span] = dataclasses.field(default_factory=builtins.list) - schema_url: typing.Optional[builtins.str] = "" + schema_url: builtins.str | None = "" def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -202,10 +202,10 @@ class Event(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message Event """ - time_unix_nano: typing.Optional[builtins.int] = 0 - name: typing.Optional[builtins.str] = "" + time_unix_nano: builtins.int | None = 0 + name: builtins.str | None = "" attributes: builtins.list[opentelemetry.proto_json.common.v1.common.KeyValue] = dataclasses.field(default_factory=builtins.list) - dropped_attributes_count: typing.Optional[builtins.int] = 0 + dropped_attributes_count: builtins.int | None = 0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -259,12 +259,12 @@ class Link(opentelemetry.proto_json._json_codec.JsonMessage): Generated from protobuf message Link """ - trace_id: typing.Optional[builtins.bytes] = b"" - span_id: typing.Optional[builtins.bytes] = b"" - trace_state: typing.Optional[builtins.str] = "" + trace_id: builtins.bytes | None = b"" + span_id: builtins.bytes | None = b"" + trace_state: builtins.str | None = "" attributes: builtins.list[opentelemetry.proto_json.common.v1.common.KeyValue] = dataclasses.field(default_factory=builtins.list) - dropped_attributes_count: typing.Optional[builtins.int] = 0 - flags: typing.Optional[builtins.int] = 0 + dropped_attributes_count: builtins.int | None = 0 + flags: builtins.int | None = 0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -320,22 +320,22 @@ def from_dict(cls, data: builtins.dict[builtins.str, typing.Any]) -> "Span.Link" return cls(**_args) - trace_id: typing.Optional[builtins.bytes] = b"" - span_id: typing.Optional[builtins.bytes] = b"" - trace_state: typing.Optional[builtins.str] = "" - parent_span_id: typing.Optional[builtins.bytes] = b"" - flags: typing.Optional[builtins.int] = 0 - name: typing.Optional[builtins.str] = "" - kind: typing.Union[Span.SpanKind, builtins.int, None] = 0 - start_time_unix_nano: typing.Optional[builtins.int] = 0 - end_time_unix_nano: typing.Optional[builtins.int] = 0 + trace_id: builtins.bytes | None = b"" + span_id: builtins.bytes | None = b"" + trace_state: builtins.str | None = "" + parent_span_id: builtins.bytes | None = b"" + flags: builtins.int | None = 0 + name: builtins.str | None = "" + kind: Span.SpanKind | builtins.int | None = 0 + start_time_unix_nano: builtins.int | None = 0 + end_time_unix_nano: builtins.int | None = 0 attributes: builtins.list[opentelemetry.proto_json.common.v1.common.KeyValue] = dataclasses.field(default_factory=builtins.list) - dropped_attributes_count: typing.Optional[builtins.int] = 0 + dropped_attributes_count: builtins.int | None = 0 events: builtins.list[Span.Event] = dataclasses.field(default_factory=builtins.list) - dropped_events_count: typing.Optional[builtins.int] = 0 + dropped_events_count: builtins.int | None = 0 links: builtins.list[Span.Link] = dataclasses.field(default_factory=builtins.list) - dropped_links_count: typing.Optional[builtins.int] = 0 - status: typing.Optional[Status] = None + dropped_links_count: builtins.int | None = 0 + status: Status | None = None def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ @@ -453,8 +453,8 @@ class StatusCode(enum.IntEnum): STATUS_CODE_OK = 1 STATUS_CODE_ERROR = 2 - message: typing.Optional[builtins.str] = "" - code: typing.Union[Status.StatusCode, builtins.int, None] = 0 + message: builtins.str | None = "" + code: Status.StatusCode | builtins.int | None = 0 def to_dict(self) -> builtins.dict[builtins.str, typing.Any]: """ diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index b6b1ce88f69..74b759c328c 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -11,16 +11,13 @@ import threading import traceback import warnings +from collections.abc import Callable from dataclasses import dataclass, field from os import environ from threading import Lock from time import time_ns from typing import ( # noqa Any, - Callable, - Sequence, - Tuple, - Union, cast, overload, ) @@ -381,7 +378,7 @@ class SynchronousMultiLogRecordProcessor(LogRecordProcessor): def __init__(self): # use a tuple to avoid race conditions when adding a new log and # iterating through it on "emit". - self._log_record_processors = () # type: Tuple[LogRecordProcessor, ...] + self._log_record_processors = () # type: tuple[LogRecordProcessor, ...] self._lock = threading.Lock() def add_log_record_processor( @@ -441,7 +438,7 @@ class ConcurrentMultiLogRecordProcessor(LogRecordProcessor): def __init__(self, max_workers: int = 2): # use a tuple to avoid race conditions when adding a new log and # iterating through it on "emit". - self._log_record_processors = () # type: Tuple[LogRecordProcessor, ...] + self._log_record_processors = () # type: tuple[LogRecordProcessor, ...] self._lock = threading.Lock() self._executor = concurrent.futures.ThreadPoolExecutor( max_workers=max_workers diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/export/in_memory_log_exporter.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/export/in_memory_log_exporter.py index 1f793745458..d67e9470c6b 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/export/in_memory_log_exporter.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/export/in_memory_log_exporter.py @@ -1,8 +1,8 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +import collections.abc import threading -import typing from typing_extensions import deprecated @@ -35,7 +35,7 @@ def get_finished_logs(self) -> tuple[ReadableLogRecord, ...]: return tuple(self._logs) def export( - self, batch: typing.Sequence[ReadableLogRecord] + self, batch: collections.abc.Sequence[ReadableLogRecord] ) -> LogRecordExportResult: if self._stopped: return LogRecordExportResult.FAILURE diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py index 6585741a58f..09120f71498 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py @@ -56,9 +56,8 @@ import socket import sys import threading -import typing import uuid -from collections.abc import Sequence +from collections.abc import Mapping, Sequence from json import dumps from os import environ from types import ModuleType @@ -87,7 +86,7 @@ pass LabelValue = AttributeValue -Attributes = typing.Mapping[str, LabelValue] +Attributes = Mapping[str, LabelValue] logger = logging.getLogger(__name__) CLOUD_PROVIDER = ResourceAttributes.CLOUD_PROVIDER diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py index d1477843812..067fb3ded32 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations +import collections.abc import logging import sys import typing @@ -63,7 +64,9 @@ class SpanExporter: `SimpleSpanProcessor` or a `BatchSpanProcessor`. """ - def export(self, spans: typing.Sequence[ReadableSpan]) -> SpanExportResult: # pyright: ignore[reportReturnType] + def export( + self, spans: collections.abc.Sequence[ReadableSpan] + ) -> SpanExportResult: # pyright: ignore[reportReturnType] """Exports a batch of telemetry data. Args: @@ -328,15 +331,17 @@ def __init__( self, service_name: str | None = None, out: typing.IO = sys.stdout, - formatter: typing.Callable[[ReadableSpan], str] = lambda span: ( - span.to_json() + linesep - ), + formatter: collections.abc.Callable[ + [ReadableSpan], str + ] = lambda span: (span.to_json() + linesep), ): self.out = out self.formatter = formatter self.service_name = service_name - def export(self, spans: typing.Sequence[ReadableSpan]) -> SpanExportResult: + def export( + self, spans: collections.abc.Sequence[ReadableSpan] + ) -> SpanExportResult: for span in spans: self.out.write(self.formatter(span)) self.out.flush() diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/in_memory_span_exporter.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/in_memory_span_exporter.py index 25a66294659..ec64e7372f6 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/in_memory_span_exporter.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/in_memory_span_exporter.py @@ -1,8 +1,8 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +import collections.abc import threading -import typing from opentelemetry.sdk.trace import ReadableSpan from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult @@ -31,7 +31,9 @@ def get_finished_spans(self) -> tuple[ReadableSpan, ...]: with self._lock: return tuple(self._finished_spans) - def export(self, spans: typing.Sequence[ReadableSpan]) -> SpanExportResult: + def export( + self, spans: collections.abc.Sequence[ReadableSpan] + ) -> SpanExportResult: """Stores a list of spans in memory.""" if self._stopped: return SpanExportResult.FAILURE diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py index 27cd4a0d620..1652220dfc9 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py @@ -1,6 +1,7 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 + """ For general information about sampling, see `the specification `_. @@ -121,13 +122,14 @@ def get_sampler(sampler_argument): above sampler, set ``OTEL_TRACES_SAMPLER=custom_sampler_name`` and ``OTEL_TRACES_SAMPLER_ARG=0.5``. """ +from __future__ import annotations + import abc import enum import os from collections.abc import Sequence from logging import getLogger from types import MappingProxyType -from typing import Optional # pylint: disable=unused-import from opentelemetry.context import Context @@ -174,8 +176,8 @@ def __repr__(self) -> str: def __init__( self, decision: Decision, - attributes: "Attributes" = None, - trace_state: Optional["TraceState"] = None, + attributes: Attributes = None, + trace_state: TraceState | None = None, ) -> None: self.decision = decision if attributes is None: @@ -189,14 +191,14 @@ class Sampler(abc.ABC): @abc.abstractmethod def should_sample( self, - parent_context: Optional["Context"], + parent_context: Context | None, trace_id: int, name: str, kind: SpanKind | None = None, attributes: Attributes = None, - links: Sequence["Link"] | None = None, - trace_state: Optional["TraceState"] = None, - ) -> "SamplingResult": + links: Sequence[Link] | None = None, + trace_state: TraceState | None = None, + ) -> SamplingResult: pass @abc.abstractmethod @@ -207,19 +209,19 @@ def get_description(self) -> str: class StaticSampler(Sampler): """Sampler that always returns the same decision.""" - def __init__(self, decision: "Decision") -> None: + def __init__(self, decision: Decision) -> None: self._decision = decision def should_sample( self, - parent_context: Optional["Context"], + parent_context: Context | None, trace_id: int, name: str, kind: SpanKind | None = None, attributes: Attributes = None, - links: Sequence["Link"] | None = None, - trace_state: Optional["TraceState"] = None, - ) -> "SamplingResult": + links: Sequence[Link] | None = None, + trace_state: TraceState | None = None, + ) -> SamplingResult: if self._decision is Decision.DROP: attributes = None return SamplingResult( @@ -273,14 +275,14 @@ def bound(self) -> int: def should_sample( self, - parent_context: Optional["Context"], + parent_context: Context | None, trace_id: int, name: str, kind: SpanKind | None = None, attributes: Attributes = None, - links: Sequence["Link"] | None = None, - trace_state: Optional["TraceState"] = None, - ) -> "SamplingResult": + links: Sequence[Link] | None = None, + trace_state: TraceState | None = None, + ) -> SamplingResult: decision = Decision.DROP if trace_id & self.TRACE_ID_LIMIT < self.bound: decision = Decision.RECORD_AND_SAMPLE @@ -328,14 +330,14 @@ def __init__( def should_sample( self, - parent_context: Optional["Context"], + parent_context: Context | None, trace_id: int, name: str, kind: SpanKind | None = None, attributes: Attributes = None, - links: Sequence["Link"] | None = None, - trace_state: Optional["TraceState"] = None, - ) -> "SamplingResult": + links: Sequence[Link] | None = None, + trace_state: TraceState | None = None, + ) -> SamplingResult: parent_span_context = get_current_span( parent_context ).get_span_context() @@ -436,7 +438,7 @@ def _get_from_env_or_default() -> Sampler: def _get_parent_trace_state( parent_context: Context | None, -) -> Optional["TraceState"]: +) -> TraceState | None: parent_span_context = get_current_span(parent_context).get_span_context() if parent_span_context is None or not parent_span_context.is_valid: return None diff --git a/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/__init__.py b/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/__init__.py index 3c4de0cbf0f..025a2b5dc5b 100644 --- a/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/__init__.py +++ b/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/__init__.py @@ -1,7 +1,7 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -import typing +import collections.abc from re import compile as re_compile from typing_extensions import deprecated @@ -191,7 +191,7 @@ def __init__(self, *args, **kwargs): def _extract_first_element( - items: typing.Iterable[CarrierT], + items: collections.abc.Iterable[CarrierT], ) -> CarrierT | None: if items is None: return None diff --git a/propagator/opentelemetry-propagator-jaeger/src/opentelemetry/propagators/jaeger/__init__.py b/propagator/opentelemetry-propagator-jaeger/src/opentelemetry/propagators/jaeger/__init__.py index 52551695220..79bb1d89ea8 100644 --- a/propagator/opentelemetry-propagator-jaeger/src/opentelemetry/propagators/jaeger/__init__.py +++ b/propagator/opentelemetry-propagator-jaeger/src/opentelemetry/propagators/jaeger/__init__.py @@ -1,7 +1,7 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -import typing +import collections.abc import urllib.parse from opentelemetry import baggage, trace @@ -122,7 +122,7 @@ def _format_uber_trace_id(trace_id, span_id, parent_span_id, flags): def _extract_first_element( - items: typing.Iterable[CarrierT], + items: collections.abc.Iterable[CarrierT], ) -> CarrierT | None: if items is None: return None @@ -130,7 +130,7 @@ def _extract_first_element( def _parse_trace_id_header( - items: typing.Iterable[CarrierT], + items: collections.abc.Iterable[CarrierT], ) -> tuple[int]: invalid_header_result = (trace.INVALID_TRACE_ID, trace.INVALID_SPAN_ID, 0)