diff --git a/CHANGELOG.md b/CHANGELOG.md index e2d0b55121b..ccf9f81c10c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#1285](https://github.com/open-telemetry/opentelemetry-python/pull/1285)) - Added `__repr__` for `DefaultSpan`, added `trace_flags` to `__repr__` of `SpanContext` ([#1485](https://github.com/open-telemetry/opentelemetry-python/pull/1485)]) +### Changed +- `opentelemetry-exporter-zipkin` Updated zipkin exporter status code and error tag + ([#1486](https://github.com/open-telemetry/opentelemetry-python/pull/1486)) ## [0.16b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.16b1) - 2020-11-26 ### Added 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 c6d3559b905..6b376c203c5 100644 --- a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py +++ b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py @@ -82,6 +82,7 @@ from opentelemetry.exporter.zipkin.gen import zipkin_pb2 from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult from opentelemetry.trace import Span, SpanContext, SpanKind +from opentelemetry.trace.status import StatusCode TRANSPORT_FORMAT_JSON = "json" TRANSPORT_FORMAT_PROTOBUF = "protobuf" @@ -237,14 +238,14 @@ def _translate_to_json(self, spans: Sequence[Span]): "otel.instrumentation_library.version" ] = span.instrumentation_info.version - if span.status is not None: - zipkin_span["tags"]["otel.status_code"] = str( - span.status.status_code.value - ) - if span.status.description is not None: - zipkin_span["tags"][ - "otel.status_description" - ] = span.status.description + if span.status.status_code is not StatusCode.UNSET: + zipkin_span["tags"][ + "otel.status_code" + ] = span.status.status_code.name + if span.status.status_code is StatusCode.ERROR: + zipkin_span["tags"]["error"] = ( + span.status.description or "" + ) if context.trace_flags.sampled: zipkin_span["debug"] = True @@ -317,13 +318,13 @@ def _translate_to_protobuf(self, spans: Sequence[Span]): } ) - if span.status is not None: + if span.status.status_code is not StatusCode.UNSET: pbuf_span.tags.update( - {"otel.status_code": str(span.status.status_code.value)} + {"otel.status_code": span.status.status_code.name} ) - if span.status.description is not None: + if span.status.status_code is StatusCode.ERROR: pbuf_span.tags.update( - {"otel.status_description": span.status.description} + {"error": span.status.description or ""} ) if context.trace_flags.sampled: diff --git a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py index a21199659b8..eb3f4894c12 100644 --- a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py +++ b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py @@ -246,8 +246,8 @@ def test_export_json(self): "key_bool": "False", "key_string": "hello_world", "key_float": "111.22", - "otel.status_code": "2", - "otel.status_description": "Example description", + "otel.status_code": "ERROR", + "error": "Example description", }, "debug": True, "parentId": format(parent_id, "x"), @@ -272,10 +272,7 @@ def test_export_json(self): "duration": durations[1] // 10 ** 3, "localEndpoint": local_endpoint, "kind": span_kind, - "tags": { - "key_resource": "some_resource", - "otel.status_code": "1", - }, + "tags": {"key_resource": "some_resource"}, "annotations": None, }, { @@ -289,7 +286,6 @@ def test_export_json(self): "tags": { "key_string": "hello_world", "key_resource": "some_resource", - "otel.status_code": "1", }, "annotations": None, }, @@ -304,7 +300,6 @@ def test_export_json(self): "tags": { "otel.instrumentation_library.name": "name", "otel.instrumentation_library.version": "version", - "otel.status_code": "1", }, "annotations": None, }, @@ -383,7 +378,7 @@ def test_export_json_zero_padding(self): "duration": duration // 10 ** 3, "localEndpoint": local_endpoint, "kind": SPAN_KIND_MAP_JSON[SpanKind.INTERNAL], - "tags": {"otel.status_code": "1"}, + "tags": {}, "annotations": None, "debug": True, "parentId": "0aaaaaaaaaaaaaaa", @@ -737,6 +732,7 @@ def test_export_protobuf(self): otel_spans[1].resource = Resource( attributes={"key_resource": "some_resource"} ) + otel_spans[1].set_status(Status(StatusCode.OK)) otel_spans[1].end(end_time=end_times[1]) otel_spans[2].start(start_time=start_times[2]) @@ -775,8 +771,8 @@ def test_export_protobuf(self): "key_bool": "False", "key_string": "hello_world", "key_float": "111.22", - "otel.status_code": "2", - "otel.status_description": "Example description", + "otel.status_code": "ERROR", + "error": "Example description", }, debug=True, parent_id=ZipkinSpanExporter.format_pbuf_span_id( @@ -809,7 +805,7 @@ def test_export_protobuf(self): kind=span_kind, tags={ "key_resource": "some_resource", - "otel.status_code": "1", + "otel.status_code": "OK", }, ), zipkin_pb2.Span( @@ -825,7 +821,6 @@ def test_export_protobuf(self): tags={ "key_string": "hello_world", "key_resource": "some_resource", - "otel.status_code": "1", }, ), zipkin_pb2.Span( @@ -841,7 +836,6 @@ def test_export_protobuf(self): tags={ "otel.instrumentation_library.name": "name", "otel.instrumentation_library.version": "version", - "otel.status_code": "1", }, ), ],