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

Add support for OTLP v0.6.0 #1472

Merged
merged 16 commits into from
Jan 5, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v0.16b1...HEAD)

- Add support for OTLP v0.6.0
([#1472](https://github.com/open-telemetry/opentelemetry-python/pull/1472))

- Add protobuf via gRPC exporting support for Jaeger
([#1471](https://github.com/open-telemetry/opentelemetry-python/pull/1471))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,15 @@ def _translate_links(self, sdk_span: SDKSpan) -> None:
)

def _translate_status(self, sdk_span: SDKSpan) -> None:
# pylint: disable=no-member
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.status_code is StatusCode.ERROR:
proto_status_code = Status.STATUS_CODE_UNKNOWN_ERROR
deprecated_code = Status.DEPRECATED_STATUS_CODE_OK
if sdk_span.status.status_code == StatusCode.ERROR:
deprecated_code = Status.DEPRECATED_STATUS_CODE_UNKNOWN_ERROR
self._collector_span_kwargs["status"] = Status(
code=proto_status_code, message=sdk_span.status.description,
deprecated_code=deprecated_code,
code=sdk_span.status.status_code.value,
message=sdk_span.status.description,
)

def _translate_data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
from opentelemetry.proto.trace.v1.trace_pb2 import Span as OTLPSpan
from opentelemetry.proto.trace.v1.trace_pb2 import Status
from opentelemetry.sdk.resources import Resource as SDKResource
from opentelemetry.sdk.trace import Status as SDKStatus
from opentelemetry.sdk.trace import StatusCode as SDKStatusCode
from opentelemetry.sdk.trace import TracerProvider, _Span
from opentelemetry.sdk.trace.export import (
SimpleExportSpanProcessor,
Expand Down Expand Up @@ -343,3 +345,72 @@ def test_translate_spans(self):

# pylint: disable=protected-access
self.assertEqual(expected, self.exporter._translate_data([self.span]))

def _check_translated_status(
self,
translated: ExportTraceServiceRequest,
code_expected: Status,
deprecated_code_expected: Status,
):
status = (
translated.resource_spans[0]
.instrumentation_library_spans[0]
.spans[0]
.status
)

self.assertEqual(
status.code, code_expected,
)
self.assertEqual(
status.deprecated_code, deprecated_code_expected,
)

def test_span_status_translate(self):
# pylint: disable=protected-access,no-member
unset = SDKStatus(status_code=SDKStatusCode.UNSET)
ok = SDKStatus(status_code=SDKStatusCode.OK)
error = SDKStatus(status_code=SDKStatusCode.ERROR)
unset_translated = self.exporter._translate_data(
[_create_span_with_status(unset)]
)
ok_translated = self.exporter._translate_data(
[_create_span_with_status(ok)]
)
error_translated = self.exporter._translate_data(
[_create_span_with_status(error)]
)
self._check_translated_status(
unset_translated,
Status.STATUS_CODE_UNSET,
Status.DEPRECATED_STATUS_CODE_OK,
)
self._check_translated_status(
ok_translated,
Status.STATUS_CODE_OK,
Status.DEPRECATED_STATUS_CODE_OK,
)
self._check_translated_status(
error_translated,
Status.STATUS_CODE_ERROR,
Status.DEPRECATED_STATUS_CODE_UNKNOWN_ERROR,
)


def _create_span_with_status(status: SDKStatus):
span = _Span(
"a",
context=Mock(
**{
"trace_state": OrderedDict([("a", "b"), ("c", "d")]),
"span_id": 10217189687419569865,
"trace_id": 67545097771067222548457157018666467027,
}
),
parent=Mock(**{"span_id": 12345}),
instrumentation_info=InstrumentationInfo(
name="name", version="version"
),
)
span.set_status(status)
return span
8 changes: 4 additions & 4 deletions opentelemetry-api/src/opentelemetry/trace/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
class StatusCode(enum.Enum):
"""Represents the canonical set of status codes of a finished Span."""

OK = 0
"""The operation has been validated by an Application developer or Operator to have completed successfully."""

UNSET = 1
UNSET = 0
"""The default status."""

OK = 1
"""The operation has been validated by an Application developer or Operator to have completed successfully."""

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enum order as followed in OTLP v0.6.0 and Spec.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought this would've broke some tests in contrib that compared the enum numerical value, but I guess not!

ERROR = 2
"""The operation contains an error."""

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading