Skip to content

Commit 4195360

Browse files
authored
Update zipkin exporter status code and error tag (open-telemetry#1486)
1 parent dbe9d38 commit 4195360

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030
([#1285](https://github.com/open-telemetry/opentelemetry-python/pull/1285))
3131
- Added `__repr__` for `DefaultSpan`, added `trace_flags` to `__repr__` of
3232
`SpanContext` ([#1485](https://github.com/open-telemetry/opentelemetry-python/pull/1485)])
33+
### Changed
34+
- `opentelemetry-exporter-zipkin` Updated zipkin exporter status code and error tag
35+
([#1486](https://github.com/open-telemetry/opentelemetry-python/pull/1486))
3336

3437
## [0.16b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.16b1) - 2020-11-26
3538
### Added

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
from opentelemetry.exporter.zipkin.gen import zipkin_pb2
8383
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
8484
from opentelemetry.trace import Span, SpanContext, SpanKind
85+
from opentelemetry.trace.status import StatusCode
8586

8687
TRANSPORT_FORMAT_JSON = "json"
8788
TRANSPORT_FORMAT_PROTOBUF = "protobuf"
@@ -237,14 +238,14 @@ def _translate_to_json(self, spans: Sequence[Span]):
237238
"otel.instrumentation_library.version"
238239
] = span.instrumentation_info.version
239240

240-
if span.status is not None:
241-
zipkin_span["tags"]["otel.status_code"] = str(
242-
span.status.status_code.value
243-
)
244-
if span.status.description is not None:
245-
zipkin_span["tags"][
246-
"otel.status_description"
247-
] = span.status.description
241+
if span.status.status_code is not StatusCode.UNSET:
242+
zipkin_span["tags"][
243+
"otel.status_code"
244+
] = span.status.status_code.name
245+
if span.status.status_code is StatusCode.ERROR:
246+
zipkin_span["tags"]["error"] = (
247+
span.status.description or ""
248+
)
248249

249250
if context.trace_flags.sampled:
250251
zipkin_span["debug"] = True
@@ -317,13 +318,13 @@ def _translate_to_protobuf(self, spans: Sequence[Span]):
317318
}
318319
)
319320

320-
if span.status is not None:
321+
if span.status.status_code is not StatusCode.UNSET:
321322
pbuf_span.tags.update(
322-
{"otel.status_code": str(span.status.status_code.value)}
323+
{"otel.status_code": span.status.status_code.name}
323324
)
324-
if span.status.description is not None:
325+
if span.status.status_code is StatusCode.ERROR:
325326
pbuf_span.tags.update(
326-
{"otel.status_description": span.status.description}
327+
{"error": span.status.description or ""}
327328
)
328329

329330
if context.trace_flags.sampled:

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ def test_export_json(self):
246246
"key_bool": "False",
247247
"key_string": "hello_world",
248248
"key_float": "111.22",
249-
"otel.status_code": "2",
250-
"otel.status_description": "Example description",
249+
"otel.status_code": "ERROR",
250+
"error": "Example description",
251251
},
252252
"debug": True,
253253
"parentId": format(parent_id, "x"),
@@ -272,10 +272,7 @@ def test_export_json(self):
272272
"duration": durations[1] // 10 ** 3,
273273
"localEndpoint": local_endpoint,
274274
"kind": span_kind,
275-
"tags": {
276-
"key_resource": "some_resource",
277-
"otel.status_code": "1",
278-
},
275+
"tags": {"key_resource": "some_resource"},
279276
"annotations": None,
280277
},
281278
{
@@ -289,7 +286,6 @@ def test_export_json(self):
289286
"tags": {
290287
"key_string": "hello_world",
291288
"key_resource": "some_resource",
292-
"otel.status_code": "1",
293289
},
294290
"annotations": None,
295291
},
@@ -304,7 +300,6 @@ def test_export_json(self):
304300
"tags": {
305301
"otel.instrumentation_library.name": "name",
306302
"otel.instrumentation_library.version": "version",
307-
"otel.status_code": "1",
308303
},
309304
"annotations": None,
310305
},
@@ -383,7 +378,7 @@ def test_export_json_zero_padding(self):
383378
"duration": duration // 10 ** 3,
384379
"localEndpoint": local_endpoint,
385380
"kind": SPAN_KIND_MAP_JSON[SpanKind.INTERNAL],
386-
"tags": {"otel.status_code": "1"},
381+
"tags": {},
387382
"annotations": None,
388383
"debug": True,
389384
"parentId": "0aaaaaaaaaaaaaaa",
@@ -737,6 +732,7 @@ def test_export_protobuf(self):
737732
otel_spans[1].resource = Resource(
738733
attributes={"key_resource": "some_resource"}
739734
)
735+
otel_spans[1].set_status(Status(StatusCode.OK))
740736
otel_spans[1].end(end_time=end_times[1])
741737

742738
otel_spans[2].start(start_time=start_times[2])
@@ -775,8 +771,8 @@ def test_export_protobuf(self):
775771
"key_bool": "False",
776772
"key_string": "hello_world",
777773
"key_float": "111.22",
778-
"otel.status_code": "2",
779-
"otel.status_description": "Example description",
774+
"otel.status_code": "ERROR",
775+
"error": "Example description",
780776
},
781777
debug=True,
782778
parent_id=ZipkinSpanExporter.format_pbuf_span_id(
@@ -809,7 +805,7 @@ def test_export_protobuf(self):
809805
kind=span_kind,
810806
tags={
811807
"key_resource": "some_resource",
812-
"otel.status_code": "1",
808+
"otel.status_code": "OK",
813809
},
814810
),
815811
zipkin_pb2.Span(
@@ -825,7 +821,6 @@ def test_export_protobuf(self):
825821
tags={
826822
"key_string": "hello_world",
827823
"key_resource": "some_resource",
828-
"otel.status_code": "1",
829824
},
830825
),
831826
zipkin_pb2.Span(
@@ -841,7 +836,6 @@ def test_export_protobuf(self):
841836
tags={
842837
"otel.instrumentation_library.name": "name",
843838
"otel.instrumentation_library.version": "version",
844-
"otel.status_code": "1",
845839
},
846840
),
847841
],

0 commit comments

Comments
 (0)