-
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
Conversation
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.
Minor suggestions, otherwise looks good to me 😄
@@ -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 comment
The 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 service_name = None
lower to line 322 perhaps?
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.
makes sense, updated!
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
It look like UNKNOWN_SERVICE_NAME
is only used 1 time in this exporter? Because that's the case you could consider just doing "unknown_service"
like we do in opentelemetry-sdk
:
But not a blocker!
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.
Either that or change both to use UNKNOWN_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.
thanks, updated, i just removed the use of UNKNOWN_SERVICE_NAME
entirely and went with "unknown_service".
CHANGELOG.md
Outdated
@@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
([#560](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/560)) | |||
- `opentelemetry-instrumentation-django` Migrated Django middleware to new-style. | |||
([#533](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/533)) | |||
- `opentelemetry-exporter-datadog` Fix service name resolution. |
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?
- `opentelemetry-exporter-datadog` Fix service name resolution. | |
- `opentelemetry-exporter-datadog` Datadog exporter should not use `unknown_service` as fallback resource 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.
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
exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/constants.py
Outdated
Show resolved
Hide resolved
@lzchen yes generally speaking I think that's a good direction to take, as I'd like to nudge folks to use the opentelemetry semantic conventions when using opentelemetry libraries. If that means removing the My only blocker is that I would have to coordinate with an update to the docs/blog posts/etc on my employers doc website so that any onboarding users were using the correct code snippets. So, if possible, i would prefer if we could just ship this non-breaking change (all the feedback seems reasonable, will update), and then I can try to get everything in order to update the exporter to be in line with other non-otlp exporters. If you'd like to make an issue for that work and assign it to me so that we can make sure this is tracked/completed, that's good with me. Is that approach ok for y'all? |
@ericmustin |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Technically tags
could just be {}
here since it's not really use here at this point too! But that's not in scope for your PR I would say :-)
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.
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
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.
Could you add a test for this?
@lzchen sorry for delay was on pto, added a test lmk if anything else needed here |
Description
This PR fixes the
service_name
resolution for the datadog exporter. The order of operations here is:service.name
service
However, in practice due to the work done in this PR: open-telemetry/opentelemetry-python#1480
The resource attribute resolution will provide a default resource service.name of "unknown_service" in the event no resource attribute has been set for
service.name
. This means that even when a user does supply a fallback datadogservice
it will never be discovered beacuse the default"unknown_service"
will take precedence. This PR updates the datadog exporter to explicitly check if a defaultunknown_service
is being used for resource attributeservice.name
and if it does, allows the datadog suppliedservice
to override it.Fixes # (issue)
Internall bug reports impacting end users
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.