Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use BoundedAttributes instead of raw dict to extract attributes from LogRecord #3114 #3310

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3fd450d
Switched to using BoundedAttributes as per #3114
nstawski May 10, 2023
986ba7d
Switched to using BoundedAttributes as per #3114
nstawski May 10, 2023
6a3b62a
Code linting
nstawski May 10, 2023
2d88ce4
Code linting
nstawski May 10, 2023
1c5b20c
Code linting
nstawski May 10, 2023
bdae2f2
Comment
nstawski May 10, 2023
deff884
Moved the instantiating of BoundedAttributes into the LogRecord class…
nstawski May 11, 2023
58b734d
Properly serializing the items from BoundedAttributes in to_json sinc…
nstawski May 11, 2023
2dd23e5
Update version to 1.19.0.dev/0.40b0.dev (#3297)
opentelemetrybot May 12, 2023
13f2426
Merge branch 'open-telemetry:main' into ns-3114-bounded-attributes-in…
nstawski May 15, 2023
9f88cd5
Lint
nstawski May 15, 2023
f626411
Tests + changelog update
nstawski May 15, 2023
820eb09
Lint
nstawski May 15, 2023
4749c8e
Added limits + tests
nstawski May 19, 2023
7c39620
Updated changelog
nstawski May 19, 2023
cb17281
Added LogLimits and tests
nstawski May 19, 2023
387c928
Lint
nstawski May 19, 2023
3e6e5ea
Lint
nstawski May 19, 2023
b1a646d
Lint
nstawski May 19, 2023
95c9c22
Lint
nstawski May 19, 2023
8fba6c8
Lint
nstawski May 19, 2023
a8c6332
Lint
nstawski May 19, 2023
4946e18
Addressed pull request comments
nstawski May 19, 2023
08df03c
Merge branch 'main' into ns-3114-bounded-attributes-insteadof-dict-Lo…
ocelotl May 23, 2023
72fade9
Addressed pull request comment, removed private variable from __all__
nstawski May 23, 2023
93beb55
lint
nstawski May 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,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,
nstawski marked this conversation as resolved.
Show resolved Hide resolved
immutable=False,
),
nstawski marked this conversation as resolved.
Show resolved Hide resolved
}
)
self.resource = resource
Expand All @@ -93,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": 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
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-sdk/tests/logs/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand Down
8 changes: 8 additions & 0 deletions opentelemetry-sdk/tests/logs/test_log_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import json
import unittest

from opentelemetry.attributes import BoundedAttributes
from opentelemetry.sdk._logs import LogRecord


Expand All @@ -39,3 +40,10 @@ 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))
ocelotl marked this conversation as resolved.
Show resolved Hide resolved