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

ext/jaeger - Transform resource to tags when exporting #645

Merged
merged 9 commits into from
May 19, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ def _translate_to_jaeger(spans: Span):
parent_id = span.parent.span_id if span.parent else 0

tags = _extract_tags(span.attributes)
if span.resource is not None:

Choose a reason for hiding this comment

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

I'm wondering how we can make this test more efficient. It looks to me that resource is never None but it is _EMPTY_RESOURCE.

resource: Resource = Resource.create_empty(),

def create_empty() -> "Resource":
return _EMPTY_RESOURCE

I think one solution could be to expose _EMPTY_RESOURCE (remove the _) and make a comparison using the is operator.

if span.resource is not ̣̣̣resources.EMPTY_RESOURCE:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the suggested change.
Though notice, I had to create an empty resource in all of the spans used for the jaeger tests, as it is not created by default when accessing the trace.Span directly.

I guess that in the real flow it will always be created, but maybe it's something to consider and we should keep the is not None check nonetheless, just to play it safe.
What do you think?

Choose a reason for hiding this comment

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

Good point. TBH I'm not 100% what's the best approach here, I made that suggestion to make it more efficient, but probably it's not worthy as this check is very fast in both cases and we haven't done an optimization in other places yet. I'm fine with both solutions, let's see other people's opinions on this.

tags.extend(_extract_tags(span.resource.labels))

tags.extend(
[
Expand Down
7 changes: 7 additions & 0 deletions ext/opentelemetry-ext-jaeger/tests/test_jaeger_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from opentelemetry import trace as trace_api
from opentelemetry.ext.jaeger.gen.jaeger import ttypes as jaeger
from opentelemetry.sdk import trace
from opentelemetry.sdk.trace import Resource
from opentelemetry.trace.status import Status, StatusCanonicalCode


Expand Down Expand Up @@ -199,6 +200,7 @@ def test_translate_to_jaeger(self):
otel_spans[0].set_attribute("key_bool", False)
otel_spans[0].set_attribute("key_string", "hello_world")
otel_spans[0].set_attribute("key_float", 111.22)
otel_spans[0].resource = Resource(labels={ "key_resource": "some_resource" })
otel_spans[0].set_status(
Status(StatusCanonicalCode.UNKNOWN, "Example description")
)
Expand Down Expand Up @@ -237,6 +239,11 @@ def test_translate_to_jaeger(self):
vType=jaeger.TagType.DOUBLE,
vDouble=111.22,
),
jaeger.Tag(
key="key_resource",
vType=jaeger.TagType.STRING,
vStr="some_resource"
),
jaeger.Tag(
key="status.code",
vType=jaeger.TagType.LONG,
Expand Down