Skip to content

exporter/datadog: add support for resource labels and service.name #1074

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

Merged

Conversation

ericmustin
Copy link
Contributor

Description

This PR adds support within the Datadog Exporter for capturing resource labels as datadog span tags as well as to set the service name using the more OpenTelemetry standard Resource service.name. This aligns the exporter with the more broadly accepted OpenTelemetry standards and allows existing users of OpenTelemetry to leverage their existing patterns for service and span tagging if they choose to export to Datadog.

cc @majorgreys for review and any comments here, if there's improvements or something I've missed please let me know.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

I've updated the Unit Tests as well as the Example

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@ericmustin ericmustin requested a review from a team September 3, 2020 23:40
Copy link
Contributor

@ocelotl ocelotl left a comment

Choose a reason for hiding this comment

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

LGTM, minor comments

Comment on lines 313 to 320
if isinstance(attribute_value, (int, bool, float)):
value = str(attribute_value)
elif isinstance(attribute_value, str):
value = attribute_value
else:
logger.warning("Could not serialize tag %s", attribute_key)
continue

Copy link
Contributor

Choose a reason for hiding this comment

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

This could be more simply handled by attempting to cast to string inside a try/except block and log the exception if casting fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, i had ripped it from the zipkin approach but agreed those improvements make sense to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

turns out datadog's add span method handles this casting under the hood, so removing this section entirely for perf

@ericmustin
Copy link
Contributor Author

just waiting on some internal review here, apols on the delay

has special significance within datadog"""
tags = {}
service_name = None
if not resource and resource.labels:
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean if not (resource and resource.labels):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 ah yup ty, updated

Copy link
Contributor

@majorgreys majorgreys left a comment

Choose a reason for hiding this comment

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

This looks right to me. We can simplify the tag extraction and would benefit from having a few more tests around how resource and span attributes interact as well as how we had previously been configuring the exporter. Do we also want to explicitly deprecate passing a service name to the exporter and depend on the resource set in the tracer provider?

return [tags, service_name]

for attribute_key, attribute_value in resource.labels.items():
if isinstance(attribute_value, (int, bool, float)):
Copy link
Contributor

Choose a reason for hiding this comment

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

We can safely remove this logic since the exporter already makes use of ddtrace.span.Span.set_tag for handling span.attributes, which does the necessary casting based on the value or special conditions on keys:

https://github.com/DataDog/dd-trace-py/blob/master/ddtrace/span.py#L180-L259

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, updated

resource = Resource(
labels={
"key_resource": "some_resource",
"service.name": "resource_service_name",
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to add a test for when span.attributes also has values for the same keys. Given the ordering above, span.attributes should override the resource labels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, added

@@ -245,8 +255,13 @@ def test_translate_to_datadog(self):
start=start_times[2],
duration=durations[2],
error=0,
service="test-service",
meta={"env": "test", "team": "testers", "version": "0.0.1"},
service="resource_service_name",
Copy link
Contributor

Choose a reason for hiding this comment

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

Also want a test for when the span.resources does not include service.name and it's backed off to the existing configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added 👍

@ericmustin
Copy link
Contributor Author

sorry for all the noise here, was having some linting issues

@codeboten codeboten merged commit 6503daf into open-telemetry:master Sep 18, 2020
@ericmustin ericmustin deleted the update_datadog_resource_label_usage branch September 19, 2020 13:05
alertedsnake pushed a commit to alertedsnake/opentelemetry-python that referenced this pull request Sep 25, 2020
…pen-telemetry#1074)

* exporter/datadog: add support for resource labels and service.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants