Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…try-python into exp
  • Loading branch information
lzchen committed Nov 12, 2020
2 parents 604c054 + 26bf23f commit b8d7528
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,22 @@
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 import SpanKind
from opentelemetry.trace.status import StatusCode

DEFAULT_AGENT_HOST_NAME = "localhost"
DEFAULT_AGENT_PORT = 6831

UDP_PACKET_MAX_LENGTH = 65000

OTLP_JAEGER_SPAN_KIND = {
SpanKind.CLIENT: "client",
SpanKind.SERVER: "server",
SpanKind.CONSUMER: "consumer",
SpanKind.PRODUCER: "producer",
SpanKind.INTERNAL: "internal",
}

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -226,7 +235,7 @@ def _translate_to_jaeger(spans: Span):
[
_get_long_tag("status.code", status.status_code.value),
_get_string_tag("status.message", status.description),
_get_string_tag("span.kind", span.kind.name),
_get_string_tag("span.kind", OTLP_JAEGER_SPAN_KIND[span.kind]),
]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from opentelemetry.sdk import trace
from opentelemetry.sdk.trace import Resource
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.trace import SpanKind
from opentelemetry.trace.status import Status, StatusCode


Expand Down Expand Up @@ -151,6 +152,10 @@ def test_nsec_to_usec_round(self):
self.assertEqual(nsec_to_usec_round(5499), 5)
self.assertEqual(nsec_to_usec_round(5500), 6)

def test_all_otlp_span_kinds_are_mapped(self):
for kind in SpanKind:
self.assertIn(kind, jaeger_exporter.OTLP_JAEGER_SPAN_KIND)

# pylint: disable=too-many-locals
def test_translate_to_jaeger(self):
# pylint: disable=invalid-name
Expand Down Expand Up @@ -216,9 +221,7 @@ def test_translate_to_jaeger(self):
key="status.message", vType=jaeger.TagType.STRING, vStr=None
),
jaeger.Tag(
key="span.kind",
vType=jaeger.TagType.STRING,
vStr=trace_api.SpanKind.INTERNAL.name,
key="span.kind", vType=jaeger.TagType.STRING, vStr="internal",
),
]

Expand Down Expand Up @@ -315,7 +318,7 @@ def test_translate_to_jaeger(self):
jaeger.Tag(
key="span.kind",
vType=jaeger.TagType.STRING,
vStr=trace_api.SpanKind.CLIENT.name,
vStr="client",
),
jaeger.Tag(
key="error", vType=jaeger.TagType.BOOL, vBool=True
Expand Down Expand Up @@ -391,7 +394,7 @@ def test_translate_to_jaeger(self):
jaeger.Tag(
key="span.kind",
vType=jaeger.TagType.STRING,
vStr=trace_api.SpanKind.INTERNAL.name,
vStr="internal",
),
jaeger.Tag(
key="otel.instrumentation_library.name",
Expand Down
4 changes: 2 additions & 2 deletions tests/util/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ package_dir=
=src
packages=find_namespace:
install_requires =
opentelemetry-api
opentelemetry-sdk
opentelemetry-api == 0.16.dev0
opentelemetry-sdk == 0.16.dev0

[options.extras_require]
test = flask~=1.0
Expand Down

0 comments on commit b8d7528

Please sign in to comment.