Skip to content

Commit

Permalink
Merge branch 'main' into pr3995
Browse files Browse the repository at this point in the history
  • Loading branch information
asasvari committed Jul 22, 2024
2 parents 127464b + 8749168 commit d88c11b
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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):
Expand All @@ -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,
)


Expand Down Expand Up @@ -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.
Expand All @@ -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,
)
2 changes: 2 additions & 0 deletions opentelemetry-api/tests/logs/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -646,17 +647,24 @@ 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,
InstrumentationScope(
name,
version,
schema_url,
attributes,
),
)

Expand Down
4 changes: 4 additions & 0 deletions opentelemetry-sdk/tests/logs/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ def test_get_logger(self):
"name",
version="version",
schema_url="schema_url",
attributes={"key": "value"},
)

self.assertEqual(logger._instrumentation_scope.name, "name")
self.assertEqual(logger._instrumentation_scope.version, "version")
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
7 changes: 4 additions & 3 deletions scripts/semconv/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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}

Expand Down

0 comments on commit d88c11b

Please sign in to comment.