From 53199dcef75b21a2647fc9661a8fc682a614a71f Mon Sep 17 00:00:00 2001 From: Wilbert Guo Date: Wed, 16 Sep 2020 10:38:23 -0700 Subject: [PATCH 1/6] [Issue #1111] Add span status to tags for Zipkin exporter --- .../src/opentelemetry/exporter/zipkin/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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 8c3c91a6d3c..e5bd81a2539 100644 --- a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py +++ b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py @@ -183,6 +183,15 @@ def _translate_to_zipkin(self, spans: Sequence[Span]): "otel.instrumentation_library.version" ] = span.instrumentation_info.version + if span.status is not None: + zipkin_span["tags"][ + "ot.status_code" + ] = span.status.canonical_code.value + if span.status.description is not None: + zipkin_span["tags"][ + "ot.status_description" + ] = span.status.description + if context.trace_flags.sampled: zipkin_span["debug"] = True From 2c05bc0a4db48411b65907839994297c01afa793 Mon Sep 17 00:00:00 2001 From: Wilbert Guo Date: Wed, 16 Sep 2020 11:57:41 -0700 Subject: [PATCH 2/6] [Issue #1111] Add status code to unit test for Zipkin exporter --- .../tests/test_zipkin_exporter.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py index 309d9668057..f2de4c7aed6 100644 --- a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py +++ b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py @@ -213,6 +213,7 @@ def test_export(self): "key_bool": "False", "key_string": "hello_world", "key_float": "111.22", + "ot.status_code":0 }, "annotations": [ { @@ -231,7 +232,10 @@ def test_export(self): "duration": durations[1] // 10 ** 3, "localEndpoint": local_endpoint, "kind": None, - "tags": {"key_resource": "some_resource"}, + "tags": { + "key_resource": "some_resource", + "ot.status_code":0 + }, "annotations": None, }, { @@ -245,6 +249,7 @@ def test_export(self): "tags": { "key_string": "hello_world", "key_resource": "some_resource", + "ot.status_code":0 }, "annotations": None, }, @@ -259,6 +264,7 @@ def test_export(self): "tags": { "otel.instrumentation_library.name": "name", "otel.instrumentation_library.version": "version", + "ot.status_code":0 }, "annotations": None, }, @@ -324,7 +330,9 @@ def test_zero_padding(self): "duration": duration // 10 ** 3, "localEndpoint": local_endpoint, "kind": None, - "tags": {}, + "tags": { + "ot.status_code":0 + }, "annotations": None, "debug": True, "parentId": "0aaaaaaaaaaaaaaa", From db9673fdd31b129cf1f382a7556c92afb49436ce Mon Sep 17 00:00:00 2001 From: Wilbert Guo Date: Wed, 16 Sep 2020 16:59:27 -0700 Subject: [PATCH 3/6] [Issue #1111] Fix lint errors --- .../tests/test_zipkin_exporter.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py index f2de4c7aed6..f2ed8e233f9 100644 --- a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py +++ b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py @@ -213,7 +213,7 @@ def test_export(self): "key_bool": "False", "key_string": "hello_world", "key_float": "111.22", - "ot.status_code":0 + "ot.status_code": 0, }, "annotations": [ { @@ -232,10 +232,7 @@ def test_export(self): "duration": durations[1] // 10 ** 3, "localEndpoint": local_endpoint, "kind": None, - "tags": { - "key_resource": "some_resource", - "ot.status_code":0 - }, + "tags": {"key_resource": "some_resource", "ot.status_code": 0}, "annotations": None, }, { @@ -249,7 +246,7 @@ def test_export(self): "tags": { "key_string": "hello_world", "key_resource": "some_resource", - "ot.status_code":0 + "ot.status_code": 0, }, "annotations": None, }, @@ -264,7 +261,7 @@ def test_export(self): "tags": { "otel.instrumentation_library.name": "name", "otel.instrumentation_library.version": "version", - "ot.status_code":0 + "ot.status_code": 0, }, "annotations": None, }, @@ -330,9 +327,7 @@ def test_zero_padding(self): "duration": duration // 10 ** 3, "localEndpoint": local_endpoint, "kind": None, - "tags": { - "ot.status_code":0 - }, + "tags": {"ot.status_code": 0}, "annotations": None, "debug": True, "parentId": "0aaaaaaaaaaaaaaa", From 9a31db19dda1ba15a61ae432e9893ae804b293c5 Mon Sep 17 00:00:00 2001 From: Wilbert Guo Date: Thu, 17 Sep 2020 08:59:03 -0700 Subject: [PATCH 4/6] [Issue #1111] Update changelog for Zipkin exporter --- exporter/opentelemetry-exporter-zipkin/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exporter/opentelemetry-exporter-zipkin/CHANGELOG.md b/exporter/opentelemetry-exporter-zipkin/CHANGELOG.md index b456edea272..72f65c0b4e5 100644 --- a/exporter/opentelemetry-exporter-zipkin/CHANGELOG.md +++ b/exporter/opentelemetry-exporter-zipkin/CHANGELOG.md @@ -11,6 +11,8 @@ ([#1097](https://github.com/open-telemetry/opentelemetry-python/pull/1097)) - Drop support for Python 3.4 ([#1099](https://github.com/open-telemetry/opentelemetry-python/pull/1099)) +- Add status mapping to tags + ([#1111](https://github.com/open-telemetry/opentelemetry-python/issues/1111)) ## Version 0.12b0 From 9a7ec134faaad8ef34baff9d1f60b29d9c048157 Mon Sep 17 00:00:00 2001 From: Wilbert Guo Date: Thu, 17 Sep 2020 09:32:00 -0700 Subject: [PATCH 5/6] [Issue #1111] Add test to test status code change and status description for Zipkin exporter --- .../tests/test_zipkin_exporter.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py index f2ed8e233f9..337bc655626 100644 --- a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py +++ b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py @@ -24,6 +24,7 @@ from opentelemetry.sdk.trace.export import SpanExportResult from opentelemetry.sdk.util.instrumentation import InstrumentationInfo from opentelemetry.trace import TraceFlags +from opentelemetry.trace.status import Status, StatusCanonicalCode class MockResponse: @@ -174,6 +175,9 @@ def test_export(self): otel_spans[0].set_attribute("key_bool", False) otel_spans[0].set_attribute("key_string", "hello_world") otel_spans[0].set_attribute("key_float", 111.22) + otel_spans[0].set_status( + Status(StatusCanonicalCode.UNKNOWN, "Example description") + ) otel_spans[0].end(end_time=end_times[0]) otel_spans[1].start(start_time=start_times[1]) @@ -213,7 +217,8 @@ def test_export(self): "key_bool": "False", "key_string": "hello_world", "key_float": "111.22", - "ot.status_code": 0, + "ot.status_code": 2, + "ot.status_description": "Example description", }, "annotations": [ { From 96d07f2eeaef2d55104f9835296e5a14d0e18077 Mon Sep 17 00:00:00 2001 From: Wilbert Guo Date: Fri, 18 Sep 2020 09:28:59 -0700 Subject: [PATCH 6/6] [Issue #1111] Changed status to use otel instead of ot --- .../src/opentelemetry/exporter/zipkin/__init__.py | 4 ++-- .../tests/test_zipkin_exporter.py | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) 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 e5bd81a2539..1e544bcdac2 100644 --- a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py +++ b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py @@ -185,11 +185,11 @@ def _translate_to_zipkin(self, spans: Sequence[Span]): if span.status is not None: zipkin_span["tags"][ - "ot.status_code" + "otel.status_code" ] = span.status.canonical_code.value if span.status.description is not None: zipkin_span["tags"][ - "ot.status_description" + "otel.status_description" ] = span.status.description 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 337bc655626..49d1c2ffe62 100644 --- a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py +++ b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py @@ -217,8 +217,8 @@ def test_export(self): "key_bool": "False", "key_string": "hello_world", "key_float": "111.22", - "ot.status_code": 2, - "ot.status_description": "Example description", + "otel.status_code": 2, + "otel.status_description": "Example description", }, "annotations": [ { @@ -237,7 +237,10 @@ def test_export(self): "duration": durations[1] // 10 ** 3, "localEndpoint": local_endpoint, "kind": None, - "tags": {"key_resource": "some_resource", "ot.status_code": 0}, + "tags": { + "key_resource": "some_resource", + "otel.status_code": 0, + }, "annotations": None, }, { @@ -251,7 +254,7 @@ def test_export(self): "tags": { "key_string": "hello_world", "key_resource": "some_resource", - "ot.status_code": 0, + "otel.status_code": 0, }, "annotations": None, }, @@ -266,7 +269,7 @@ def test_export(self): "tags": { "otel.instrumentation_library.name": "name", "otel.instrumentation_library.version": "version", - "ot.status_code": 0, + "otel.status_code": 0, }, "annotations": None, }, @@ -332,7 +335,7 @@ def test_zero_padding(self): "duration": duration // 10 ** 3, "localEndpoint": local_endpoint, "kind": None, - "tags": {"ot.status_code": 0}, + "tags": {"otel.status_code": 0}, "annotations": None, "debug": True, "parentId": "0aaaaaaaaaaaaaaa",