Skip to content

Commit f1199ff

Browse files
wilguoMichael Stella
authored and
Michael Stella
committed
exporter/zipkin: Add status to the tags for the Zipkin Exporter (open-telemetry#1124)
* [Issue open-telemetry#1111] Add span status to tags for Zipkin exporter
1 parent 3cdbbd6 commit f1199ff

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

exporter/opentelemetry-exporter-zipkin/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Released 2020-09-17
1515
([#1097](https://github.com/open-telemetry/opentelemetry-python/pull/1097))
1616
- Drop support for Python 3.4
1717
([#1099](https://github.com/open-telemetry/opentelemetry-python/pull/1099))
18+
- Add status mapping to tags
19+
([#1111](https://github.com/open-telemetry/opentelemetry-python/issues/1111))
1820

1921
## Version 0.12b0
2022

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

+9
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ def _translate_to_zipkin(self, spans: Sequence[Span]):
183183
"otel.instrumentation_library.version"
184184
] = span.instrumentation_info.version
185185

186+
if span.status is not None:
187+
zipkin_span["tags"][
188+
"otel.status_code"
189+
] = span.status.canonical_code.value
190+
if span.status.description is not None:
191+
zipkin_span["tags"][
192+
"otel.status_description"
193+
] = span.status.description
194+
186195
if context.trace_flags.sampled:
187196
zipkin_span["debug"] = True
188197

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

+13-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from opentelemetry.sdk.trace.export import SpanExportResult
2525
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
2626
from opentelemetry.trace import TraceFlags
27+
from opentelemetry.trace.status import Status, StatusCanonicalCode
2728

2829

2930
class MockResponse:
@@ -174,6 +175,9 @@ def test_export(self):
174175
otel_spans[0].set_attribute("key_bool", False)
175176
otel_spans[0].set_attribute("key_string", "hello_world")
176177
otel_spans[0].set_attribute("key_float", 111.22)
178+
otel_spans[0].set_status(
179+
Status(StatusCanonicalCode.UNKNOWN, "Example description")
180+
)
177181
otel_spans[0].end(end_time=end_times[0])
178182

179183
otel_spans[1].start(start_time=start_times[1])
@@ -213,6 +217,8 @@ def test_export(self):
213217
"key_bool": "False",
214218
"key_string": "hello_world",
215219
"key_float": "111.22",
220+
"otel.status_code": 2,
221+
"otel.status_description": "Example description",
216222
},
217223
"annotations": [
218224
{
@@ -231,7 +237,10 @@ def test_export(self):
231237
"duration": durations[1] // 10 ** 3,
232238
"localEndpoint": local_endpoint,
233239
"kind": None,
234-
"tags": {"key_resource": "some_resource"},
240+
"tags": {
241+
"key_resource": "some_resource",
242+
"otel.status_code": 0,
243+
},
235244
"annotations": None,
236245
},
237246
{
@@ -245,6 +254,7 @@ def test_export(self):
245254
"tags": {
246255
"key_string": "hello_world",
247256
"key_resource": "some_resource",
257+
"otel.status_code": 0,
248258
},
249259
"annotations": None,
250260
},
@@ -259,6 +269,7 @@ def test_export(self):
259269
"tags": {
260270
"otel.instrumentation_library.name": "name",
261271
"otel.instrumentation_library.version": "version",
272+
"otel.status_code": 0,
262273
},
263274
"annotations": None,
264275
},
@@ -324,7 +335,7 @@ def test_zero_padding(self):
324335
"duration": duration // 10 ** 3,
325336
"localEndpoint": local_endpoint,
326337
"kind": None,
327-
"tags": {},
338+
"tags": {"otel.status_code": 0},
328339
"annotations": None,
329340
"debug": True,
330341
"parentId": "0aaaaaaaaaaaaaaa",

0 commit comments

Comments
 (0)