From 2bc6b218614c5e4d74fe8fdf4163c504029a12d4 Mon Sep 17 00:00:00 2001 From: Yusuke Tsutsumi Date: Tue, 9 Mar 2021 22:46:26 -0800 Subject: [PATCH 1/3] datadog: do not add None tracestate value. The datadog exporter sometimes attempts to add a "None" value, if the datadog origin header doesn't exist. This does not cause runtime errors in the most recent opentelemetry release (tracestate protects against an invalid value), but does cause warnings: WARNING opentelemetry.trace.span:span.py:230 Invalid key/value pair (dd_origin, None) found. --- .../src/opentelemetry/exporter/datadog/propagator.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py index 9e28398579..11c0ed1be7 100644 --- a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py +++ b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py @@ -27,8 +27,7 @@ class DatadogFormat(TextMapPropagator): - """Propagator for the Datadog HTTP header format. - """ + """Propagator for the Datadog HTTP header format.""" TRACE_ID_KEY = "x-datadog-trace-id" PARENT_ID_KEY = "x-datadog-parent-id" @@ -65,12 +64,15 @@ def extract( if trace_id is None or span_id is None: return set_span_in_context(trace.INVALID_SPAN, context) + trace_state = [] + if origin is not None: + trace_state.append((constants.DD_ORIGIN, origin)) span_context = trace.SpanContext( trace_id=int(trace_id), span_id=int(span_id), is_remote=True, trace_flags=trace_flags, - trace_state=trace.TraceState([(constants.DD_ORIGIN, origin)]), + trace_state=trace.TraceState(trace_state), ) return set_span_in_context( @@ -89,7 +91,9 @@ def inject( return sampled = (trace.TraceFlags.SAMPLED & span.context.trace_flags) != 0 set_in_carrier( - carrier, self.TRACE_ID_KEY, format_trace_id(span.context.trace_id), + carrier, + self.TRACE_ID_KEY, + format_trace_id(span.context.trace_id), ) set_in_carrier( carrier, self.PARENT_ID_KEY, format_span_id(span.context.span_id) From 98d0751bb158dd84fe837d19a3853e1f527bc8f1 Mon Sep 17 00:00:00 2001 From: Yusuke Tsutsumi Date: Tue, 9 Mar 2021 23:00:55 -0800 Subject: [PATCH 2/3] Adding changelog entry --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7930081776..538ee3269f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Rename `IdsGenerator` to `IdGenerator` ([#350](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/350)) +- `opentelemetry-exporter-datadog` Fix warning when DatadogFormat encounters a request with + no DD_ORIGIN headers ([#368](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/368)). ## [0.18b0](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.18b0) - 2021-02-16 @@ -21,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#345](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/345)) ### Removed -- Remove `component` span attribute in instrumentations. +- Remove `component` span attribute in instrumentations. `opentelemetry-instrumentation-aiopg`, `opentelemetry-instrumentation-dbapi` Remove unused `database_type` parameter from `trace_integration` function. ([#301](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/301)) - `opentelemetry-instrumentation-asgi` Return header values using case insensitive keys From 7f572a226d7234edf0dcaa8bf4751f9f1d958137 Mon Sep 17 00:00:00 2001 From: Yusuke Tsutsumi Date: Tue, 9 Mar 2021 23:08:59 -0800 Subject: [PATCH 3/3] fixing lint --- .../src/opentelemetry/exporter/datadog/propagator.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py index 11c0ed1be7..bddf0cabba 100644 --- a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py +++ b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py @@ -91,9 +91,7 @@ def inject( return sampled = (trace.TraceFlags.SAMPLED & span.context.trace_flags) != 0 set_in_carrier( - carrier, - self.TRACE_ID_KEY, - format_trace_id(span.context.trace_id), + carrier, self.TRACE_ID_KEY, format_trace_id(span.context.trace_id), ) set_in_carrier( carrier, self.PARENT_ID_KEY, format_span_id(span.context.span_id)