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

Zipkin: Update span boolean attribute conversion #1509

Merged
merged 4 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1513](https://github.com/open-telemetry/opentelemetry-python/pull/1513))
- Update default port for OTLP exporter from 55680 to 4317
([#1516](https://github.com/open-telemetry/opentelemetry-python/pull/1516))
- `opentelemetry-exporter-zipkin` Update boolean attribute value transformation
([#1509](https://github.com/open-telemetry/opentelemetry-python/pull/1509))

### Removed
- `opentelemetry-api` Remove ThreadLocalRuntimeContext since python3.4 is not supported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ def _extract_tags_from_dict(self, tags_dict):
if not tags_dict:
return tags
for attribute_key, attribute_value in tags_dict.items():
if isinstance(attribute_value, (int, bool, float, str)):
if isinstance(attribute_value, bool):
value = str(attribute_value).lower()
elif isinstance(attribute_value, (int, float, str)):
value = str(attribute_value)
elif isinstance(attribute_value, Sequence):
value = self._extract_tag_value_string_from_sequence(
Expand Down Expand Up @@ -381,7 +383,9 @@ def _extract_tag_value_string_from_sequence(self, sequence: Sequence):
defined_max_tag_value_length = self.max_tag_value_length > 0

for element in sequence:
if isinstance(element, (int, bool, float, str)):
if isinstance(element, bool):
tag_value_element = str(element).lower()
elif isinstance(element, (int, float, str)):
tag_value_element = str(element)
elif element is None:
tag_value_element = None
Expand All @@ -407,7 +411,7 @@ def _extract_tag_value_string_from_sequence(self, sequence: Sequence):
return json.dumps(tag_value_elements, separators=(",", ":"))

def _extract_tags_from_span(self, span: Span):
tags = self._extract_tags_from_dict(getattr(span, "attributes", None))
tags = self._extract_tags_from_dict(span.attributes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a specific reason we were using getattr?

Copy link
Contributor

@owais owais Jan 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be because API Span does not have "attributes" attribute and it might be used as a noop span in some situations? That'd be my guess.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Better of just leave it then. @lonewolf3739

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig into to see if I could find some relevant comments when this was added. #707 (comment) this was the discussion that introduced this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering If that is true we should be doing that all other attributes such as events, status, timestamps, kind and instrumentation_info etc.. and that should be done for not just zipkin but all exporters?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does SpanProcessor not take care of discarding those DefaultSpans?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toumorokoshi
Does this use case still apply?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this would happen (we check for DefaultSpan in the span processor and it should never reach the exporter).

if span.resource:
tags.update(self._extract_tags_from_dict(span.resource.attributes))
return tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def test_export_json(self):
"localEndpoint": local_endpoint,
"kind": span_kind,
"tags": {
"key_bool": "False",
"key_bool": "false",
"key_string": "hello_world",
"key_float": "111.22",
"otel.status_code": "ERROR",
Expand Down Expand Up @@ -471,11 +471,11 @@ def test_export_json_max_tag_length(self):
)
self.assertEqual(
tags["list5"],
'["True","True","True","True","True","True","True","True","True","True","True","True","True","True","True","True","True","True"]',
'["true","true","true","true","true","true","true","true","true","true","true","true","true","true","true","true","true","true"]',
)
self.assertEqual(
tags["list6"],
'["True","True","True","True","True","True","True","True","True","True"]',
'["true","true","true","true","true","true","true","true","true","true"]',
)
self.assertEqual(
tags["tuple1"],
Expand All @@ -493,11 +493,11 @@ def test_export_json_max_tag_length(self):
)
self.assertEqual(
tags["tuple5"],
'["True","True","True","True","True","True","True","True","True","True","True","True","True","True","True","True","True","True"]',
'["true","true","true","true","true","true","true","true","true","true","true","true","true","true","true","true","true","true"]',
)
self.assertEqual(
tags["tuple6"],
'["True","True","True","True","True","True","True","True","True","True"]',
'["true","true","true","true","true","true","true","true","true","true"]',
)
self.assertEqual(
tags["range1"],
Expand Down Expand Up @@ -580,14 +580,14 @@ def test_export_json_max_tag_length(self):
self.assertEqual(tags["list2"], '["a","a"]')
self.assertEqual(tags["list3"], '["2","2"]')
self.assertEqual(tags["list4"], '["2","2"]')
self.assertEqual(tags["list5"], '["True"]')
self.assertEqual(tags["list6"], '["True"]')
self.assertEqual(tags["list5"], '["true"]')
self.assertEqual(tags["list6"], '["true"]')
self.assertEqual(tags["tuple1"], '["a","a"]')
self.assertEqual(tags["tuple2"], '["a","a"]')
self.assertEqual(tags["tuple3"], '["2","2"]')
self.assertEqual(tags["tuple4"], '["2","2"]')
self.assertEqual(tags["tuple5"], '["True"]')
self.assertEqual(tags["tuple6"], '["True"]')
self.assertEqual(tags["tuple5"], '["true"]')
self.assertEqual(tags["tuple6"], '["true"]')
self.assertEqual(tags["range1"], '["0","1"]')
self.assertEqual(tags["range2"], '["0","1"]')

Expand All @@ -606,14 +606,14 @@ def test_export_json_max_tag_length(self):
self.assertEqual(tags["list2"], '["a","a"]')
self.assertEqual(tags["list3"], '["2","2"]')
self.assertEqual(tags["list4"], '["2","2"]')
self.assertEqual(tags["list5"], '["True"]')
self.assertEqual(tags["list6"], '["True"]')
self.assertEqual(tags["list5"], '["true"]')
self.assertEqual(tags["list6"], '["true"]')
self.assertEqual(tags["tuple1"], '["a","a"]')
self.assertEqual(tags["tuple2"], '["a","a"]')
self.assertEqual(tags["tuple3"], '["2","2"]')
self.assertEqual(tags["tuple4"], '["2","2"]')
self.assertEqual(tags["tuple5"], '["True"]')
self.assertEqual(tags["tuple6"], '["True"]')
self.assertEqual(tags["tuple5"], '["true"]')
self.assertEqual(tags["tuple6"], '["true"]')
self.assertEqual(tags["range1"], '["0","1"]')
self.assertEqual(tags["range2"], '["0","1"]')

Expand All @@ -632,14 +632,14 @@ def test_export_json_max_tag_length(self):
self.assertEqual(tags["list2"], '["a","a"]')
self.assertEqual(tags["list3"], '["2","2"]')
self.assertEqual(tags["list4"], '["2","2"]')
self.assertEqual(tags["list5"], '["True"]')
self.assertEqual(tags["list6"], '["True"]')
self.assertEqual(tags["list5"], '["true"]')
self.assertEqual(tags["list6"], '["true"]')
self.assertEqual(tags["tuple1"], '["a","a"]')
self.assertEqual(tags["tuple2"], '["a","a"]')
self.assertEqual(tags["tuple3"], '["2","2"]')
self.assertEqual(tags["tuple4"], '["2","2"]')
self.assertEqual(tags["tuple5"], '["True"]')
self.assertEqual(tags["tuple6"], '["True"]')
self.assertEqual(tags["tuple5"], '["true"]')
self.assertEqual(tags["tuple6"], '["true"]')
self.assertEqual(tags["range1"], '["0","1"]')
self.assertEqual(tags["range2"], '["0","1"]')

Expand Down Expand Up @@ -768,7 +768,7 @@ def test_export_protobuf(self):
local_endpoint=local_endpoint,
kind=span_kind,
tags={
"key_bool": "False",
"key_bool": "false",
"key_string": "hello_world",
"key_float": "111.22",
"otel.status_code": "ERROR",
Expand Down