-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
106 changed files
with
2,269 additions
and
1,224 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
100 changes: 100 additions & 0 deletions
100
exporter/opentelemetry-exporter-otlp-proto-common/tests/test_attribute_encoder.py
This file contains 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,100 @@ | ||
# 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 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, "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)), | ||
], | ||
) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.