Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose StatusCode from opentelemetry.trace #1681

Merged
merged 2 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1663](https://github.com/open-telemetry/opentelemetry-python/pull/1663))
- Rename `JaegerSpanExporter` to `JaegerExporter` and rename `ZipkinSpanExporter` to `ZipkinExporter`
([#1664](https://github.com/open-telemetry/opentelemetry-python/pull/1664))
- Expose `StatusCode` from the `opentelemetry.trace` module
([#](https://github.com/open-telemetry/opentelemetry-python/pull/))

### Removed
- Removed unused `get_hexadecimal_trace_id` and `get_hexadecimal_span_id` methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,12 @@ def test_translate_to_collector(self):
otel_spans[0].set_attribute("key_float", 111.22)
otel_spans[0].set_attribute("key_int", 333)
otel_spans[0].set_status(
trace_api.Status(
trace_api.status.StatusCode.OK, "test description",
)
trace_api.Status(trace_api.StatusCode.OK, "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.StatusCode.ERROR, {"test", "val"},
)
trace_api.Status(trace_api.StatusCode.ERROR, {"test", "val"},)
)
otel_spans[1].end(end_time=end_times[1])
otel_spans[2].start(start_time=start_times[2])
Expand Down Expand Up @@ -196,7 +192,7 @@ def test_translate_to_collector(self):
output_spans[2].parent_span_id, b"\x11\x11\x11\x11\x11\x11\x11\x11"
)
self.assertEqual(
output_spans[0].status.code, trace_api.status.StatusCode.OK.value,
output_spans[0].status.code, trace_api.StatusCode.OK.value,
)
self.assertEqual(output_spans[0].status.message, "test description")
self.assertEqual(len(output_spans[0].tracestate.entries), 1)
Expand Down Expand Up @@ -267,8 +263,7 @@ def test_translate_to_collector(self):
trace_pb2.Span.Link.Type.TYPE_UNSPECIFIED,
)
self.assertEqual(
output_spans[1].status.code,
trace_api.status.StatusCode.ERROR.value,
output_spans[1].status.code, trace_api.StatusCode.ERROR.value,
)
self.assertEqual(
output_spans[2].links.link[0].type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
)
from opentelemetry.sdk.trace import Span as ReadableSpan
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
from opentelemetry.trace.status import StatusCode
from opentelemetry.trace import StatusCode

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
from opentelemetry.trace import (
Span,
SpanContext,
StatusCode,
format_span_id,
format_trace_id,
)
from opentelemetry.trace.status import StatusCode

EncodedLocalEndpointT = TypeVar("EncodedLocalEndpointT")

Expand Down
1 change: 1 addition & 0 deletions opentelemetry-api/src/opentelemetry/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,5 @@ def use_span(
"set_span_in_context",
"use_span",
"Status",
"StatusCode",
]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from wrapt import ObjectProxy

from opentelemetry.trace.status import StatusCode
from opentelemetry.trace import StatusCode


def extract_attributes_from_object(
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-instrumentation/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from opentelemetry.instrumentation.utils import http_status_to_status_code
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace.status import StatusCode
from opentelemetry.trace import StatusCode


class TestUtils(TestBase):
Expand Down
18 changes: 6 additions & 12 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from opentelemetry.sdk.trace.id_generator import RandomIdGenerator
from opentelemetry.sdk.util import ns_to_iso_str
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.trace.status import StatusCode
from opentelemetry.trace import StatusCode
from opentelemetry.util.time import time_ns


Expand Down Expand Up @@ -835,18 +835,14 @@ def test_start_span(self):
self.assertEqual(start_time, span.start_time)

self.assertIsNotNone(span.status)
self.assertIs(
span.status.status_code, trace_api.status.StatusCode.UNSET
)
self.assertIs(span.status.status_code, trace_api.StatusCode.UNSET)

# status
new_status = trace_api.status.Status(
trace_api.status.StatusCode.ERROR, "Test description"
trace_api.StatusCode.ERROR, "Test description"
)
span.set_status(new_status)
self.assertIs(
span.status.status_code, trace_api.status.StatusCode.ERROR
)
self.assertIs(span.status.status_code, trace_api.StatusCode.ERROR)
self.assertIs(span.status.description, "Test description")

def test_start_accepts_context(self):
Expand Down Expand Up @@ -906,14 +902,12 @@ def test_ended_span(self):
self.assertEqual(root.name, "root")

new_status = trace_api.status.Status(
trace_api.status.StatusCode.ERROR, "Test description"
trace_api.StatusCode.ERROR, "Test description"
)

with self.assertLogs(level=WARNING):
root.set_status(new_status)
self.assertEqual(
root.status.status_code, trace_api.status.StatusCode.UNSET
)
self.assertEqual(root.status.status_code, trace_api.StatusCode.UNSET)

def test_error_status(self):
def error_status_test(context):
Expand Down