From 2d9df106455de7b1b5aa3dfe180059fe9366d039 Mon Sep 17 00:00:00 2001 From: Yusuke Tsutsumi Date: Wed, 10 Mar 2021 22:33:12 -0800 Subject: [PATCH] datadog: do not add None tracestate value. (#368) 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. --- CHANGELOG.md | 4 +++- .../src/opentelemetry/exporter/datadog/propagator.py | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) 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 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..bddf0cabba 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(