Skip to content

Commit

Permalink
remove canonical, change defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen committed Oct 26, 2020
1 parent 82356a8 commit cf13537
Show file tree
Hide file tree
Showing 44 changed files with 203 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import opentelemetry.trace as trace_api
from opentelemetry.sdk.trace import sampling
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
from opentelemetry.trace.status import StatusCanonicalCode
from opentelemetry.trace.status import StatusCode

# pylint:disable=relative-beyond-top-level
from .constants import (
Expand Down Expand Up @@ -145,7 +145,7 @@ def _translate_to_datadog(self, spans):
datadog_span.start_ns = span.start_time
datadog_span.duration_ns = span.end_time - span.start_time

if span.status.canonical_code is not StatusCanonicalCode.OK:
if span.status.canonical_code is not StatusCode.OK:
datadog_span.error = 1
if span.status.description:
exc_type, exc_val = _get_exc_info(span)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
from opentelemetry.exporter.jaeger.gen.agent import Agent as agent
from opentelemetry.exporter.jaeger.gen.jaeger import Collector as jaeger
from opentelemetry.sdk.trace.export import Span, SpanExporter, SpanExportResult
from opentelemetry.trace.status import StatusCanonicalCode
from opentelemetry.trace.status import StatusCode

DEFAULT_AGENT_HOST_NAME = "localhost"
DEFAULT_AGENT_PORT = 6831
Expand Down Expand Up @@ -245,7 +245,7 @@ def _translate_to_jaeger(spans: Span):
)

# Ensure that if Status.Code is not OK, that we set the "error" tag on the Jaeger span.
if status.canonical_code is not StatusCanonicalCode.OK:
if status.canonical_code is not StatusCode.OK:
tags.append(_get_bool_tag("error", True))

refs = _extract_refs_from_span(span)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from opentelemetry.sdk import trace
from opentelemetry.sdk.trace import Resource
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.trace.status import Status, StatusCanonicalCode
from opentelemetry.trace.status import Status, StatusCode


class TestJaegerSpanExporter(unittest.TestCase):
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_translate_to_jaeger(self):
jaeger.Tag(
key="status.code",
vType=jaeger.TagType.LONG,
vLong=StatusCanonicalCode.OK.value,
vLong=StatusCode.OK.value,
),
jaeger.Tag(
key="status.message", vType=jaeger.TagType.STRING, vStr=None
Expand Down Expand Up @@ -249,7 +249,7 @@ def test_translate_to_jaeger(self):
attributes={"key_resource": "some_resource"}
)
otel_spans[0].set_status(
Status(StatusCanonicalCode.UNKNOWN, "Example description")
Status(StatusCode.ERROR, "Example description")
)
otel_spans[0].end(end_time=end_times[0])

Expand Down Expand Up @@ -304,7 +304,7 @@ def test_translate_to_jaeger(self):
jaeger.Tag(
key="status.code",
vType=jaeger.TagType.LONG,
vLong=StatusCanonicalCode.UNKNOWN.value,
vLong=StatusCode.ERROR.value,
),
jaeger.Tag(
key="status.message",
Expand Down Expand Up @@ -380,7 +380,7 @@ def test_translate_to_jaeger(self):
jaeger.Tag(
key="status.code",
vType=jaeger.TagType.LONG,
vLong=StatusCanonicalCode.OK.value,
vLong=StatusCode.OK.value,
),
jaeger.Tag(
key="status.message",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ def test_translate_to_collector(self):
otel_spans[0].set_attribute("key_int", 333)
otel_spans[0].set_status(
trace_api.Status(
trace_api.status.StatusCanonicalCode.INTERNAL,
trace_api.status.StatusCode.INTERNAL,
"test description",
)
)
otel_spans[0].end(end_time=end_times[0])
otel_spans[1].start(start_time=start_times[1])
otel_spans[1].set_status(
trace_api.Status(
trace_api.status.StatusCanonicalCode.INTERNAL, {"test", "val"},
trace_api.status.StatusCode.INTERNAL, {"test", "val"},
)
)
otel_spans[1].end(end_time=end_times[1])
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_translate_to_collector(self):
)
self.assertEqual(
output_spans[0].status.code,
trace_api.status.StatusCanonicalCode.INTERNAL.value,
trace_api.status.StatusCode.INTERNAL.value,
)
self.assertEqual(output_spans[0].status.message, "test description")
self.assertEqual(len(output_spans[0].tracestate.entries), 1)
Expand Down Expand Up @@ -270,7 +270,7 @@ def test_translate_to_collector(self):
)
self.assertEqual(
output_spans[1].status.code,
trace_api.status.StatusCanonicalCode.INTERNAL.value,
trace_api.status.StatusCode.INTERNAL.value,
)
self.assertEqual(
output_spans[2].links.link[0].type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from opentelemetry.proto.trace.v1.trace_pb2 import Status
from opentelemetry.sdk.trace import Span as SDKSpan
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
from opentelemetry.trace.status import StatusCode

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -159,8 +160,12 @@ def _translate_links(self, sdk_span: SDKSpan) -> None:

def _translate_status(self, sdk_span: SDKSpan) -> None:
if sdk_span.status is not None:
# TODO: Update this when the proto definitions are updated to include UNSET and ERROR
proto_status_code = Status.STATUS_CODE_OK
if sdk_span.status.canonical_code is StatusCode.ERROR:
proto_status_code = Status.STATUS_CODE_UNKNOWN_ERROR
self._collector_span_kwargs["status"] = Status(
code=sdk_span.status.canonical_code.value,
code=proto_status_code.value,
message=sdk_span.status.description,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +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
from opentelemetry.trace.status import Status, StatusCode


class MockResponse:
Expand Down Expand Up @@ -179,7 +179,7 @@ def test_export(self):
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")
Status(StatusCode.ERROR, "Example description")
)
otel_spans[0].end(end_time=end_times[0])

Expand Down Expand Up @@ -401,7 +401,7 @@ def test_max_tag_length(self):
span.set_attribute("k1", "v" * 500)
span.set_attribute("k2", "v" * 50)
span.set_status(
Status(StatusCanonicalCode.UNKNOWN, "Example description")
Status(StatusCode.ERROR, "Example description")
)
span.end()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def strip_query_params(url: yarl.URL) -> str:
unwrap,
)
from opentelemetry.trace import SpanKind, TracerProvider, get_tracer
from opentelemetry.trace.status import Status, StatusCanonicalCode
from opentelemetry.trace.status import Status, StatusCode

