From 3fd450dd4c4ffac7c7120d62ae051c45878524eb Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Wed, 10 May 2023 14:12:32 -0700 Subject: [PATCH 01/24] Switched to using BoundedAttributes as per #3114 --- .../src/opentelemetry/sdk/_logs/_internal/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index eda9b093c93..2858d3e7388 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -31,6 +31,7 @@ get_logger_provider, std_to_otel, ) +from opentelemetry.attributes import BoundedAttributes from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.util import ns_to_iso_str from opentelemetry.sdk.util.instrumentation import InstrumentationScope @@ -334,9 +335,9 @@ def __init__( @staticmethod def _get_attributes(record: logging.LogRecord) -> Attributes: - attributes = { + attributes = BoundedAttributes({ k: v for k, v in vars(record).items() if k not in _RESERVED_ATTRS - } + }) if record.exc_info: exc_type = "" message = "" From 986ba7dc8f485b1145a8b26698d03769a0250332 Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Wed, 10 May 2023 15:20:37 -0700 Subject: [PATCH 02/24] Switched to using BoundedAttributes as per #3114 --- .../src/opentelemetry/sdk/_logs/_internal/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 2858d3e7388..33237c6fbeb 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -335,9 +335,10 @@ def __init__( @staticmethod def _get_attributes(record: logging.LogRecord) -> Attributes: - attributes = BoundedAttributes({ + attr_dict = { k: v for k, v in vars(record).items() if k not in _RESERVED_ATTRS - }) + } + attributes = BoundedAttributes(maxlen=None, attributes = attr_dict if bool(attr_dict) else None, immutable=False) if record.exc_info: exc_type = "" message = "" From 6a3b62a153275b781a666a4ef236311d37a6a08e Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Wed, 10 May 2023 15:35:33 -0700 Subject: [PATCH 03/24] Code linting --- .../src/opentelemetry/sdk/_logs/_internal/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 33237c6fbeb..768c1c29f23 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -338,7 +338,7 @@ def _get_attributes(record: logging.LogRecord) -> Attributes: attr_dict = { k: v for k, v in vars(record).items() if k not in _RESERVED_ATTRS } - attributes = BoundedAttributes(maxlen=None, attributes = attr_dict if bool(attr_dict) else None, immutable=False) + attributes = BoundedAttributes(maxlen = None, attributes = attr_dict if bool(attr_dict) else None, immutable = False) if record.exc_info: exc_type = "" message = "" From 2d88ce4f35f2944c52de0e07d9c218471f0f6468 Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Wed, 10 May 2023 15:42:50 -0700 Subject: [PATCH 04/24] Code linting --- .../src/opentelemetry/sdk/_logs/_internal/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 768c1c29f23..0423ca9b73b 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -338,7 +338,11 @@ def _get_attributes(record: logging.LogRecord) -> Attributes: attr_dict = { k: v for k, v in vars(record).items() if k not in _RESERVED_ATTRS } - attributes = BoundedAttributes(maxlen = None, attributes = attr_dict if bool(attr_dict) else None, immutable = False) + attributes = BoundedAttributes( + maxlen = None, + attributes = attr_dict if bool(attr_dict) else None, + immutable = False + ) if record.exc_info: exc_type = "" message = "" From 1c5b20cb78428f9d33973f26986d684b713f0211 Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Wed, 10 May 2023 15:58:41 -0700 Subject: [PATCH 05/24] Code linting --- .../src/opentelemetry/sdk/_logs/_internal/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 0423ca9b73b..3a429bf1546 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -339,9 +339,9 @@ def _get_attributes(record: logging.LogRecord) -> Attributes: k: v for k, v in vars(record).items() if k not in _RESERVED_ATTRS } attributes = BoundedAttributes( - maxlen = None, - attributes = attr_dict if bool(attr_dict) else None, - immutable = False + maxlen=None, + attributes=attr_dict if bool(attr_dict) else None, + immutable=False, ) if record.exc_info: exc_type = "" From bdae2f2c84985ef3915b8a10d7f8dc5c6621c364 Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Wed, 10 May 2023 16:19:40 -0700 Subject: [PATCH 06/24] Comment --- .../src/opentelemetry/sdk/_logs/_internal/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 3a429bf1546..66aa7301968 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -338,6 +338,7 @@ def _get_attributes(record: logging.LogRecord) -> Attributes: attr_dict = { k: v for k, v in vars(record).items() if k not in _RESERVED_ATTRS } + # using BoundedAttributes instead of a dict attributes = BoundedAttributes( maxlen=None, attributes=attr_dict if bool(attr_dict) else None, From deff884483c7519061802934f8f71ae1f2a37e9c Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Thu, 11 May 2023 12:08:34 -0700 Subject: [PATCH 07/24] Moved the instantiating of BoundedAttributes into the LogRecord class init, so it would still work if the record is instantiated directly --- .../opentelemetry/sdk/_logs/_internal/__init__.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 66aa7301968..42743236bfa 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -78,7 +78,11 @@ def __init__( "severity_text": severity_text, "severity_number": severity_number, "body": body, - "attributes": attributes, + "attributes": BoundedAttributes( + maxlen=None, + attributes=attributes if bool(attributes) else None, + immutable=False, + ), } ) self.resource = resource @@ -335,15 +339,9 @@ def __init__( @staticmethod def _get_attributes(record: logging.LogRecord) -> Attributes: - attr_dict = { + attributes = { k: v for k, v in vars(record).items() if k not in _RESERVED_ATTRS } - # using BoundedAttributes instead of a dict - attributes = BoundedAttributes( - maxlen=None, - attributes=attr_dict if bool(attr_dict) else None, - immutable=False, - ) if record.exc_info: exc_type = "" message = "" From 58b734de860e36993787c600818fd976b0fdcc5b Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Thu, 11 May 2023 16:56:39 -0700 Subject: [PATCH 08/24] Properly serializing the items from BoundedAttributes in to_json since BoundedAttributes is not serializable --- .../src/opentelemetry/sdk/_logs/_internal/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 42743236bfa..fe43794e352 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -98,7 +98,7 @@ def to_json(self, indent=4) -> str: "body": self.body, "severity_number": repr(self.severity_number), "severity_text": self.severity_text, - "attributes": self.attributes, + "attributes": dict(self.attributes) if bool(self.attributes) else None, "timestamp": ns_to_iso_str(self.timestamp), "trace_id": f"0x{format_trace_id(self.trace_id)}" if self.trace_id is not None From 2dd23e59a3bd23084e38382240ac184940958529 Mon Sep 17 00:00:00 2001 From: OpenTelemetry Bot <107717825+opentelemetrybot@users.noreply.github.com> Date: Fri, 12 May 2023 14:30:36 -0700 Subject: [PATCH 09/24] Update version to 1.19.0.dev/0.40b0.dev (#3297) Co-authored-by: Diego Hurtado --- .github/workflows/test.yml | 2 +- CHANGELOG.md | 2 ++ eachdist.ini | 4 ++-- .../src/opentelemetry/exporter/jaeger/proto/grpc/version.py | 2 +- .../src/opentelemetry/exporter/jaeger/thrift/version.py | 2 +- exporter/opentelemetry-exporter-jaeger/pyproject.toml | 4 ++-- .../src/opentelemetry/exporter/jaeger/version.py | 2 +- exporter/opentelemetry-exporter-opencensus/pyproject.toml | 2 +- .../src/opentelemetry/exporter/opencensus/version.py | 2 +- .../opentelemetry-exporter-otlp-proto-common/pyproject.toml | 2 +- .../src/opentelemetry/exporter/otlp/proto/common/version.py | 2 +- .../opentelemetry-exporter-otlp-proto-grpc/pyproject.toml | 6 +++--- .../src/opentelemetry/exporter/otlp/proto/grpc/version.py | 2 +- .../opentelemetry-exporter-otlp-proto-http/pyproject.toml | 6 +++--- .../src/opentelemetry/exporter/otlp/proto/http/version.py | 2 +- exporter/opentelemetry-exporter-otlp/pyproject.toml | 4 ++-- .../src/opentelemetry/exporter/otlp/version.py | 2 +- .../src/opentelemetry/exporter/prometheus/version.py | 2 +- .../src/opentelemetry/exporter/zipkin/json/version.py | 2 +- .../opentelemetry-exporter-zipkin-proto-http/pyproject.toml | 2 +- .../src/opentelemetry/exporter/zipkin/proto/http/version.py | 2 +- exporter/opentelemetry-exporter-zipkin/pyproject.toml | 4 ++-- .../src/opentelemetry/exporter/zipkin/version.py | 2 +- opentelemetry-api/src/opentelemetry/version.py | 2 +- opentelemetry-proto/src/opentelemetry/proto/version.py | 2 +- opentelemetry-sdk/pyproject.toml | 4 ++-- opentelemetry-sdk/src/opentelemetry/sdk/version.py | 2 +- .../src/opentelemetry/semconv/version.py | 2 +- .../src/opentelemetry/propagators/b3/version.py | 2 +- .../src/opentelemetry/propagators/jaeger/version.py | 2 +- shim/opentelemetry-opencensus-shim/pyproject.toml | 2 +- .../src/opentelemetry/shim/opencensus/version.py | 2 +- shim/opentelemetry-opentracing-shim/pyproject.toml | 2 +- .../src/opentelemetry/shim/opentracing_shim/version.py | 2 +- tests/opentelemetry-test-utils/pyproject.toml | 4 ++-- .../src/opentelemetry/test/version.py | 2 +- 36 files changed, 47 insertions(+), 45 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 70b278b9ac2..1bdff92077e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ env: # Otherwise, set variable to the commit of your branch on # opentelemetry-python-contrib which is compatible with these Core repo # changes. - CONTRIB_REPO_SHA: 511709802466a751786047b7d98c2eb84801b34f + CONTRIB_REPO_SHA: 2edd017c22edb4896e182c934bc199d716495ce6 # This is needed because we do not clone the core repo in contrib builds anymore. # When running contrib builds as part of core builds, we use actions/checkout@v2 which # does not set an environment variable (simply just runs tox), which is different when diff --git a/CHANGELOG.md b/CHANGELOG.md index aeb41a3c584..a5896872952 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 +## Version 1.18.0/0.39b0 (2023-05-04) + - Select histogram aggregation with an environment variable ([#3265](https://github.com/open-telemetry/opentelemetry-python/pull/3265)) - Move Protobuf encoding to its own package diff --git a/eachdist.ini b/eachdist.ini index c33b4e09230..896dabb66e4 100644 --- a/eachdist.ini +++ b/eachdist.ini @@ -11,7 +11,7 @@ sortfirst= exporter/* [stable] -version=1.18.0.dev +version=1.19.0.dev packages= opentelemetry-sdk @@ -30,7 +30,7 @@ packages= opentelemetry-api [prerelease] -version=0.39b0.dev +version=0.40b0.dev packages= opentelemetry-opentracing-shim diff --git a/exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/version.py b/exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/version.py index 6b6b22d30fc..8e6645935aa 100644 --- a/exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/version.py +++ b/exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/version.py b/exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/version.py index 6b6b22d30fc..8e6645935aa 100644 --- a/exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/version.py +++ b/exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/exporter/opentelemetry-exporter-jaeger/pyproject.toml b/exporter/opentelemetry-exporter-jaeger/pyproject.toml index 95c93736dea..cc7c45cbd12 100644 --- a/exporter/opentelemetry-exporter-jaeger/pyproject.toml +++ b/exporter/opentelemetry-exporter-jaeger/pyproject.toml @@ -26,8 +26,8 @@ classifiers = [ "Typing :: Typed", ] dependencies = [ - "opentelemetry-exporter-jaeger-proto-grpc == 1.18.0.dev", - "opentelemetry-exporter-jaeger-thrift == 1.18.0.dev", + "opentelemetry-exporter-jaeger-proto-grpc == 1.19.0.dev", + "opentelemetry-exporter-jaeger-thrift == 1.19.0.dev", ] [project.optional-dependencies] diff --git a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/version.py b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/version.py index 6b6b22d30fc..8e6645935aa 100644 --- a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/version.py +++ b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/exporter/opentelemetry-exporter-opencensus/pyproject.toml b/exporter/opentelemetry-exporter-opencensus/pyproject.toml index 48e0a59ea41..f906b87bb74 100644 --- a/exporter/opentelemetry-exporter-opencensus/pyproject.toml +++ b/exporter/opentelemetry-exporter-opencensus/pyproject.toml @@ -28,7 +28,7 @@ classifiers = [ dependencies = [ "grpcio >= 1.0.0, < 2.0.0", "opencensus-proto >= 0.1.0, < 1.0.0", - "opentelemetry-api >= 1.18.0.dev", + "opentelemetry-api >= 1.19.0.dev", "opentelemetry-sdk >= 1.15", "protobuf ~= 3.13", "setuptools >= 16.0", diff --git a/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/version.py b/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/version.py index eb62a67e283..87b20fddc37 100644 --- a/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/version.py +++ b/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.39b0.dev" +__version__ = "0.40b0.dev" diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/pyproject.toml b/exporter/opentelemetry-exporter-otlp-proto-common/pyproject.toml index 5f872cd0867..64e2767deec 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/pyproject.toml +++ b/exporter/opentelemetry-exporter-otlp-proto-common/pyproject.toml @@ -25,7 +25,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", ] dependencies = [ - "opentelemetry-proto == 1.18.0.dev", + "opentelemetry-proto == 1.19.0.dev", ] [project.urls] diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/version.py b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/version.py index 80d12781d3d..168a28bae9e 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/version.py +++ b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/pyproject.toml b/exporter/opentelemetry-exporter-otlp-proto-grpc/pyproject.toml index 82ec2b0a19d..ebeaa357456 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/pyproject.toml +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/pyproject.toml @@ -31,9 +31,9 @@ dependencies = [ "googleapis-common-protos ~= 1.52", "grpcio >= 1.0.0, < 2.0.0", "opentelemetry-api ~= 1.15", - "opentelemetry-proto == 1.18.0.dev", - "opentelemetry-sdk ~= 1.18.0.dev", - "opentelemetry-exporter-otlp-proto-common == 1.18.0.dev", + "opentelemetry-proto == 1.19.0.dev", + "opentelemetry-sdk ~= 1.19.0.dev", + "opentelemetry-exporter-otlp-proto-common == 1.19.0.dev", ] [project.optional-dependencies] diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/version.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/version.py index 80d12781d3d..168a28bae9e 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/version.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/pyproject.toml b/exporter/opentelemetry-exporter-otlp-proto-http/pyproject.toml index 54f2b67249a..10eeafccf5c 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/pyproject.toml +++ b/exporter/opentelemetry-exporter-otlp-proto-http/pyproject.toml @@ -30,9 +30,9 @@ dependencies = [ "backoff >= 1.10.0, < 3.0.0; python_version>='3.7'", "googleapis-common-protos ~= 1.52", "opentelemetry-api ~= 1.15", - "opentelemetry-proto == 1.18.0.dev", - "opentelemetry-sdk ~= 1.18.0.dev", - "opentelemetry-exporter-otlp-proto-common == 1.18.0.dev", + "opentelemetry-proto == 1.19.0.dev", + "opentelemetry-sdk ~= 1.19.0.dev", + "opentelemetry-exporter-otlp-proto-common == 1.19.0.dev", "requests ~= 2.7", ] diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/version.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/version.py index 80d12781d3d..168a28bae9e 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/version.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/exporter/opentelemetry-exporter-otlp/pyproject.toml b/exporter/opentelemetry-exporter-otlp/pyproject.toml index 8af01b433c9..a2bb316e364 100644 --- a/exporter/opentelemetry-exporter-otlp/pyproject.toml +++ b/exporter/opentelemetry-exporter-otlp/pyproject.toml @@ -26,8 +26,8 @@ classifiers = [ "Typing :: Typed", ] dependencies = [ - "opentelemetry-exporter-otlp-proto-grpc == 1.18.0.dev", - "opentelemetry-exporter-otlp-proto-http == 1.18.0.dev", + "opentelemetry-exporter-otlp-proto-grpc == 1.19.0.dev", + "opentelemetry-exporter-otlp-proto-http == 1.19.0.dev", ] [project.entry-points.opentelemetry_logs_exporter] diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/version.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/version.py index 80d12781d3d..168a28bae9e 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/version.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/exporter/opentelemetry-exporter-prometheus/src/opentelemetry/exporter/prometheus/version.py b/exporter/opentelemetry-exporter-prometheus/src/opentelemetry/exporter/prometheus/version.py index eb62a67e283..87b20fddc37 100644 --- a/exporter/opentelemetry-exporter-prometheus/src/opentelemetry/exporter/prometheus/version.py +++ b/exporter/opentelemetry-exporter-prometheus/src/opentelemetry/exporter/prometheus/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.39b0.dev" +__version__ = "0.40b0.dev" diff --git a/exporter/opentelemetry-exporter-zipkin-json/src/opentelemetry/exporter/zipkin/json/version.py b/exporter/opentelemetry-exporter-zipkin-json/src/opentelemetry/exporter/zipkin/json/version.py index 80d12781d3d..168a28bae9e 100644 --- a/exporter/opentelemetry-exporter-zipkin-json/src/opentelemetry/exporter/zipkin/json/version.py +++ b/exporter/opentelemetry-exporter-zipkin-json/src/opentelemetry/exporter/zipkin/json/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/exporter/opentelemetry-exporter-zipkin-proto-http/pyproject.toml b/exporter/opentelemetry-exporter-zipkin-proto-http/pyproject.toml index 8764b35d434..6e0069848f6 100644 --- a/exporter/opentelemetry-exporter-zipkin-proto-http/pyproject.toml +++ b/exporter/opentelemetry-exporter-zipkin-proto-http/pyproject.toml @@ -27,7 +27,7 @@ classifiers = [ ] dependencies = [ "opentelemetry-api ~= 1.3", - "opentelemetry-exporter-zipkin-json == 1.18.0.dev", + "opentelemetry-exporter-zipkin-json == 1.19.0.dev", "opentelemetry-sdk ~= 1.11", "protobuf ~= 3.12", "requests ~= 2.7", diff --git a/exporter/opentelemetry-exporter-zipkin-proto-http/src/opentelemetry/exporter/zipkin/proto/http/version.py b/exporter/opentelemetry-exporter-zipkin-proto-http/src/opentelemetry/exporter/zipkin/proto/http/version.py index 80d12781d3d..168a28bae9e 100644 --- a/exporter/opentelemetry-exporter-zipkin-proto-http/src/opentelemetry/exporter/zipkin/proto/http/version.py +++ b/exporter/opentelemetry-exporter-zipkin-proto-http/src/opentelemetry/exporter/zipkin/proto/http/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/exporter/opentelemetry-exporter-zipkin/pyproject.toml b/exporter/opentelemetry-exporter-zipkin/pyproject.toml index 03dedc6deac..5a1325e20c9 100644 --- a/exporter/opentelemetry-exporter-zipkin/pyproject.toml +++ b/exporter/opentelemetry-exporter-zipkin/pyproject.toml @@ -26,8 +26,8 @@ classifiers = [ "Typing :: Typed", ] dependencies = [ - "opentelemetry-exporter-zipkin-json == 1.18.0.dev", - "opentelemetry-exporter-zipkin-proto-http == 1.18.0.dev", + "opentelemetry-exporter-zipkin-json == 1.19.0.dev", + "opentelemetry-exporter-zipkin-proto-http == 1.19.0.dev", ] [project.optional-dependencies] diff --git a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/version.py b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/version.py index 80d12781d3d..168a28bae9e 100644 --- a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/version.py +++ b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/opentelemetry-api/src/opentelemetry/version.py b/opentelemetry-api/src/opentelemetry/version.py index 80d12781d3d..168a28bae9e 100644 --- a/opentelemetry-api/src/opentelemetry/version.py +++ b/opentelemetry-api/src/opentelemetry/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/opentelemetry-proto/src/opentelemetry/proto/version.py b/opentelemetry-proto/src/opentelemetry/proto/version.py index 80d12781d3d..168a28bae9e 100644 --- a/opentelemetry-proto/src/opentelemetry/proto/version.py +++ b/opentelemetry-proto/src/opentelemetry/proto/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/opentelemetry-sdk/pyproject.toml b/opentelemetry-sdk/pyproject.toml index 5be574f3a28..88f3ca8f01c 100644 --- a/opentelemetry-sdk/pyproject.toml +++ b/opentelemetry-sdk/pyproject.toml @@ -26,8 +26,8 @@ classifiers = [ "Typing :: Typed", ] dependencies = [ - "opentelemetry-api == 1.18.0.dev", - "opentelemetry-semantic-conventions == 0.39b0.dev", + "opentelemetry-api == 1.19.0.dev", + "opentelemetry-semantic-conventions == 0.40b0.dev", "setuptools >= 16.0", "typing-extensions >= 3.7.4", ] diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/version.py b/opentelemetry-sdk/src/opentelemetry/sdk/version.py index 80d12781d3d..168a28bae9e 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/version.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/opentelemetry-semantic-conventions/src/opentelemetry/semconv/version.py b/opentelemetry-semantic-conventions/src/opentelemetry/semconv/version.py index eb62a67e283..87b20fddc37 100644 --- a/opentelemetry-semantic-conventions/src/opentelemetry/semconv/version.py +++ b/opentelemetry-semantic-conventions/src/opentelemetry/semconv/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.39b0.dev" +__version__ = "0.40b0.dev" diff --git a/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/version.py b/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/version.py index 80d12781d3d..168a28bae9e 100644 --- a/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/version.py +++ b/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/propagator/opentelemetry-propagator-jaeger/src/opentelemetry/propagators/jaeger/version.py b/propagator/opentelemetry-propagator-jaeger/src/opentelemetry/propagators/jaeger/version.py index 80d12781d3d..168a28bae9e 100644 --- a/propagator/opentelemetry-propagator-jaeger/src/opentelemetry/propagators/jaeger/version.py +++ b/propagator/opentelemetry-propagator-jaeger/src/opentelemetry/propagators/jaeger/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.18.0.dev" +__version__ = "1.19.0.dev" diff --git a/shim/opentelemetry-opencensus-shim/pyproject.toml b/shim/opentelemetry-opencensus-shim/pyproject.toml index 43bef2fdd59..19b072b19a4 100644 --- a/shim/opentelemetry-opencensus-shim/pyproject.toml +++ b/shim/opentelemetry-opencensus-shim/pyproject.toml @@ -34,7 +34,7 @@ dependencies = [ [project.optional-dependencies] test = [ - "opentelemetry-test-utils == 0.39b0.dev", + "opentelemetry-test-utils == 0.40b0.dev", "opencensus == 0.11.1", ] diff --git a/shim/opentelemetry-opencensus-shim/src/opentelemetry/shim/opencensus/version.py b/shim/opentelemetry-opencensus-shim/src/opentelemetry/shim/opencensus/version.py index eb62a67e283..87b20fddc37 100644 --- a/shim/opentelemetry-opencensus-shim/src/opentelemetry/shim/opencensus/version.py +++ b/shim/opentelemetry-opencensus-shim/src/opentelemetry/shim/opencensus/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.39b0.dev" +__version__ = "0.40b0.dev" diff --git a/shim/opentelemetry-opentracing-shim/pyproject.toml b/shim/opentelemetry-opentracing-shim/pyproject.toml index 6345b77d35f..5ef35795204 100644 --- a/shim/opentelemetry-opentracing-shim/pyproject.toml +++ b/shim/opentelemetry-opentracing-shim/pyproject.toml @@ -33,7 +33,7 @@ dependencies = [ [project.optional-dependencies] test = [ - "opentelemetry-test-utils == 0.39b0.dev", + "opentelemetry-test-utils == 0.40b0.dev", "opentracing ~= 2.2.0", ] diff --git a/shim/opentelemetry-opentracing-shim/src/opentelemetry/shim/opentracing_shim/version.py b/shim/opentelemetry-opentracing-shim/src/opentelemetry/shim/opentracing_shim/version.py index eb62a67e283..87b20fddc37 100644 --- a/shim/opentelemetry-opentracing-shim/src/opentelemetry/shim/opentracing_shim/version.py +++ b/shim/opentelemetry-opentracing-shim/src/opentelemetry/shim/opentracing_shim/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.39b0.dev" +__version__ = "0.40b0.dev" diff --git a/tests/opentelemetry-test-utils/pyproject.toml b/tests/opentelemetry-test-utils/pyproject.toml index fb1c0915f45..41fc56244fc 100644 --- a/tests/opentelemetry-test-utils/pyproject.toml +++ b/tests/opentelemetry-test-utils/pyproject.toml @@ -25,8 +25,8 @@ classifiers = [ ] dependencies = [ "asgiref ~= 3.0", - "opentelemetry-api == 1.18.0.dev", - "opentelemetry-sdk == 1.18.0.dev", + "opentelemetry-api == 1.19.0.dev", + "opentelemetry-sdk == 1.19.0.dev", ] [project.optional-dependencies] diff --git a/tests/opentelemetry-test-utils/src/opentelemetry/test/version.py b/tests/opentelemetry-test-utils/src/opentelemetry/test/version.py index 15f6e2a9b43..a4a2694c890 100644 --- a/tests/opentelemetry-test-utils/src/opentelemetry/test/version.py +++ b/tests/opentelemetry-test-utils/src/opentelemetry/test/version.py @@ -1 +1 @@ -__version__ = "0.39b0.dev" +__version__ = "0.40b0.dev" From 9f88cd58fe5f93f12060130b83ac72c4cf607633 Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Mon, 15 May 2023 13:42:42 -0700 Subject: [PATCH 10/24] Lint --- .../src/opentelemetry/sdk/_logs/_internal/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index fe43794e352..17c43f09d14 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -98,7 +98,9 @@ def to_json(self, indent=4) -> str: "body": self.body, "severity_number": repr(self.severity_number), "severity_text": self.severity_text, - "attributes": dict(self.attributes) if bool(self.attributes) else None, + "attributes": dict(self.attributes) + if bool(self.attributes) + else None, "timestamp": ns_to_iso_str(self.timestamp), "trace_id": f"0x{format_trace_id(self.trace_id)}" if self.trace_id is not None From f62641133b6adca090071a0480592605980c8d8b Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Mon, 15 May 2023 15:42:18 -0700 Subject: [PATCH 11/24] Tests + changelog update --- CHANGELOG.md | 2 +- opentelemetry-sdk/tests/logs/test_handler.py | 2 ++ opentelemetry-sdk/tests/logs/test_log_record.py | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5896872952..de50f809617 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased - +- Use BoundedAttributes instead of raw dict to extract attributes from LogRecord ([#3310](https://github.com/open-telemetry/opentelemetry-python/pull/3310)) ## Version 1.18.0/0.39b0 (2023-05-04) - Select histogram aggregation with an environment variable diff --git a/opentelemetry-sdk/tests/logs/test_handler.py b/opentelemetry-sdk/tests/logs/test_handler.py index b9c40608e14..04cf5640f5f 100644 --- a/opentelemetry-sdk/tests/logs/test_handler.py +++ b/opentelemetry-sdk/tests/logs/test_handler.py @@ -17,6 +17,7 @@ from opentelemetry._logs import SeverityNumber from opentelemetry._logs import get_logger as APIGetLogger +from opentelemetry.attributes import BoundedAttributes from opentelemetry.sdk import trace from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler from opentelemetry.semconv.trace import SpanAttributes @@ -91,6 +92,7 @@ def test_log_record_user_attributes(self): self.assertIsNotNone(log_record) self.assertEqual(log_record.attributes, {"http.status_code": 200}) + self.assertTrue(isinstance(log_record.attributes, BoundedAttributes)) def test_log_record_exception(self): """Exception information will be included in attributes""" diff --git a/opentelemetry-sdk/tests/logs/test_log_record.py b/opentelemetry-sdk/tests/logs/test_log_record.py index 7142408c4c0..d98d8f6d589 100644 --- a/opentelemetry-sdk/tests/logs/test_log_record.py +++ b/opentelemetry-sdk/tests/logs/test_log_record.py @@ -15,6 +15,7 @@ import json import unittest +from opentelemetry.attributes import BoundedAttributes from opentelemetry.sdk._logs import LogRecord @@ -39,3 +40,14 @@ def test_log_record_to_json(self): body="a log line", ).to_json() self.assertEqual(expected, actual) + + def test_log_record_bounded_attributes(self): + attr = {"key": "value"} + + record = LogRecord( + timestamp=0, + body="a log line", + attributes=attr + ) + + self.assertTrue(isinstance(record.attributes, BoundedAttributes)) From 820eb09fa8c432634e475add7f0c2dcbb68b0c6e Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Mon, 15 May 2023 16:11:33 -0700 Subject: [PATCH 12/24] Lint --- opentelemetry-sdk/tests/logs/test_log_record.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/opentelemetry-sdk/tests/logs/test_log_record.py b/opentelemetry-sdk/tests/logs/test_log_record.py index d98d8f6d589..6494949e3f1 100644 --- a/opentelemetry-sdk/tests/logs/test_log_record.py +++ b/opentelemetry-sdk/tests/logs/test_log_record.py @@ -44,10 +44,6 @@ def test_log_record_to_json(self): def test_log_record_bounded_attributes(self): attr = {"key": "value"} - record = LogRecord( - timestamp=0, - body="a log line", - attributes=attr - ) + record = LogRecord(timestamp=0, body="a log line", attributes=attr) self.assertTrue(isinstance(record.attributes, BoundedAttributes)) From 4749c8efab31153f1edaeb42686448c90693aabe Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Thu, 18 May 2023 17:27:57 -0700 Subject: [PATCH 13/24] Added limits + tests --- .../sdk/_logs/_internal/__init__.py | 13 ++++- .../tests/logs/test_log_record.py | 52 ++++++++++++++++++- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 17c43f09d14..b8282d5fee7 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -33,6 +33,7 @@ ) from opentelemetry.attributes import BoundedAttributes from opentelemetry.sdk.resources import Resource +from opentelemetry.sdk.trace import SpanLimits from opentelemetry.sdk.util import ns_to_iso_str from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.semconv.trace import SpanAttributes @@ -67,6 +68,7 @@ def __init__( body: Optional[Any] = None, resource: Optional[Resource] = None, attributes: Optional[Attributes] = None, + limits: Optional[SpanLimits] = SpanLimits(), ): super().__init__( **{ @@ -79,10 +81,11 @@ def __init__( "severity_number": severity_number, "body": body, "attributes": BoundedAttributes( - maxlen=None, + maxlen=limits.max_span_attributes, attributes=attributes if bool(attributes) else None, immutable=False, - ), + max_value_len=limits.max_attribute_length, + ) } ) self.resource = resource @@ -116,6 +119,12 @@ def to_json(self, indent=4) -> str: indent=indent, ) + @property + def dropped_attributes(self) -> int: + if self.attributes: + return self.attributes.dropped + return 0 + class LogData: """Readable LogRecord data plus associated InstrumentationLibrary.""" diff --git a/opentelemetry-sdk/tests/logs/test_log_record.py b/opentelemetry-sdk/tests/logs/test_log_record.py index 6494949e3f1..e34f2bb9b1f 100644 --- a/opentelemetry-sdk/tests/logs/test_log_record.py +++ b/opentelemetry-sdk/tests/logs/test_log_record.py @@ -17,6 +17,7 @@ from opentelemetry.attributes import BoundedAttributes from opentelemetry.sdk._logs import LogRecord +from opentelemetry.sdk.trace import SpanLimits class TestLogRecord(unittest.TestCase): @@ -44,6 +45,53 @@ def test_log_record_to_json(self): def test_log_record_bounded_attributes(self): attr = {"key": "value"} - record = LogRecord(timestamp=0, body="a log line", attributes=attr) + result = LogRecord(timestamp=0, body="a log line", attributes=attr) - self.assertTrue(isinstance(record.attributes, BoundedAttributes)) + self.assertTrue(isinstance(result.attributes, BoundedAttributes)) + + def test_log_record_dropped_attributes_empty_limits(self): + attr = {"key": "value"} + + result = LogRecord(timestamp=0, body="a log line", attributes=attr) + + self.assertTrue(result.dropped_attributes == 0) + + def test_log_record_dropped_attributes_set_limits_max_attribute(self): + attr = {"key": "value", "key2": "value2"} + limits = SpanLimits( + max_attributes=1, + ) + + result = LogRecord(timestamp=0, body="a log line", attributes=attr, limits=limits) + self.assertTrue(result.dropped_attributes == 1) + + def test_log_record_dropped_attributes_set_limits_max_attribute_length(self): + attr = {"key": "value", "key2": "value2"} + expected = {"key": "v", "key2": "v"} + limits = SpanLimits( + max_attribute_length=1, + ) + + result = LogRecord(timestamp=0, body="a log line", attributes=attr, limits=limits) + self.assertTrue(result.dropped_attributes == 0) + self.assertEqual(expected, result.attributes) + + def test_log_record_dropped_attributes_set_limits(self): + attr = {"key": "value", "key2": "value2"} + expected = {"key2": "v"} + limits = SpanLimits( + max_attributes=1, + max_attribute_length=1, + ) + + result = LogRecord(timestamp=0, body="a log line", attributes=attr, limits=limits) + self.assertTrue(result.dropped_attributes == 1) + self.assertEqual(expected, result.attributes) + + def test_log_record_dropped_attributes_unset_limits(self): + attr = {"key": "value", "key2": "value2"} + limits = SpanLimits() + + result = LogRecord(timestamp=0, body="a log line", attributes=attr, limits=limits) + self.assertTrue(result.dropped_attributes == 0) + self.assertEqual(attr, result.attributes) From 7c3962058a1ceaf7e9bea36b657b9f691d00f5da Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Thu, 18 May 2023 18:03:20 -0700 Subject: [PATCH 14/24] Updated changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de50f809617..3ce6fc42516 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased -- Use BoundedAttributes instead of raw dict to extract attributes from LogRecord ([#3310](https://github.com/open-telemetry/opentelemetry-python/pull/3310)) +- Use BoundedAttributes instead of raw dict to extract attributes from LogRecord and Support dropped_attributes_count in LogRecord ([#3310](https://github.com/open-telemetry/opentelemetry-python/pull/3310)) ## Version 1.18.0/0.39b0 (2023-05-04) - Select histogram aggregation with an environment variable From cb17281787324470a7e7e5cdebe9e11270c1a8c2 Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Fri, 19 May 2023 11:03:12 -0700 Subject: [PATCH 15/24] Added LogLimits and tests --- .../src/opentelemetry/sdk/_logs/__init__.py | 4 + .../sdk/_logs/_internal/__init__.py | 105 +++++++++++++++++- .../tests/logs/test_log_limits.py | 40 +++++++ .../tests/logs/test_log_record.py | 14 ++- 4 files changed, 154 insertions(+), 9 deletions(-) create mode 100644 opentelemetry-sdk/tests/logs/test_log_limits.py diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py index a86fbaee0f1..3827207d7d0 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py @@ -20,6 +20,8 @@ LoggingHandler, LogRecord, LogRecordProcessor, + LogLimits, + _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT, ) __all__ = [ @@ -29,4 +31,6 @@ "LoggingHandler", "LogRecord", "LogRecordProcessor", + "LogLimits", + "_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT", ] diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index b8282d5fee7..57c75bea88d 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -21,6 +21,7 @@ import traceback from time import time_ns from typing import Any, Callable, Optional, Tuple, Union +from os import environ from opentelemetry._logs import Logger as APILogger from opentelemetry._logs import LoggerProvider as APILoggerProvider @@ -32,8 +33,11 @@ std_to_otel, ) from opentelemetry.attributes import BoundedAttributes +from opentelemetry.sdk.environment_variables import ( + OTEL_ATTRIBUTE_COUNT_LIMIT, + OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT, +) from opentelemetry.sdk.resources import Resource -from opentelemetry.sdk.trace import SpanLimits from opentelemetry.sdk.util import ns_to_iso_str from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.semconv.trace import SpanAttributes @@ -47,6 +51,100 @@ _logger = logging.getLogger(__name__) +_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT = 128 +_ENV_VALUE_UNSET = "" + +class LogLimits: + """This class is based on a SpanLimits class in the Tracing module. + + The limits that should be enforced on recorded data such as events, links, attributes etc. + + This class does not enforce any limits itself. It only provides an a way read limits from env, + default values and from user provided arguments. + + All limit arguments must be either a non-negative integer, ``None`` or ``LogLimits.UNSET``. + + - All limit arguments are optional. + - If a limit argument is not set, the class will try to read its value from the corresponding + environment variable. + - If the environment variable is not set, the default value, if any, will be used. + + Limit precedence: + + - If a model specific limit is set, it will be used. + - Else if the corresponding global limit is set, it will be used. + - Else if the model specific limit has a default value, the default value will be used. + - Else if the global limit has a default value, the default value will be used. + + Args: + max_attributes: Maximum number of attributes that can be added to a span, event, and link. + Environment variable: OTEL_ATTRIBUTE_COUNT_LIMIT + Default: {_DEFAULT_ATTRIBUTE_COUNT_LIMIT} + max_attribute_length: Maximum length an attribute value can have. Values longer than + the specified length will be truncated. + """ + + UNSET = -1 + + def __init__( + self, + max_attributes: Optional[int] = None, + max_attribute_length: Optional[int] = None, + ): + + + # attribute count + global_max_attributes = self._from_env_if_absent( + max_attributes, OTEL_ATTRIBUTE_COUNT_LIMIT + ) + self.max_attributes = ( + global_max_attributes + if global_max_attributes is not None + else _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT + ) + + # attribute length + self.max_attribute_length = self._from_env_if_absent( + max_attribute_length, + OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT, + ) + + def __repr__(self): + return f"{type(self).__name__}(max_attributes={self.max_attributes}, max_attribute_length={self.max_attribute_length})" + + @classmethod + def _from_env_if_absent( + cls, value: Optional[int], env_var: str, default: Optional[int] = None + ) -> Optional[int]: + if value == cls.UNSET: + return None + + err_msg = "{0} must be a non-negative integer but got {}" + + # if no value is provided for the limit, try to load it from env + if value is None: + # return default value if env var is not set + if env_var not in environ: + return default + + str_value = environ.get(env_var, "").strip().lower() + if str_value == _ENV_VALUE_UNSET: + return None + + try: + value = int(str_value) + except ValueError: + raise ValueError(err_msg.format(env_var, str_value)) + + if value < 0: + raise ValueError(err_msg.format(env_var, value)) + return value + + +_UnsetLogLimits = LogLimits( + max_attributes=LogLimits.UNSET, + max_attribute_length=LogLimits.UNSET, +) class LogRecord(APILogRecord): """A LogRecord instance represents an event being logged. @@ -68,7 +166,7 @@ def __init__( body: Optional[Any] = None, resource: Optional[Resource] = None, attributes: Optional[Attributes] = None, - limits: Optional[SpanLimits] = SpanLimits(), + limits: Optional[LogLimits] = _UnsetLogLimits, ): super().__init__( **{ @@ -81,7 +179,7 @@ def __init__( "severity_number": severity_number, "body": body, "attributes": BoundedAttributes( - maxlen=limits.max_span_attributes, + maxlen=limits.max_attributes, attributes=attributes if bool(attributes) else None, immutable=False, max_value_len=limits.max_attribute_length, @@ -503,3 +601,4 @@ def force_flush(self, timeout_millis: int = 30000) -> bool: False otherwise. """ return self._multi_log_record_processor.force_flush(timeout_millis) + \ No newline at end of file diff --git a/opentelemetry-sdk/tests/logs/test_log_limits.py b/opentelemetry-sdk/tests/logs/test_log_limits.py new file mode 100644 index 00000000000..1eca2c2854e --- /dev/null +++ b/opentelemetry-sdk/tests/logs/test_log_limits.py @@ -0,0 +1,40 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +from opentelemetry.attributes import BoundedAttributes +from opentelemetry.sdk._logs import ( + LogLimits, + _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT +) + +class TestLogLimits(unittest.TestCase): + def test_log_limits_repr_unset(self): + expected = "LogLimits(max_attributes=" + _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT + ", max_attribute_length=None)" + limits = str(LogLimits()) + + self.assertEqual(expected, limits) + + def test_log_limits_max_attributes(self): + expected = 1 + limits = LogLimits(max_attributes=1) + + self.assertEqual(expected, limits.max_attributes) + + def test_log_limits_max_attribute_length(self): + expected = 1 + limits = LogLimits(max_attribute_length=1) + + self.assertEqual(expected, limits.max_attribute_length) diff --git a/opentelemetry-sdk/tests/logs/test_log_record.py b/opentelemetry-sdk/tests/logs/test_log_record.py index e34f2bb9b1f..17f450f0893 100644 --- a/opentelemetry-sdk/tests/logs/test_log_record.py +++ b/opentelemetry-sdk/tests/logs/test_log_record.py @@ -16,8 +16,10 @@ import unittest from opentelemetry.attributes import BoundedAttributes -from opentelemetry.sdk._logs import LogRecord -from opentelemetry.sdk.trace import SpanLimits +from opentelemetry.sdk._logs import ( + LogRecord, + LogLimits +) class TestLogRecord(unittest.TestCase): @@ -58,7 +60,7 @@ def test_log_record_dropped_attributes_empty_limits(self): def test_log_record_dropped_attributes_set_limits_max_attribute(self): attr = {"key": "value", "key2": "value2"} - limits = SpanLimits( + limits = LogLimits( max_attributes=1, ) @@ -68,7 +70,7 @@ def test_log_record_dropped_attributes_set_limits_max_attribute(self): def test_log_record_dropped_attributes_set_limits_max_attribute_length(self): attr = {"key": "value", "key2": "value2"} expected = {"key": "v", "key2": "v"} - limits = SpanLimits( + limits = LogLimits( max_attribute_length=1, ) @@ -79,7 +81,7 @@ def test_log_record_dropped_attributes_set_limits_max_attribute_length(self): def test_log_record_dropped_attributes_set_limits(self): attr = {"key": "value", "key2": "value2"} expected = {"key2": "v"} - limits = SpanLimits( + limits = LogLimits( max_attributes=1, max_attribute_length=1, ) @@ -90,7 +92,7 @@ def test_log_record_dropped_attributes_set_limits(self): def test_log_record_dropped_attributes_unset_limits(self): attr = {"key": "value", "key2": "value2"} - limits = SpanLimits() + limits = LogLimits() result = LogRecord(timestamp=0, body="a log line", attributes=attr, limits=limits) self.assertTrue(result.dropped_attributes == 0) From 387c92888695d57f752ca56fdb305481d554b4db Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Fri, 19 May 2023 11:07:45 -0700 Subject: [PATCH 16/24] Lint --- .../sdk/_logs/_internal/__init__.py | 2 +- .../tests/logs/test_log_record.py | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 57c75bea88d..a8b3cfb90eb 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -183,7 +183,7 @@ def __init__( attributes=attributes if bool(attributes) else None, immutable=False, max_value_len=limits.max_attribute_length, - ) + ), } ) self.resource = resource diff --git a/opentelemetry-sdk/tests/logs/test_log_record.py b/opentelemetry-sdk/tests/logs/test_log_record.py index 17f450f0893..cdf1e86e619 100644 --- a/opentelemetry-sdk/tests/logs/test_log_record.py +++ b/opentelemetry-sdk/tests/logs/test_log_record.py @@ -64,17 +64,23 @@ def test_log_record_dropped_attributes_set_limits_max_attribute(self): max_attributes=1, ) - result = LogRecord(timestamp=0, body="a log line", attributes=attr, limits=limits) + result = LogRecord( + timestamp=0, body="a log line", attributes=attr, limits=limits + ) self.assertTrue(result.dropped_attributes == 1) - def test_log_record_dropped_attributes_set_limits_max_attribute_length(self): + def test_log_record_dropped_attributes_set_limits_max_attribute_length( + self + ): attr = {"key": "value", "key2": "value2"} expected = {"key": "v", "key2": "v"} limits = LogLimits( max_attribute_length=1, ) - result = LogRecord(timestamp=0, body="a log line", attributes=attr, limits=limits) + result = LogRecord( + timestamp=0, body="a log line", attributes=attr, limits=limits + ) self.assertTrue(result.dropped_attributes == 0) self.assertEqual(expected, result.attributes) @@ -86,7 +92,9 @@ def test_log_record_dropped_attributes_set_limits(self): max_attribute_length=1, ) - result = LogRecord(timestamp=0, body="a log line", attributes=attr, limits=limits) + result = LogRecord( + timestamp=0, body="a log line", attributes=attr, limits=limits + ) self.assertTrue(result.dropped_attributes == 1) self.assertEqual(expected, result.attributes) @@ -94,6 +102,8 @@ def test_log_record_dropped_attributes_unset_limits(self): attr = {"key": "value", "key2": "value2"} limits = LogLimits() - result = LogRecord(timestamp=0, body="a log line", attributes=attr, limits=limits) + result = LogRecord( + timestamp=0, body="a log line", attributes=attr, limits=limits + ) self.assertTrue(result.dropped_attributes == 0) self.assertEqual(attr, result.attributes) From 3e6e5ea0f5b4710a16da369534beb904f36ed913 Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Fri, 19 May 2023 11:14:09 -0700 Subject: [PATCH 17/24] Lint --- .../src/opentelemetry/sdk/_logs/_internal/__init__.py | 3 ++- opentelemetry-sdk/tests/logs/test_log_limits.py | 8 ++++++-- opentelemetry-sdk/tests/logs/test_log_record.py | 9 +++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index a8b3cfb90eb..2774658b4bb 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -54,6 +54,7 @@ _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT = 128 _ENV_VALUE_UNSET = "" + class LogLimits: """This class is based on a SpanLimits class in the Tracing module. @@ -92,7 +93,6 @@ def __init__( max_attribute_length: Optional[int] = None, ): - # attribute count global_max_attributes = self._from_env_if_absent( max_attributes, OTEL_ATTRIBUTE_COUNT_LIMIT @@ -146,6 +146,7 @@ def _from_env_if_absent( max_attribute_length=LogLimits.UNSET, ) + class LogRecord(APILogRecord): """A LogRecord instance represents an event being logged. diff --git a/opentelemetry-sdk/tests/logs/test_log_limits.py b/opentelemetry-sdk/tests/logs/test_log_limits.py index 1eca2c2854e..4085ce7c338 100644 --- a/opentelemetry-sdk/tests/logs/test_log_limits.py +++ b/opentelemetry-sdk/tests/logs/test_log_limits.py @@ -17,12 +17,16 @@ from opentelemetry.attributes import BoundedAttributes from opentelemetry.sdk._logs import ( LogLimits, - _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT + _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT, ) class TestLogLimits(unittest.TestCase): def test_log_limits_repr_unset(self): - expected = "LogLimits(max_attributes=" + _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT + ", max_attribute_length=None)" + expected = ( + "LogLimits(max_attributes=" + + _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT + + ", max_attribute_length=None)" + ) limits = str(LogLimits()) self.assertEqual(expected, limits) diff --git a/opentelemetry-sdk/tests/logs/test_log_record.py b/opentelemetry-sdk/tests/logs/test_log_record.py index cdf1e86e619..b2f842a7676 100644 --- a/opentelemetry-sdk/tests/logs/test_log_record.py +++ b/opentelemetry-sdk/tests/logs/test_log_record.py @@ -16,10 +16,7 @@ import unittest from opentelemetry.attributes import BoundedAttributes -from opentelemetry.sdk._logs import ( - LogRecord, - LogLimits -) +from opentelemetry.sdk._logs import LogRecord, LogLimits class TestLogRecord(unittest.TestCase): @@ -70,8 +67,8 @@ def test_log_record_dropped_attributes_set_limits_max_attribute(self): self.assertTrue(result.dropped_attributes == 1) def test_log_record_dropped_attributes_set_limits_max_attribute_length( - self - ): + self + ): attr = {"key": "value", "key2": "value2"} expected = {"key": "v", "key2": "v"} limits = LogLimits( From b1a646d3af0c34964768beaa2eeba48e9a8197da Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Fri, 19 May 2023 11:21:07 -0700 Subject: [PATCH 18/24] Lint --- .../src/opentelemetry/sdk/_logs/_internal/__init__.py | 1 - opentelemetry-sdk/tests/logs/test_log_limits.py | 1 + opentelemetry-sdk/tests/logs/test_log_record.py | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 2774658b4bb..68ad9feeac8 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -602,4 +602,3 @@ def force_flush(self, timeout_millis: int = 30000) -> bool: False otherwise. """ return self._multi_log_record_processor.force_flush(timeout_millis) - \ No newline at end of file diff --git a/opentelemetry-sdk/tests/logs/test_log_limits.py b/opentelemetry-sdk/tests/logs/test_log_limits.py index 4085ce7c338..6f4a34a2608 100644 --- a/opentelemetry-sdk/tests/logs/test_log_limits.py +++ b/opentelemetry-sdk/tests/logs/test_log_limits.py @@ -20,6 +20,7 @@ _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT, ) + class TestLogLimits(unittest.TestCase): def test_log_limits_repr_unset(self): expected = ( diff --git a/opentelemetry-sdk/tests/logs/test_log_record.py b/opentelemetry-sdk/tests/logs/test_log_record.py index b2f842a7676..f3bc519bee2 100644 --- a/opentelemetry-sdk/tests/logs/test_log_record.py +++ b/opentelemetry-sdk/tests/logs/test_log_record.py @@ -67,7 +67,7 @@ def test_log_record_dropped_attributes_set_limits_max_attribute(self): self.assertTrue(result.dropped_attributes == 1) def test_log_record_dropped_attributes_set_limits_max_attribute_length( - self + self, ): attr = {"key": "value", "key2": "value2"} expected = {"key": "v", "key2": "v"} From 95c9c2298a9b4452e270a62b54c7b03e2a792839 Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Fri, 19 May 2023 11:25:14 -0700 Subject: [PATCH 19/24] Lint --- opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py | 8 ++++---- .../src/opentelemetry/sdk/_logs/_internal/__init__.py | 2 +- opentelemetry-sdk/tests/logs/test_log_limits.py | 2 +- opentelemetry-sdk/tests/logs/test_log_record.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py index 3827207d7d0..5342ca4ff90 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py @@ -14,23 +14,23 @@ from opentelemetry.sdk._logs._internal import ( + _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT, LogData, Logger, LoggerProvider, LoggingHandler, + LogLimits, LogRecord, LogRecordProcessor, - LogLimits, - _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT, ) __all__ = [ + "_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT", "LogData", "Logger", "LoggerProvider", "LoggingHandler", + "LogLimits", "LogRecord", "LogRecordProcessor", - "LogLimits", - "_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT", ] diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 68ad9feeac8..1093c60fd2e 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -19,9 +19,9 @@ import logging import threading import traceback +from os import environ from time import time_ns from typing import Any, Callable, Optional, Tuple, Union -from os import environ from opentelemetry._logs import Logger as APILogger from opentelemetry._logs import LoggerProvider as APILoggerProvider diff --git a/opentelemetry-sdk/tests/logs/test_log_limits.py b/opentelemetry-sdk/tests/logs/test_log_limits.py index 6f4a34a2608..7ceddf6539d 100644 --- a/opentelemetry-sdk/tests/logs/test_log_limits.py +++ b/opentelemetry-sdk/tests/logs/test_log_limits.py @@ -16,8 +16,8 @@ from opentelemetry.attributes import BoundedAttributes from opentelemetry.sdk._logs import ( - LogLimits, _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT, + LogLimits, ) diff --git a/opentelemetry-sdk/tests/logs/test_log_record.py b/opentelemetry-sdk/tests/logs/test_log_record.py index f3bc519bee2..a5993e5833f 100644 --- a/opentelemetry-sdk/tests/logs/test_log_record.py +++ b/opentelemetry-sdk/tests/logs/test_log_record.py @@ -16,7 +16,7 @@ import unittest from opentelemetry.attributes import BoundedAttributes -from opentelemetry.sdk._logs import LogRecord, LogLimits +from opentelemetry.sdk._logs import LogLimits, LogRecord class TestLogRecord(unittest.TestCase): From 8fba6c8039c2d2eae486dfda481346069df7dd8f Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Fri, 19 May 2023 11:32:44 -0700 Subject: [PATCH 20/24] Lint --- opentelemetry-sdk/tests/logs/test_log_limits.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/opentelemetry-sdk/tests/logs/test_log_limits.py b/opentelemetry-sdk/tests/logs/test_log_limits.py index 7ceddf6539d..f9fc780b9d8 100644 --- a/opentelemetry-sdk/tests/logs/test_log_limits.py +++ b/opentelemetry-sdk/tests/logs/test_log_limits.py @@ -14,7 +14,6 @@ import unittest -from opentelemetry.attributes import BoundedAttributes from opentelemetry.sdk._logs import ( _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT, LogLimits, @@ -23,11 +22,7 @@ class TestLogLimits(unittest.TestCase): def test_log_limits_repr_unset(self): - expected = ( - "LogLimits(max_attributes=" - + _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT - + ", max_attribute_length=None)" - ) + expected = f'LogLimits(max_attributes={_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT}, max_attribute_length=None)' limits = str(LogLimits()) self.assertEqual(expected, limits) From a8c6332dcb791c9bcba8a4a51c63751321086cb9 Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Fri, 19 May 2023 11:34:58 -0700 Subject: [PATCH 21/24] Lint --- opentelemetry-sdk/tests/logs/test_log_limits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/tests/logs/test_log_limits.py b/opentelemetry-sdk/tests/logs/test_log_limits.py index f9fc780b9d8..afc9c96d789 100644 --- a/opentelemetry-sdk/tests/logs/test_log_limits.py +++ b/opentelemetry-sdk/tests/logs/test_log_limits.py @@ -22,7 +22,7 @@ class TestLogLimits(unittest.TestCase): def test_log_limits_repr_unset(self): - expected = f'LogLimits(max_attributes={_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT}, max_attribute_length=None)' + expected = f"LogLimits(max_attributes={_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT}, max_attribute_length=None)" limits = str(LogLimits()) self.assertEqual(expected, limits) From 4946e18199733f4794b0d6d5624787ca946dab2d Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Fri, 19 May 2023 15:08:29 -0700 Subject: [PATCH 22/24] Addressed pull request comments --- .../src/opentelemetry/sdk/_logs/_internal/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py index 1093c60fd2e..7410138067c 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py @@ -58,9 +58,9 @@ class LogLimits: """This class is based on a SpanLimits class in the Tracing module. - The limits that should be enforced on recorded data such as events, links, attributes etc. + This class represents the limits that should be enforced on recorded data such as events, links, attributes etc. - This class does not enforce any limits itself. It only provides an a way read limits from env, + This class does not enforce any limits itself. It only provides a way to read limits from env, default values and from user provided arguments. All limit arguments must be either a non-negative integer, ``None`` or ``LogLimits.UNSET``. @@ -79,8 +79,8 @@ class LogLimits: Args: max_attributes: Maximum number of attributes that can be added to a span, event, and link. - Environment variable: OTEL_ATTRIBUTE_COUNT_LIMIT - Default: {_DEFAULT_ATTRIBUTE_COUNT_LIMIT} + Environment variable: ``OTEL_ATTRIBUTE_COUNT_LIMIT`` + Default: {_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT} max_attribute_length: Maximum length an attribute value can have. Values longer than the specified length will be truncated. """ From 72fade9e3b14982efacf2619af7acd72362851ca Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Mon, 22 May 2023 20:19:42 -0700 Subject: [PATCH 23/24] Addressed pull request comment, removed private variable from __all__ --- opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py | 2 -- opentelemetry-sdk/tests/logs/test_log_limits.py | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py index 5342ca4ff90..881bb9a4b27 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py @@ -14,7 +14,6 @@ from opentelemetry.sdk._logs._internal import ( - _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT, LogData, Logger, LoggerProvider, @@ -25,7 +24,6 @@ ) __all__ = [ - "_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT", "LogData", "Logger", "LoggerProvider", diff --git a/opentelemetry-sdk/tests/logs/test_log_limits.py b/opentelemetry-sdk/tests/logs/test_log_limits.py index afc9c96d789..a1c64a0d22a 100644 --- a/opentelemetry-sdk/tests/logs/test_log_limits.py +++ b/opentelemetry-sdk/tests/logs/test_log_limits.py @@ -14,10 +14,8 @@ import unittest -from opentelemetry.sdk._logs import ( - _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT, - LogLimits, -) +from opentelemetry.sdk._logs import LogLimits +from opentelemetry.sdk._logs._internal import _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT class TestLogLimits(unittest.TestCase): From 93beb55b749fdf7b247341ac217394f42cca25df Mon Sep 17 00:00:00 2001 From: Nina Stawski Date: Mon, 22 May 2023 21:06:27 -0700 Subject: [PATCH 24/24] lint --- opentelemetry-sdk/tests/logs/test_log_limits.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/opentelemetry-sdk/tests/logs/test_log_limits.py b/opentelemetry-sdk/tests/logs/test_log_limits.py index a1c64a0d22a..c2135b65694 100644 --- a/opentelemetry-sdk/tests/logs/test_log_limits.py +++ b/opentelemetry-sdk/tests/logs/test_log_limits.py @@ -15,7 +15,9 @@ import unittest from opentelemetry.sdk._logs import LogLimits -from opentelemetry.sdk._logs._internal import _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT +from opentelemetry.sdk._logs._internal import ( + _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT, +) class TestLogLimits(unittest.TestCase):