-
Notifications
You must be signed in to change notification settings - Fork 712
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
exporter/datadog: add support for resource labels and service.name #1074
Conversation
exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py
Outdated
Show resolved
Hide resolved
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, minor comments
exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py
Outdated
Show resolved
Hide resolved
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 | ||
|
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.
This could be more simply handled by attempting to cast to string inside a try/except
block and log the exception if casting fails.
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, i had ripped it from the zipkin approach but agreed those improvements make sense to me
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.
turns out datadog's add span method handles this casting under the hood, so removing this section entirely for perf
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: |
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.
Did you mean if not (resource and resource.labels):
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.
👍 ah yup ty, 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.
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)): |
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.
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
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
resource = Resource( | ||
labels={ | ||
"key_resource": "some_resource", | ||
"service.name": "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.
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.
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, 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", |
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.
Also want a test for when the span.resources
does not include service.name
and it's backed off to the existing configuration.
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.
added 👍
sorry for all the noise here, was having some linting issues |
…pen-telemetry#1074) * exporter/datadog: add support for resource labels and service.name
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.
How Has This Been Tested?
I've updated the Unit Tests as well as the Example
Checklist: