-
Notifications
You must be signed in to change notification settings - Fork 599
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
[exporter/datadog]: fix service name resolution #570
Changes from 7 commits
a61c752
f094c60
12ef531
e45662e
2156de4
e341d67
2829dd7
0da9fe0
1cc8fbd
ad5aecd
9a96ef3
74d7cd3
995e59d
b41cb25
9d99049
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
EXCEPTION_TYPE_ATTR_KEY, | ||
SAMPLE_RATE_METRIC_KEY, | ||
SERVICE_NAME_TAG, | ||
UNKNOWN_SERVICE_NAME, | ||
VERSION_KEY, | ||
) | ||
from opentelemetry.sdk.trace import sampling | ||
|
@@ -135,12 +136,12 @@ def _translate_to_datadog(self, spans): | |
[ | ||
resource_tags, | ||
resource_service_name, | ||
] = _extract_tags_from_resource(span.resource) | ||
] = _extract_tags_from_resource(span.resource, self.service) | ||
|
||
datadog_span = DatadogSpan( | ||
tracer, | ||
_get_span_name(span), | ||
service=resource_service_name or self.service, | ||
service=resource_service_name, | ||
resource=_get_resource(span), | ||
span_type=_get_span_type(span), | ||
trace_id=trace_id, | ||
|
@@ -312,19 +313,23 @@ def _parse_tags_str(tags_str): | |
return parsed_tags | ||
|
||
|
||
def _extract_tags_from_resource(resource): | ||
def _extract_tags_from_resource(resource, fallback_service_name): | ||
"""Parse tags from resource.attributes, except service.name which | ||
has special significance within datadog""" | ||
tags = {} | ||
service_name = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it's not used below on line 321 anymore, I think it would make sense to push the initialization of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense, updated! |
||
if not (resource and getattr(resource, "attributes", None)): | ||
return [tags, service_name] | ||
return [tags, fallback_service_name] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch. As you can tell my code is not particularly pythonic (i'm mostly ruby these days 😅 ). But there's a lot in this little exporter that could get cleaned up. I'll make a note to also try to give this code another pass for #574 |
||
|
||
for attribute_key, attribute_value in resource.attributes.items(): | ||
if attribute_key == SERVICE_NAME_TAG: | ||
service_name = attribute_value | ||
else: | ||
tags[attribute_key] = attribute_value | ||
|
||
if service_name is None or service_name == UNKNOWN_SERVICE_NAME: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It look like But not a blocker! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either that or change both to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, updated, i just removed the use of |
||
service_name = fallback_service_name | ||
|
||
return [tags, service_name] | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this describes the change more explicitly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, updated