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

Diff for: docs/examples/auto-instrumentation/README.rst

+2-2
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",

Diff for: docs/examples/django/README.rst

+1-1
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",

Diff for: docs/getting-started.rst

+3-3
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": [],

Diff for: exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py

+1-2
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)

Diff for: exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py

+3-3
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)

Diff for: exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter.py

+7-6
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",

Diff for: exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py

+1-1
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

Diff for: exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py

+4-6
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,

Diff for: exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py

+6-2
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(

Diff for: exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py

+1-1
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"][

Diff for: exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from opentelemetry.sdk.trace.export import SpanExportResult
2525
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
2626
from opentelemetry.trace import TraceFlags
27-
from opentelemetry.trace.status import Status, StatusCanonicalCode
27+
from opentelemetry.trace.status import Status, StatusCode
2828

2929

3030
class MockResponse:
@@ -179,7 +179,7 @@ def test_export(self):
179179
otel_spans[0].set_attribute("key_string", "hello_world")
180180
otel_spans[0].set_attribute("key_float", 111.22)
181181
otel_spans[0].set_status(
182-
Status(StatusCanonicalCode.UNKNOWN, "Example description")
182+
Status(StatusCode.ERROR, "Example description")
183183
)
184184
otel_spans[0].end(end_time=end_times[0])
185185

@@ -248,7 +248,7 @@ def test_export(self):
248248
"kind": None,
249249
"tags": {
250250
"key_resource": "some_resource",
251-
"otel.status_code": "0",
251+
"otel.status_code": "1",
252252
},
253253
"annotations": None,
254254
},
@@ -263,7 +263,7 @@ def test_export(self):
263263
"tags": {
264264
"key_string": "hello_world",
265265
"key_resource": "some_resource",
266-
"otel.status_code": "0",
266+
"otel.status_code": "1",
267267
},
268268
"annotations": None,
269269
},
@@ -278,7 +278,7 @@ def test_export(self):
278278
"tags": {
279279
"otel.instrumentation_library.name": "name",
280280
"otel.instrumentation_library.version": "version",
281-
"otel.status_code": "0",
281+
"otel.status_code": "1",
282282
},
283283
"annotations": None,
284284
},
@@ -356,7 +356,7 @@ def test_zero_padding(self):
356356
"duration": duration // 10 ** 3,
357357
"localEndpoint": local_endpoint,
358358
"kind": None,
359-
"tags": {"otel.status_code": "0"},
359+
"tags": {"otel.status_code": "1"},
360360
"annotations": None,
361361
"debug": True,
362362
"parentId": "0aaaaaaaaaaaaaaa",
@@ -400,9 +400,7 @@ def test_max_tag_length(self):
400400
# added here to preserve order
401401
span.set_attribute("k1", "v" * 500)
402402
span.set_attribute("k2", "v" * 50)
403-
span.set_status(
404-
Status(StatusCanonicalCode.UNKNOWN, "Example description")
405-
)
403+
span.set_status(Status(StatusCode.ERROR, "Example description"))
406404
span.end()
407405

408406
exporter = ZipkinSpanExporter(service_name)

Diff for: instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py

+5-21
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ def strip_query_params(url: yarl.URL) -> str:
7474
from opentelemetry.instrumentation.aiohttp_client.version import __version__
7575
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
7676
from opentelemetry.instrumentation.utils import (
77-
http_status_to_canonical_code,
77+
http_status_to_status_code,
7878
unwrap,
7979
)
8080
from opentelemetry.trace import SpanKind, TracerProvider, get_tracer
81-
from opentelemetry.trace.status import Status, StatusCanonicalCode
81+
from opentelemetry.trace.status import Status, StatusCode
8282

8383
_UrlFilterT = typing.Optional[typing.Callable[[str], str]]
8484
_SpanNameT = typing.Optional[
@@ -194,9 +194,7 @@ async def on_request_end(
194194

195195
if trace_config_ctx.span.is_recording():
196196
trace_config_ctx.span.set_status(
197-
Status(
198-
http_status_to_canonical_code(int(params.response.status))
199-
)
197+
Status(http_status_to_status_code(int(params.response.status)))
200198
)
201199
trace_config_ctx.span.set_attribute(
202200
"http.status_code", params.response.status
@@ -214,22 +212,8 @@ async def on_request_exception(
214212
if trace_config_ctx.span is None:
215213
return
216214

217-
if trace_config_ctx.span.is_recording():
218-
if isinstance(
219-
params.exception,
220-
(aiohttp.ServerTimeoutError, aiohttp.TooManyRedirects),
221-
):
222-
status = StatusCanonicalCode.DEADLINE_EXCEEDED
223-
# Assume any getaddrinfo error is a DNS failure.
224-
elif isinstance(
225-
params.exception, aiohttp.ClientConnectorError
226-
) and isinstance(params.exception.os_error, socket.gaierror):
227-
# DNS resolution failed
228-
status = StatusCanonicalCode.UNKNOWN
229-
else:
230-
status = StatusCanonicalCode.UNAVAILABLE
231-
232-
trace_config_ctx.span.set_status(Status(status))
215+
if trace_config_ctx.span.is_recording() and params.exception:
216+
trace_config_ctx.span.set_status(Status(StatusCode.ERROR))
233217
trace_config_ctx.span.record_exception(params.exception)
234218
_end_trace(trace_config_ctx)
235219

0 commit comments

Comments
 (0)