exporter/zipkin: Add status to the tags for the Zipkin Exporter (#1124)

* [Issue #1111] Add span status to tags for Zipkin exporter
This commit is contained in:
Wilbert Guo 2020-09-18 15:03:52 -07:00 committed by alrex
parent 91ce098855
commit 9d396382e3
3 changed files with 24 additions and 2 deletions

View File

@ -15,6 +15,8 @@ Released 2020-09-17
([#1097](https://github.com/open-telemetry/opentelemetry-python/pull/1097)) ([#1097](https://github.com/open-telemetry/opentelemetry-python/pull/1097))
- Drop support for Python 3.4 - Drop support for Python 3.4
([#1099](https://github.com/open-telemetry/opentelemetry-python/pull/1099)) ([#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 ## Version 0.12b0

View File

@ -183,6 +183,15 @@ class ZipkinSpanExporter(SpanExporter):
"otel.instrumentation_library.version" "otel.instrumentation_library.version"
] = span.instrumentation_info.version ] = span.instrumentation_info.version
if span.status is not None:
zipkin_span["tags"][
"otel.status_code"
] = span.status.canonical_code.value
if span.status.description is not None:
zipkin_span["tags"][
"otel.status_description"
] = span.status.description
if context.trace_flags.sampled: if context.trace_flags.sampled:
zipkin_span["debug"] = True zipkin_span["debug"] = True

View File

@ -24,6 +24,7 @@ from opentelemetry.sdk.trace import Resource
from opentelemetry.sdk.trace.export import SpanExportResult from opentelemetry.sdk.trace.export import SpanExportResult
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.trace import TraceFlags from opentelemetry.trace import TraceFlags
from opentelemetry.trace.status import Status, StatusCanonicalCode
class MockResponse: class MockResponse:
@ -174,6 +175,9 @@ class TestZipkinSpanExporter(unittest.TestCase):
otel_spans[0].set_attribute("key_bool", False) otel_spans[0].set_attribute("key_bool", False)
otel_spans[0].set_attribute("key_string", "hello_world") otel_spans[0].set_attribute("key_string", "hello_world")
otel_spans[0].set_attribute("key_float", 111.22) 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[0].end(end_time=end_times[0])
otel_spans[1].start(start_time=start_times[1]) otel_spans[1].start(start_time=start_times[1])
@ -213,6 +217,8 @@ class TestZipkinSpanExporter(unittest.TestCase):
"key_bool": "False", "key_bool": "False",
"key_string": "hello_world", "key_string": "hello_world",
"key_float": "111.22", "key_float": "111.22",
"otel.status_code": 2,
"otel.status_description": "Example description",
}, },
"annotations": [ "annotations": [
{ {
@ -231,7 +237,10 @@ class TestZipkinSpanExporter(unittest.TestCase):
"duration": durations[1] // 10 ** 3, "duration": durations[1] // 10 ** 3,
"localEndpoint": local_endpoint, "localEndpoint": local_endpoint,
"kind": None, "kind": None,
"tags": {"key_resource": "some_resource"}, "tags": {
"key_resource": "some_resource",
"otel.status_code": 0,
},
"annotations": None, "annotations": None,
}, },
{ {
@ -245,6 +254,7 @@ class TestZipkinSpanExporter(unittest.TestCase):
"tags": { "tags": {
"key_string": "hello_world", "key_string": "hello_world",
"key_resource": "some_resource", "key_resource": "some_resource",
"otel.status_code": 0,
}, },
"annotations": None, "annotations": None,
}, },
@ -259,6 +269,7 @@ class TestZipkinSpanExporter(unittest.TestCase):
"tags": { "tags": {
"otel.instrumentation_library.name": "name", "otel.instrumentation_library.name": "name",
"otel.instrumentation_library.version": "version", "otel.instrumentation_library.version": "version",
"otel.status_code": 0,
}, },
"annotations": None, "annotations": None,
}, },
@ -324,7 +335,7 @@ class TestZipkinSpanExporter(unittest.TestCase):
"duration": duration // 10 ** 3, "duration": duration // 10 ** 3,
"localEndpoint": local_endpoint, "localEndpoint": local_endpoint,
"kind": None, "kind": None,
"tags": {}, "tags": {"otel.status_code": 0},
"annotations": None, "annotations": None,
"debug": True, "debug": True,
"parentId": "0aaaaaaaaaaaaaaa", "parentId": "0aaaaaaaaaaaaaaa",