From 57a6fb36e8cbd867b100308fea7d1f9deaa33b02 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 24 Dec 2024 09:15:09 +0100 Subject: [PATCH] Move the Optional out of LogAttributes --- .../src/opentelemetry/_logs/_internal/__init__.py | 14 +++++++------- opentelemetry-api/src/opentelemetry/util/types.py | 2 +- opentelemetry-api/tests/logs/test_proxy.py | 2 +- .../opentelemetry/sdk/_logs/_internal/__init__.py | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py b/opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py index 93de2fc2d8..de03cd636d 100644 --- a/opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py +++ b/opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py @@ -67,7 +67,7 @@ def __init__( severity_text: Optional[str] = None, severity_number: Optional[SeverityNumber] = None, body: AnyValue = None, - attributes: LogAttributes = None, + attributes: Optional[LogAttributes] = None, ): self.timestamp = timestamp if observed_timestamp is None: @@ -90,7 +90,7 @@ def __init__( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, - attributes: LogAttributes = None, + attributes: Optional[LogAttributes] = None, ) -> None: super().__init__() self._name = name @@ -119,7 +119,7 @@ def __init__( # pylint: disable=super-init-not-called name: str, version: Optional[str] = None, schema_url: Optional[str] = None, - attributes: LogAttributes = None, + attributes: Optional[LogAttributes] = None, ): self._name = name self._version = version @@ -158,7 +158,7 @@ def get_logger( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, - attributes: LogAttributes = None, + attributes: Optional[LogAttributes] = None, ) -> Logger: """Returns a `Logger` for use by the given instrumentation library. @@ -196,7 +196,7 @@ def get_logger( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, - attributes: LogAttributes = None, + attributes: Optional[LogAttributes] = None, ) -> Logger: """Returns a NoOpLogger.""" return NoOpLogger( @@ -210,7 +210,7 @@ def get_logger( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, - attributes: LogAttributes = None, + attributes: Optional[LogAttributes] = None, ) -> Logger: if _LOGGER_PROVIDER: return _LOGGER_PROVIDER.get_logger( @@ -273,7 +273,7 @@ def get_logger( instrumenting_library_version: str = "", logger_provider: Optional[LoggerProvider] = None, schema_url: Optional[str] = None, - attributes: LogAttributes = None, + attributes: Optional[LogAttributes] = None, ) -> "Logger": """Returns a `Logger` for use within a python process. diff --git a/opentelemetry-api/src/opentelemetry/util/types.py b/opentelemetry-api/src/opentelemetry/util/types.py index 7598e1d653..904b77c18f 100644 --- a/opentelemetry-api/src/opentelemetry/util/types.py +++ b/opentelemetry-api/src/opentelemetry/util/types.py @@ -57,4 +57,4 @@ ..., ] -LogAttributes = Optional[Mapping[str, "AnyValue"]] +LogAttributes = Mapping[str, "AnyValue"] diff --git a/opentelemetry-api/tests/logs/test_proxy.py b/opentelemetry-api/tests/logs/test_proxy.py index e4a46451f0..512754df89 100644 --- a/opentelemetry-api/tests/logs/test_proxy.py +++ b/opentelemetry-api/tests/logs/test_proxy.py @@ -28,7 +28,7 @@ def get_logger( name: str, version: typing.Optional[str] = None, schema_url: typing.Optional[str] = None, - attributes: LogAttributes = None, + attributes: typing.Optional[LogAttributes] = None, ) -> _logs.Logger: return LoggerTest(name) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 29060bf38f..a94218b120 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -181,7 +181,7 @@ def __init__( severity_number: Optional[SeverityNumber] = None, body: AnyValue = None, resource: Optional[Resource] = None, - attributes: LogAttributes = None, + attributes: Optional[LogAttributes] = None, limits: Optional[LogLimits] = _UnsetLogLimits, ): super().__init__( @@ -633,7 +633,7 @@ def _get_logger_no_cache( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, - attributes: LogAttributes = None, + attributes: Optional[LogAttributes] = None, ) -> Logger: return Logger( self._resource, @@ -667,7 +667,7 @@ def get_logger( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, - attributes: LogAttributes = None, + attributes: Optional[LogAttributes] = None, ) -> Logger: if self._disabled: warnings.warn("SDK is disabled.")