_UrlFilterT = typing.Optional[typing.Callable[[str], str]]
_SpanNameT = typing.Optional[
Expand Down Expand Up @@ -219,15 +219,15 @@ async def on_request_exception(
params.exception,
(aiohttp.ServerTimeoutError, aiohttp.TooManyRedirects),
):
status = StatusCanonicalCode.DEADLINE_EXCEEDED
status = StatusCode.ERROR
# Assume any getaddrinfo error is a DNS failure.
elif isinstance(
params.exception, aiohttp.ClientConnectorError
) and isinstance(params.exception.os_error, socket.gaierror):
# DNS resolution failed
status = StatusCanonicalCode.UNKNOWN
status = StatusCode.ERROR
else:
status = StatusCanonicalCode.UNAVAILABLE
status = StatusCode.ERROR

trace_config_ctx.span.set_status(Status(status))
trace_config_ctx.span.record_exception(params.exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
AioHttpClientInstrumentor,
)
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace.status import StatusCanonicalCode
from opentelemetry.trace.status import StatusCode


def run_with_test_server(
Expand Down Expand Up @@ -111,12 +111,12 @@ async def client_request(server: aiohttp.test_utils.TestServer):

def test_status_codes(self):
for status_code, span_status in (
(HTTPStatus.OK, StatusCanonicalCode.OK),
(HTTPStatus.TEMPORARY_REDIRECT, StatusCanonicalCode.OK),
(HTTPStatus.SERVICE_UNAVAILABLE, StatusCanonicalCode.UNAVAILABLE),
(HTTPStatus.OK, StatusCode.OK),
(HTTPStatus.TEMPORARY_REDIRECT, StatusCode.OK),
(HTTPStatus.SERVICE_UNAVAILABLE, StatusCode.UNAVAILABLE),
(
HTTPStatus.GATEWAY_TIMEOUT,
StatusCanonicalCode.DEADLINE_EXCEEDED,
StatusCode.DEADLINE_EXCEEDED,
),
):
with self.subTest(status_code=status_code):
Expand Down Expand Up @@ -188,7 +188,7 @@ def test_span_name_option(self):
[
(
expected,
(StatusCanonicalCode.OK, None),
(StatusCode.OK, None),
{
"component": "http",
"http.method": method,
Expand Down Expand Up @@ -220,7 +220,7 @@ def strip_query_params(url: yarl.URL) -> str:
[
(
"HTTP GET",
(StatusCanonicalCode.OK, None),
(StatusCode.OK, None),
{
"component": "http",
"http.method": "GET",
Expand All @@ -238,8 +238,8 @@ def test_connection_errors(self):
trace_configs = [aiohttp_client.create_trace_config()]

for url, expected_status in (
("http://this-is-unknown.local/", StatusCanonicalCode.UNKNOWN),
("http://127.0.0.1:1/", StatusCanonicalCode.UNAVAILABLE),
("http://this-is-unknown.local/", StatusCode.ERROR),
("http://127.0.0.1:1/", StatusCode.UNAVAILABLE),
):
with self.subTest(expected_status=expected_status):

Expand Down Expand Up @@ -286,7 +286,7 @@ async def request_handler(request):
[
(
"HTTP GET",
(StatusCanonicalCode.DEADLINE_EXCEEDED, None),
(StatusCode.DEADLINE_EXCEEDED, None),
{
"component": "http",
"http.method": "GET",
Expand Down Expand Up @@ -316,7 +316,7 @@ async def request_handler(request):
[
(
"HTTP GET",
(StatusCanonicalCode.DEADLINE_EXCEEDED, None),
(StatusCode.DEADLINE_EXCEEDED, None),
{
"component": "http",
"http.method": "GET",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
TracedCursor,
)
from opentelemetry.trace import SpanKind
from opentelemetry.trace.status import Status, StatusCanonicalCode
from opentelemetry.trace.status import Status, StatusCode


# pylint: disable=abstract-method
Expand Down Expand Up @@ -109,12 +109,12 @@ async def traced_execution(
try:
result = await query_method(*args, **kwargs)
if span.is_recording():
span.set_status(Status(StatusCanonicalCode.OK))
span.set_status(Status(StatusCode.OK))
return result
except Exception as ex: # pylint: disable=broad-except
if span.is_recording():
span.set_status(
Status(StatusCanonicalCode.UNKNOWN, str(ex))
Status(StatusCode.UNKNOWN, str(ex))
)
raise ex

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def test_span_succeeded(self):
self.assertEqual(span.attributes["net.peer.port"], 123)
self.assertIs(
span.status.canonical_code,
trace_api.status.StatusCanonicalCode.OK,
trace_api.status.StatusCode.OK,
)

def test_span_not_recording(self):
Expand Down Expand Up @@ -279,7 +279,7 @@ def test_span_failed(self):
self.assertEqual(span.attributes["db.statement"], "Test query")
self.assertIs(
span.status.canonical_code,
trace_api.status.StatusCanonicalCode.UNKNOWN,
trace_api.status.StatusCode.UNKNOWN,
)
self.assertEqual(span.status.description, "Test Exception")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from opentelemetry import context, propagators, trace
from opentelemetry.instrumentation.asgi.version import __version__ # noqa
from opentelemetry.instrumentation.utils import http_status_to_canonical_code
from opentelemetry.trace.status import Status, StatusCanonicalCode
from opentelemetry.trace.status import Status, StatusCode


def get_header_from_scope(scope: dict, header_name: str) -> typing.List[str]:
Expand Down Expand Up @@ -98,7 +98,7 @@ def set_status_code(span, status_code):
except ValueError:
span.set_status(
Status(
StatusCanonicalCode.UNKNOWN,
StatusCode.UNKNOWN,
"Non-integer HTTP status: " + repr(status_code),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.utils import unwrap
from opentelemetry.trace import SpanKind
from opentelemetry.trace.status import Status, StatusCanonicalCode
from opentelemetry.trace.status import Status, StatusCode

_APPLIED = "_opentelemetry_tracer"


def _exception_to_canonical_code(exc: Exception) -> StatusCanonicalCode:
def _exception_to_canonical_code(exc: Exception) -> StatusCode:
if isinstance(
exc, (exceptions.InterfaceError, exceptions.SyntaxOrAccessError),
):
return StatusCanonicalCode.INVALID_ARGUMENT
return StatusCode.INVALID_ARGUMENT
if isinstance(exc, exceptions.IdleInTransactionSessionTimeoutError):
return StatusCanonicalCode.DEADLINE_EXCEEDED
return StatusCanonicalCode.UNKNOWN
return StatusCode.DEADLINE_EXCEEDED
return StatusCode.UNKNOWN


def _hydrate_span_from_args(connection, query, parameters) -> dict:
Expand Down Expand Up @@ -140,6 +140,6 @@ async def _do_execute(self, func, instance, args, kwargs):
Status(_exception_to_canonical_code(exception))
)
else:
span.set_status(Status(StatusCanonicalCode.OK))
span.set_status(Status(StatusCode.OK))

return result
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def add(x, y):
from opentelemetry.instrumentation.celery.version import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.trace.propagation import get_current_span
from opentelemetry.trace.status import Status, StatusCanonicalCode
from opentelemetry.trace.status import Status, StatusCode

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -214,7 +214,7 @@ def _trace_failure(*args, **kwargs):
if span is None or not span.is_recording():
return

status_kwargs = {"canonical_code": StatusCanonicalCode.UNKNOWN}
status_kwargs = {"canonical_code": StatusCode.UNKNOWN}

ex = kwargs.get("einfo")

Expand Down
Loading

0 comments on commit cf13537

Please sign in to comment.