Skip to content

Commit b255940

Browse files
authored
Zipkin: Fix OTLP events to Zipkin annotations translation (open-telemetry#1161)
1 parent 872975b commit b255940

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

exporter/opentelemetry-exporter-zipkin/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Zipkin exporter now accepts a ``max_tag_value_length`` attribute to customize the
66
maximum allowed size a tag value can have. ([#1151](https://github.com/open-telemetry/opentelemetry-python/pull/1151))
7+
- Fixed OTLP events to Zipkin annotations translation. ([#1161](https://github.com/open-telemetry/opentelemetry-python/pull/1161))
78

89
## Version 0.13b0
910

exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,25 @@ def _extract_tags_from_span(self, span: Span):
237237
tags.update(self._extract_tags_from_dict(span.resource.attributes))
238238
return tags
239239

240-
def _extract_annotations_from_events(
241-
self, events
242-
): # pylint: disable=R0201
243-
return (
244-
[
240+
def _extract_annotations_from_events(self, events):
241+
if not events:
242+
return None
243+
244+
annotations = []
245+
for event in events:
246+
attrs = {}
247+
for key, value in event.attributes.items():
248+
if isinstance(value, str):
249+
value = value[: self.max_tag_value_length]
250+
attrs[key] = value
251+
252+
annotations.append(
245253
{
246-
"timestamp": _nsec_to_usec_round(e.timestamp),
247-
"value": e.name,
254+
"timestamp": _nsec_to_usec_round(event.timestamp),
255+
"value": json.dumps({event.name: attrs}),
248256
}
249-
for e in events
250-
]
251-
if events
252-
else None
253-
)
257+
)
258+
return annotations
254259

255260

256261
def _nsec_to_usec_round(nsec):

exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,15 @@ def test_export(self):
223223
"annotations": [
224224
{
225225
"timestamp": event_timestamp // 10 ** 3,
226-
"value": "event0",
226+
"value": json.dumps(
227+
{
228+
"event0": {
229+
"annotation_bool": True,
230+
"annotation_string": "annotation_test",
231+
"key_float": 0.3,
232+
}
233+
}
234+
),
227235
}
228236
],
229237
"debug": True,

0 commit comments

Comments
 (0)