Skip to content

Commit f3cdfa2

Browse files
authored
Change status codes from grpc status codes, remove setting status in instrumentations except on ERROR (#1282)
1 parent 42abfb7 commit f3cdfa2

File tree

55 files changed

+265
-517
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+265
-517
lines changed

docs/examples/auto-instrumentation/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ similar to:
112112
"start_time": "2020-04-30T17:28:57.886397Z",
113113
"end_time": "2020-04-30T17:28:57.886490Z",
114114
"status": {
115-
"canonical_code": "OK"
115+
"status_code": "OK"
116116
},
117117
"attributes": {
118118
"component": "http",
@@ -164,7 +164,7 @@ similar to:
164164
"start_time": "2020-04-30T17:10:02.400604Z",
165165
"end_time": "2020-04-30T17:10:02.401858Z",
166166
"status": {
167-
"canonical_code": "OK"
167+
"status_code": "OK"
168168
},
169169
"attributes": {
170170
"component": "http",

docs/examples/django/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ output similar to this one:
7777
"start_time": "2020-04-26T01:49:57.205833Z",
7878
"end_time": "2020-04-26T01:49:57.206214Z",
7979
"status": {
80-
"canonical_code": "OK"
80+
"status_code": "OK"
8181
},
8282
"attributes": {
8383
"component": "http",

docs/getting-started.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ We can run it, and see the traces print to your console:
4949
"start_time": "2020-05-07T14:39:52.906272Z",
5050
"end_time": "2020-05-07T14:39:52.906343Z",
5151
"status": {
52-
"canonical_code": "OK"
52+
"status_code": "OK"
5353
},
5454
"attributes": {},
5555
"events": [],
@@ -67,7 +67,7 @@ We can run it, and see the traces print to your console:
6767
"start_time": "2020-05-07T14:39:52.906230Z",
6868
"end_time": "2020-05-07T14:39:52.906601Z",
6969
"status": {
70-
"canonical_code": "OK"
70+
"status_code": "OK"
7171
},
7272
"attributes": {},
7373
"events": [],
@@ -85,7 +85,7 @@ We can run it, and see the traces print to your console:
8585
"start_time": "2020-05-07T14:39:52.906157Z",
8686
"end_time": "2020-05-07T14:39:52.906743Z",
8787
"status": {
88-
"canonical_code": "OK"
88+
"status_code": "OK"
8989
},
9090
"attributes": {},
9191
"events": [],

exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import opentelemetry.trace as trace_api
2424
from opentelemetry.sdk.trace import sampling
2525
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
26-
from opentelemetry.trace.status import StatusCanonicalCode
2726

2827
# pylint:disable=relative-beyond-top-level
2928
from .constants import (
@@ -145,7 +144,7 @@ def _translate_to_datadog(self, spans):
145144
datadog_span.start_ns = span.start_time
146145
datadog_span.duration_ns = span.end_time - span.start_time
147146

148-
if span.status.canonical_code is not StatusCanonicalCode.OK:
147+
if not span.status.is_ok:
149148
datadog_span.error = 1
150149
if span.status.description:
151150
exc_type, exc_val = _get_exc_info(span)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
from opentelemetry.exporter.jaeger.gen.agent import Agent as agent
7171
from opentelemetry.exporter.jaeger.gen.jaeger import Collector as jaeger
7272
from opentelemetry.sdk.trace.export import Span, SpanExporter, SpanExportResult
73-
from opentelemetry.trace.status import StatusCanonicalCode
73+
from opentelemetry.trace.status import StatusCode
7474

7575
DEFAULT_AGENT_HOST_NAME = "localhost"
7676
DEFAULT_AGENT_PORT = 6831
@@ -224,7 +224,7 @@ def _translate_to_jaeger(spans: Span):
224224

225225
tags.extend(
226226
[
227-
_get_long_tag("status.code", status.canonical_code.value),
227+
_get_long_tag("status.code", status.status_code.value),
228228
_get_string_tag("status.message", status.description),
229229
_get_string_tag("span.kind", span.kind.name),
230230
]
@@ -245,7 +245,7 @@ def _translate_to_jaeger(spans: Span):
245245
)
246246

247247
# Ensure that if Status.Code is not OK, that we set the "error" tag on the Jaeger span.
248-
if status.canonical_code is not StatusCanonicalCode.OK:
248+
if not status.is_ok:
249249
tags.append(_get_bool_tag("error", True))
250250

251251
refs = _extract_refs_from_span(span)

exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from opentelemetry.sdk import trace
2626
from opentelemetry.sdk.trace import Resource
2727
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
28-
from opentelemetry.trace.status import Status, StatusCanonicalCode
28+
from opentelemetry.trace.status import Status, StatusCode
2929

3030

3131
class TestJaegerSpanExporter(unittest.TestCase):
@@ -210,7 +210,7 @@ def test_translate_to_jaeger(self):
210210
jaeger.Tag(
211211
key="status.code",
212212
vType=jaeger.TagType.LONG,
213-
vLong=StatusCanonicalCode.OK.value,
213+
vLong=StatusCode.UNSET.value,
214214
),
215215
jaeger.Tag(
216216
key="status.message", vType=jaeger.TagType.STRING, vStr=None
@@ -249,7 +249,7 @@ def test_translate_to_jaeger(self):
249249
attributes={"key_resource": "some_resource"}
250250
)
251251
otel_spans[0].set_status(
252-
Status(StatusCanonicalCode.UNKNOWN, "Example description")
252+
Status(StatusCode.ERROR, "Example description")
253253
)
254254
otel_spans[0].end(end_time=end_times[0])
255255

@@ -259,6 +259,7 @@ def test_translate_to_jaeger(self):
259259

260260
otel_spans[2].start(start_time=start_times[2])
261261
otel_spans[2].resource = Resource({})
262+
otel_spans[2].set_status(Status(StatusCode.OK, "Example description"))
262263
otel_spans[2].end(end_time=end_times[2])
263264
otel_spans[2].instrumentation_info = InstrumentationInfo(
264265
name="name", version="version"
@@ -304,7 +305,7 @@ def test_translate_to_jaeger(self):
304305
jaeger.Tag(
305306
key="status.code",
306307
vType=jaeger.TagType.LONG,
307-
vLong=StatusCanonicalCode.UNKNOWN.value,
308+
vLong=StatusCode.ERROR.value,
308309
),
309310
jaeger.Tag(
310311
key="status.message",
@@ -380,12 +381,12 @@ def test_translate_to_jaeger(self):
380381
jaeger.Tag(
381382
key="status.code",
382383
vType=jaeger.TagType.LONG,
383-
vLong=StatusCanonicalCode.OK.value,
384+
vLong=StatusCode.OK.value,
384385
),
385386
jaeger.Tag(
386387
key="status.message",
387388
vType=jaeger.TagType.STRING,
388-
vStr=None,
389+
vStr="Example description",
389390
),
390391
jaeger.Tag(
391392
key="span.kind",

exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def translate_to_collector(spans: Sequence[Span]):
9393
status = None
9494
if span.status is not None:
9595
status = trace_pb2.Status(
96-
code=span.status.canonical_code.value,
96+
code=span.status.status_code.value,
9797
message=span.status.description,
9898
)
9999

exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,14 @@ def test_translate_to_collector(self):
148148
otel_spans[0].set_attribute("key_int", 333)
149149
otel_spans[0].set_status(
150150
trace_api.Status(
151-
trace_api.status.StatusCanonicalCode.INTERNAL,
152-
"test description",
151+
trace_api.status.StatusCode.OK, "test description",
153152
)
154153
)
155154
otel_spans[0].end(end_time=end_times[0])
156155
otel_spans[1].start(start_time=start_times[1])
157156
otel_spans[1].set_status(
158157
trace_api.Status(
159-
trace_api.status.StatusCanonicalCode.INTERNAL, {"test", "val"},
158+
trace_api.status.StatusCode.ERROR, {"test", "val"},
160159
)
161160
)
162161
otel_spans[1].end(end_time=end_times[1])
@@ -197,8 +196,7 @@ def test_translate_to_collector(self):
197196
output_spans[2].parent_span_id, b"\x11\x11\x11\x11\x11\x11\x11\x11"
198197
)
199198
self.assertEqual(
200-
output_spans[0].status.code,
201-
trace_api.status.StatusCanonicalCode.INTERNAL.value,
199+
output_spans[0].status.code, trace_api.status.StatusCode.OK.value,
202200
)
203201
self.assertEqual(output_spans[0].status.message, "test description")
204202
self.assertEqual(len(output_spans[0].tracestate.entries), 1)
@@ -270,7 +268,7 @@ def test_translate_to_collector(self):
270268
)
271269
self.assertEqual(
272270
output_spans[1].status.code,
273-
trace_api.status.StatusCanonicalCode.INTERNAL.value,
271+
trace_api.status.StatusCode.ERROR.value,
274272
)
275273
self.assertEqual(
276274
output_spans[2].links.link[0].type,

exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from opentelemetry.proto.trace.v1.trace_pb2 import Status
4242
from opentelemetry.sdk.trace import Span as SDKSpan
4343
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
44+
from opentelemetry.trace.status import StatusCode
4445

4546
logger = logging.getLogger(__name__)
4647

@@ -198,9 +199,12 @@ def _translate_links(self, sdk_span: SDKSpan) -> None:
198199

199200
def _translate_status(self, sdk_span: SDKSpan) -> None:
200201
if sdk_span.status is not None:
202+
# TODO: Update this when the proto definitions are updated to include UNSET and ERROR
203+
proto_status_code = Status.STATUS_CODE_OK
204+
if sdk_span.status.status_code is StatusCode.ERROR:
205+
proto_status_code = Status.STATUS_CODE_UNKNOWN_ERROR
201206
self._collector_span_kwargs["status"] = Status(
202-
code=sdk_span.status.canonical_code.value,
203-
message=sdk_span.status.description,
207+
code=proto_status_code, message=sdk_span.status.description,
204208
)
205209

206210
def _translate_data(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def _translate_to_zipkin(self, spans: Sequence[Span]):
193193

194194
if span.status is not None:
195195
zipkin_span["tags"]["otel.status_code"] = str(
196-
span.status.canonical_code.value
196+
span.status.status_code.value
197197
)
198198
if span.status.description is not None:
199199
zipkin_span["tags"][

0 commit comments

Comments
 (0)