diff --git a/exporter/opentelemetry-exporter-zipkin/CHANGELOG.md b/exporter/opentelemetry-exporter-zipkin/CHANGELOG.md index a980e345684..3801c81dc92 100644 --- a/exporter/opentelemetry-exporter-zipkin/CHANGELOG.md +++ b/exporter/opentelemetry-exporter-zipkin/CHANGELOG.md @@ -4,6 +4,7 @@ - Zipkin exporter now accepts a ``max_tag_value_length`` attribute to customize the maximum allowed size a tag value can have. ([#1151](https://github.com/open-telemetry/opentelemetry-python/pull/1151)) +- Fixed OTLP events to Zipkin annotations translation. ([#1161](https://github.com/open-telemetry/opentelemetry-python/pull/1161)) ## Version 0.13b0 diff --git a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py index 5e544275b33..bacfcc278d3 100644 --- a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py +++ b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py @@ -237,20 +237,25 @@ def _extract_tags_from_span(self, span: Span): tags.update(self._extract_tags_from_dict(span.resource.attributes)) return tags - def _extract_annotations_from_events( - self, events - ): # pylint: disable=R0201 - return ( - [ + def _extract_annotations_from_events(self, events): + if not events: + return None + + annotations = [] + for event in events: + attrs = {} + for key, value in event.attributes.items(): + if isinstance(value, str): + value = value[: self.max_tag_value_length] + attrs[key] = value + + annotations.append( { - "timestamp": _nsec_to_usec_round(e.timestamp), - "value": e.name, + "timestamp": _nsec_to_usec_round(event.timestamp), + "value": json.dumps({event.name: attrs}), } - for e in events - ] - if events - else None - ) + ) + return annotations def _nsec_to_usec_round(nsec): diff --git a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py index 635594868f2..1979d8459f6 100644 --- a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py +++ b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py @@ -223,7 +223,15 @@ def test_export(self): "annotations": [ { "timestamp": event_timestamp // 10 ** 3, - "value": "event0", + "value": json.dumps( + { + "event0": { + "annotation_bool": True, + "annotation_string": "annotation_test", + "key_float": 0.3, + } + } + ), } ], "debug": True,