-
Notifications
You must be signed in to change notification settings - Fork 653
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
Adding support for array attributes to Zipkin exporter #1285
Adding support for array attributes to Zipkin exporter #1285
Conversation
exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py
Outdated
Show resolved
Hide resolved
exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py
Outdated
Show resolved
Hide resolved
if isinstance(element, (int, bool, float)): | ||
tag_value_element = str(element) | ||
elif isinstance(element, str): | ||
tag_value_element = element |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit L354 to 357 repeated here, could be refactored. One complication is sequence attributes are allowed to have None
.
Could also combine the two conditions
if isinstance(element, (int, bool, float)): | |
tag_value_element = str(element) | |
elif isinstance(element, str): | |
tag_value_element = element | |
if isinstance(element, (int, bool, float, str)): | |
tag_value_element = str(element) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified the formatting as recommended but didn't refactor the duplication as it's small.
I also changed the logic to silently skip invalid sequence elements versus completely failing so that we're passing along as much data s possible.
running_string_length += ( | ||
2 # accounts for ', ' connector | ||
) | ||
if running_string_length > self.max_tag_value_length: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is max_tag_value_length
supposed to be encoded byte length or string length?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're outputting as ASCII with json.dumps() so one and the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure actually so I checked the python docs:
If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped.
So I think if the escape sequences are long, you could get longer length. I think this is OK tho 😄 Maybe just update max_tag_value_length
docstring to say its string length if not specified?
exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py
Outdated
Show resolved
Hide resolved
…thub.com/robwknox/opentelemetry-python into 1110_zipkin_exporter_support_array_attrs
…elements versus bailing completely out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an aside, I believe I've identified a bug in that bool objects are supposed to be serialized to
true
orfalse
to adhere to JSON spec, but we appear to be retaining python formatting ofTrue
andFalse
. Will file a separate bug report.
👍
Nice and thanks for addressing comments! LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just leaving some suggestions.
value = self._extract_tag_value_string_from_sequence( | ||
attribute_value | ||
) | ||
if not value: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not value: | |
if value is None: |
) | ||
self.assertEqual( | ||
tags["list5"], | ||
'["True","True","True","True","True","True","True","True","True","True","True","True","True","True","True","True","True","True"]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'["True","True","True","True","True","True","True","True","True","True","True","True","True","True","True","True","True","True"]', | |
partial_dump([str(True)] * 25) |
@@ -440,8 +457,66 @@ def test_export_json_max_tag_length(self): | |||
_, kwargs = mock_post.call_args # pylint: disable=E0633 | |||
|
|||
tags = json.loads(kwargs["data"])[0]["tags"] | |||
self.assertEqual(len(tags["k1"]), 128) | |||
self.assertEqual(len(tags["k2"]), 50) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid these long testing sequences, may I suggest:
from functools import partial
from json import dumps
...
partial_dumps = partial(dumps, separators=(",", ":"))
self.assertEqual(len(tags["string2"]), 50) | ||
self.assertEqual( | ||
tags["list1"], | ||
'["a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a"]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'["a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a"]', | |
partial_dumps(["a"] * 25), |
) | ||
self.assertEqual( | ||
tags["range1"], | ||
'["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"]', | |
partial_dumps([str(i) for i in range(25)]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Adds support for basic sequence (list, tuple, range) attribute values in the Zipkin exporter.
Since the value is serialized to a JSON list string, specific logic is needed to ensure max_tag_value_length is honored at the element boundary.
As an aside, I believe I've identified a bug in that bool objects are supposed to be serialized to
true
orfalse
to adhere to JSON spec, but we appear to be retaining python formatting ofTrue
andFalse
. Will file a separate bug report.Fixes #1110
Type of change
How Has This Been Tested?
tox environments:
Checklist: