Skip to content

Commit

Permalink
Update zipkin exporter status code and error tag (#1486)
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv authored Dec 23, 2020
1 parent dbe9d38 commit 4195360
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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,
},
{
Expand All @@ -289,7 +286,6 @@ def test_export_json(self):
"tags": {
"key_string": "hello_world",
"key_resource": "some_resource",
"otel.status_code": "1",
},
"annotations": None,
},
Expand All @@ -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,
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -841,7 +836,6 @@ def test_export_protobuf(self):
tags={
"otel.instrumentation_library.name": "name",
"otel.instrumentation_library.version": "version",
"otel.status_code": "1",
},
),
],
Expand Down

0 comments on commit 4195360

Please sign in to comment.