diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d0a605580d..05ae64c1531 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- optional scope attributes for logger creation + ([#4035](https://github.com/open-telemetry/opentelemetry-python/pull/4035)) - optional scope attribute for tracer creation ([#4028](https://github.com/open-telemetry/opentelemetry-python/pull/4028)) - OTLP exporter is encoding invalid span/trace IDs in the logs fix @@ -50,6 +52,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3991](https://github.com/open-telemetry/opentelemetry-python/pull/3991)) - Add attributes field in `MeterProvider.get_meter` and `InstrumentationScope` ([#4015](https://github.com/open-telemetry/opentelemetry-python/pull/4015)) +- Fix inaccessible `SCHEMA_URL` constants in `opentelemetry-semantic-conventions` + ([#4069](https://github.com/open-telemetry/opentelemetry-python/pull/4069)) ## Version 1.25.0/0.46b0 (2024-05-30) diff --git a/README.md b/README.md index 3bf66016dea..b9820add973 100644 --- a/README.md +++ b/README.md @@ -80,9 +80,7 @@ this repository and perform an [editable install](https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs): ```sh -pip install -e ./opentelemetry-api -pip install -e ./opentelemetry-sdk -pip install -e ./instrumentation/opentelemetry-instrumentation-{instrumentation} +pip install -e ./opentelemetry-api -e ./opentelemetry-sdk -e ./opentelemetry-semantic-conventions ``` For additional exporter and instrumentation packages, see the diff --git a/opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py b/opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py index c02f0bb3dd4..f20bd8507e5 100644 --- a/opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py +++ b/opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py @@ -90,11 +90,13 @@ def __init__( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, + attributes: Optional[Attributes] = None, ) -> None: super().__init__() self._name = name self._version = version self._schema_url = schema_url + self._attributes = attributes @abstractmethod def emit(self, record: "LogRecord") -> None: @@ -117,10 +119,12 @@ def __init__( # pylint: disable=super-init-not-called name: str, version: Optional[str] = None, schema_url: Optional[str] = None, + attributes: Optional[Attributes] = None, ): self._name = name self._version = version self._schema_url = schema_url + self._attributes = attributes self._real_logger: Optional[Logger] = None self._noop_logger = NoOpLogger(name) @@ -134,6 +138,7 @@ def _logger(self) -> Logger: self._name, self._version, self._schema_url, + self._attributes, ) return self._real_logger return self._noop_logger @@ -153,6 +158,7 @@ def get_logger( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, + attributes: Optional[Attributes] = None, ) -> Logger: """Returns a `Logger` for use by the given instrumentation library. @@ -190,9 +196,12 @@ def get_logger( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, + attributes: Optional[Attributes] = None, ) -> Logger: """Returns a NoOpLogger.""" - return NoOpLogger(name, version=version, schema_url=schema_url) + return NoOpLogger( + name, version=version, schema_url=schema_url, attributes=attributes + ) class ProxyLoggerProvider(LoggerProvider): @@ -201,17 +210,20 @@ def get_logger( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, + attributes: Optional[Attributes] = None, ) -> Logger: if _LOGGER_PROVIDER: return _LOGGER_PROVIDER.get_logger( name, version=version, schema_url=schema_url, + attributes=attributes, ) return ProxyLogger( name, version=version, schema_url=schema_url, + attributes=attributes, ) @@ -261,6 +273,7 @@ def get_logger( instrumenting_library_version: str = "", logger_provider: Optional[LoggerProvider] = None, schema_url: Optional[str] = None, + attributes: Optional[Attributes] = None, ) -> "Logger": """Returns a `Logger` for use within a python process. @@ -272,5 +285,8 @@ def get_logger( if logger_provider is None: logger_provider = get_logger_provider() return logger_provider.get_logger( - instrumenting_module_name, instrumenting_library_version, schema_url + instrumenting_module_name, + instrumenting_library_version, + schema_url, + attributes, ) diff --git a/opentelemetry-api/tests/logs/test_proxy.py b/opentelemetry-api/tests/logs/test_proxy.py index 9508a66327d..8e87ceb96ea 100644 --- a/opentelemetry-api/tests/logs/test_proxy.py +++ b/opentelemetry-api/tests/logs/test_proxy.py @@ -19,6 +19,7 @@ import opentelemetry._logs._internal as _logs_internal from opentelemetry import _logs from opentelemetry.test.globals_test import LoggingGlobalsTest +from opentelemetry.util.types import Attributes class TestProvider(_logs.NoOpLoggerProvider): @@ -27,6 +28,7 @@ def get_logger( name: str, version: typing.Optional[str] = None, schema_url: typing.Optional[str] = None, + attributes: typing.Optional[Attributes] = 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 81103ea1638..89432d5b339 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -597,6 +597,7 @@ def __init__( instrumentation_scope.name, instrumentation_scope.version, instrumentation_scope.schema_url, + instrumentation_scope.attributes, ) self._resource = resource self._multi_log_record_processor = multi_log_record_processor @@ -646,10 +647,16 @@ def get_logger( name: str, version: Optional[str] = None, schema_url: Optional[str] = None, + attributes: Optional[Attributes] = None, ) -> Logger: if self._disabled: _logger.warning("SDK is disabled.") - return NoOpLogger(name, version=version, schema_url=schema_url) + return NoOpLogger( + name, + version=version, + schema_url=schema_url, + attributes=attributes, + ) return Logger( self._resource, self._multi_log_record_processor, @@ -657,6 +664,7 @@ def get_logger( name, version, schema_url, + attributes, ), ) diff --git a/opentelemetry-sdk/tests/logs/test_logs.py b/opentelemetry-sdk/tests/logs/test_logs.py index 71098531d4f..4cb2a46c00c 100644 --- a/opentelemetry-sdk/tests/logs/test_logs.py +++ b/opentelemetry-sdk/tests/logs/test_logs.py @@ -55,6 +55,7 @@ def test_get_logger(self): "name", version="version", schema_url="schema_url", + attributes={"key": "value"}, ) self.assertEqual(logger._instrumentation_scope.name, "name") @@ -62,6 +63,9 @@ def test_get_logger(self): self.assertEqual( logger._instrumentation_scope.schema_url, "schema_url" ) + self.assertEqual( + logger._instrumentation_scope.attributes, {"key": "value"} + ) @patch.dict("os.environ", {OTEL_SDK_DISABLED: "true"}) def test_get_logger_with_sdk_disabled(self): diff --git a/opentelemetry-semantic-conventions/src/opentelemetry/semconv/metrics/__init__.py b/opentelemetry-semantic-conventions/src/opentelemetry/semconv/metrics/__init__.py index ce388fbe828..bad7b745f79 100644 --- a/opentelemetry-semantic-conventions/src/opentelemetry/semconv/metrics/__init__.py +++ b/opentelemetry-semantic-conventions/src/opentelemetry/semconv/metrics/__init__.py @@ -20,7 +20,7 @@ reason="Use metrics defined in the :py:const:`opentelemetry.semconv.metrics` and :py:const:`opentelemetry.semconv._incubating.metrics` modules instead.", ) # type: ignore class MetricInstruments: - SCHEMA_URL = "https://opentelemetry.io/schemas/v1.21.0" + SCHEMA_URL = "https://opentelemetry.io/schemas/1.21.0" """ The URL of the OpenTelemetry schema for these keys and values. """ diff --git a/opentelemetry-semantic-conventions/src/opentelemetry/semconv/resource/__init__.py b/opentelemetry-semantic-conventions/src/opentelemetry/semconv/resource/__init__.py index 4015b207670..75496e02ce7 100644 --- a/opentelemetry-semantic-conventions/src/opentelemetry/semconv/resource/__init__.py +++ b/opentelemetry-semantic-conventions/src/opentelemetry/semconv/resource/__init__.py @@ -24,7 +24,7 @@ reason="Use attributes defined in the :py:const:`opentelemetry.semconv.attributes` and :py:const:`opentelemetry.semconv._incubating.attributes` modules instead.", ) # type: ignore class ResourceAttributes: - SCHEMA_URL = "https://opentelemetry.io/schemas/v1.21.0" + SCHEMA_URL = "https://opentelemetry.io/schemas/1.21.0" """ The URL of the OpenTelemetry schema for these keys and values. """ diff --git a/opentelemetry-semantic-conventions/src/opentelemetry/semconv/schemas.py b/opentelemetry-semantic-conventions/src/opentelemetry/semconv/schemas.py index 9af106cef99..0e45ae806b5 100644 --- a/opentelemetry-semantic-conventions/src/opentelemetry/semconv/schemas.py +++ b/opentelemetry-semantic-conventions/src/opentelemetry/semconv/schemas.py @@ -21,14 +21,14 @@ class Schemas(Enum): The URL of the OpenTelemetry schema version 1.23.1. """ - V1_25_0 = "https://opentelemetry.io/schemas/v1.25.0" + V1_25_0 = "https://opentelemetry.io/schemas/1.25.0" """ - The URL of the OpenTelemetry schema version v1.25.0. + The URL of the OpenTelemetry schema version 1.25.0. """ - V1_26_0 = "https://opentelemetry.io/schemas/v1.26.0" + V1_26_0 = "https://opentelemetry.io/schemas/1.26.0" """ - The URL of the OpenTelemetry schema version v1.26.0. + The URL of the OpenTelemetry schema version 1.26.0. """ # when generating new semantic conventions, diff --git a/opentelemetry-semantic-conventions/src/opentelemetry/semconv/trace/__init__.py b/opentelemetry-semantic-conventions/src/opentelemetry/semconv/trace/__init__.py index ee63258a05a..299d3db0a87 100644 --- a/opentelemetry-semantic-conventions/src/opentelemetry/semconv/trace/__init__.py +++ b/opentelemetry-semantic-conventions/src/opentelemetry/semconv/trace/__init__.py @@ -24,7 +24,7 @@ reason="Use attributes defined in the :py:const:`opentelemetry.semconv.attributes` and :py:const:`opentelemetry.semconv._incubating.attributes` modules instead.", ) # type: ignore class SpanAttributes: - SCHEMA_URL = "https://opentelemetry.io/schemas/v1.21.0" + SCHEMA_URL = "https://opentelemetry.io/schemas/1.21.0" """ The URL of the OpenTelemetry schema for these keys and values. """ diff --git a/scripts/semconv/generate.sh b/scripts/semconv/generate.sh index 12efd2b0b1e..8c5dbdbea1b 100755 --- a/scripts/semconv/generate.sh +++ b/scripts/semconv/generate.sh @@ -5,8 +5,9 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" ROOT_DIR="${SCRIPT_DIR}/../../" # freeze the spec version to make SemanticAttributes generation reproducible -SEMCONV_VERSION=v1.26.0 -OTEL_SEMCONV_GEN_IMG_VERSION=0.24.0 +SEMCONV_VERSION=1.26.0 +SEMCONV_VERSION_TAG=v$SEMCONV_VERSION +OTEL_SEMCONV_GEN_IMG_VERSION=0.25.0 INCUBATING_DIR=_incubating cd ${SCRIPT_DIR} @@ -16,7 +17,7 @@ cd semantic-conventions git init git remote add origin https://github.com/open-telemetry/semantic-conventions.git -git fetch origin "$SEMCONV_VERSION" +git fetch origin "$SEMCONV_VERSION_TAG" git reset --hard FETCH_HEAD cd ${SCRIPT_DIR}