-
Couldn't load subscription status.
- Fork 757
log the attribute's key when encoding an attribute fails #3838
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
Merged
lzchen
merged 8 commits into
open-telemetry:main
from
danielhochman:log-unencodeable-key
Jun 26, 2024
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8378caf
log the key when encoding the attribute fails
danielhochman de1c4ed
Merge branch 'main' of github.com:open-telemetry/opentelemetry-python…
danielhochman 8ed207c
use assertLogs
danielhochman b6f6b48
Update exporter/opentelemetry-exporter-otlp-proto-common/tests/test_a…
xrmx 1667b0a
fix test
danielhochman 3a9d2c1
CHANGELOG entry
danielhochman b3f37b3
Merge branch 'main' into log-unencodeable-key
lzchen 1828093
Merge branch 'main' into log-unencodeable-key
lzchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
exporter/opentelemetry-exporter-otlp-proto-common/tests/test_attribute_encoder.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import unittest | ||
| from logging import ERROR | ||
|
|
||
| from opentelemetry.exporter.otlp.proto.common._internal import ( | ||
| _encode_attributes, | ||
| ) | ||
| from opentelemetry.proto.common.v1.common_pb2 import AnyValue as PB2AnyValue | ||
| from opentelemetry.proto.common.v1.common_pb2 import ( | ||
| ArrayValue as PB2ArrayValue, | ||
| ) | ||
| from opentelemetry.proto.common.v1.common_pb2 import KeyValue as PB2KeyValue | ||
|
|
||
|
|
||
| class TestOTLPAttributeEncoder(unittest.TestCase): | ||
| def test_encode_attributes_all_kinds(self): | ||
| result = _encode_attributes( | ||
| { | ||
| "a": 1, # int | ||
| "b": 3.14, # float | ||
| "c": False, # bool | ||
| "hello": "world", # str | ||
| "greet": ["hola", "bonjour"], # Sequence[str] | ||
| "data": [1, 2], # Sequence[int] | ||
| "data_granular": [1.4, 2.4], # Sequence[float] | ||
| } | ||
| ) | ||
| self.assertEqual( | ||
| result, | ||
| [ | ||
| PB2KeyValue(key="a", value=PB2AnyValue(int_value=1)), | ||
| PB2KeyValue(key="b", value=PB2AnyValue(double_value=3.14)), | ||
| PB2KeyValue(key="c", value=PB2AnyValue(bool_value=False)), | ||
| PB2KeyValue( | ||
| key="hello", value=PB2AnyValue(string_value="world") | ||
| ), | ||
| PB2KeyValue( | ||
| key="greet", | ||
| value=PB2AnyValue( | ||
| array_value=PB2ArrayValue( | ||
| values=[ | ||
| PB2AnyValue(string_value="hola"), | ||
| PB2AnyValue(string_value="bonjour"), | ||
| ] | ||
| ) | ||
| ), | ||
| ), | ||
| PB2KeyValue( | ||
| key="data", | ||
| value=PB2AnyValue( | ||
| array_value=PB2ArrayValue( | ||
| values=[ | ||
| PB2AnyValue(int_value=1), | ||
| PB2AnyValue(int_value=2), | ||
| ] | ||
| ) | ||
| ), | ||
| ), | ||
| PB2KeyValue( | ||
| key="data_granular", | ||
| value=PB2AnyValue( | ||
| array_value=PB2ArrayValue( | ||
| values=[ | ||
| PB2AnyValue(double_value=1.4), | ||
| PB2AnyValue(double_value=2.4), | ||
| ] | ||
| ) | ||
| ), | ||
| ), | ||
| ], | ||
| ) | ||
|
|
||
| def test_encode_attributes_error_logs_key(self): | ||
| with self.assertLogs(level=ERROR) as error: | ||
| result = _encode_attributes({"a": 1, "bad_key": None, "b": 2}) | ||
|
|
||
| self.assertEqual(len(error.records), 1) | ||
| self.assertEqual(error.records[0].msg, f"Failed to encode key %s: %s") | ||
| self.assertEqual(error.records[0].args[0], "bad_key") | ||
| self.assertIsInstance(error.records[0].args[1], Exception) | ||
| self.assertEqual( | ||
| result, | ||
| [ | ||
| PB2KeyValue(key="a", value=PB2AnyValue(int_value=1)), | ||
| PB2KeyValue(key="b", value=PB2AnyValue(int_value=2)), | ||
| ], | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.