diff --git a/ddtrace/settings/config.py b/ddtrace/settings/config.py index 972d2fff700..10cc15a5828 100644 --- a/ddtrace/settings/config.py +++ b/ddtrace/settings/config.py @@ -743,8 +743,15 @@ def _handle_remoteconfig(self, data, test_tracer=None): log.warning("unexpected number of RC payloads %r", data) return + # Check if 'lib_config' is a key in the dictionary since other items can be sent in the payload + config = None + for config_item in data["config"]: + if isinstance(config_item, Dict): + if "lib_config" in config_item: + config = config_item + break + # If no data is submitted then the RC config has been deleted. Revert the settings. - config = data["config"][0] base_rc_config = {n: None for n in self._config} if config and "lib_config" in config: @@ -777,7 +784,6 @@ def _handle_remoteconfig(self, data, test_tracer=None): if tags: tags = self._format_tags(lib_config["tracing_header_tags"]) base_rc_config["trace_http_header_tags"] = tags - self._set_config_items([(k, v, "remote_config") for k, v in base_rc_config.items()]) # called unconditionally to handle the case where header tags have been unset self._handle_remoteconfig_header_tags(base_rc_config) diff --git a/releasenotes/notes/rc_payload_fix-a03a98dcad934658.yaml b/releasenotes/notes/rc_payload_fix-a03a98dcad934658.yaml new file mode 100644 index 00000000000..330c6586eb9 --- /dev/null +++ b/releasenotes/notes/rc_payload_fix-a03a98dcad934658.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + RemoteConfig: This fix resolves an issue where remote config did not work for the tracer when using an agent + that would add a flare item to the remote config payload. With this fix, the tracer will now correctly pull out + the lib_config we need from the payload in order to implement remote config changes properly. + + diff --git a/tests/internal/test_settings.py b/tests/internal/test_settings.py index 4bae14bfef9..0ad706b3951 100644 --- a/tests/internal/test_settings.py +++ b/tests/internal/test_settings.py @@ -16,11 +16,25 @@ def _base_rc_config(cfg): return { "metadata": [], "config": [ + # this flare data can often come in and we want to make sure we're pulling the + # actual lib_config data out correctly regardless + { + "internal_order": [ + "flare-log-level.trace", + "flare-log-level.debug", + "flare-log-level.info", + "flare-log-level.warn", + "flare-log-level.error", + "flare-log-level.critical", + "flare-log-level.off", + ], + "order": [], + }, { "action": "enable", "service_target": {"service": None, "env": None}, "lib_config": cfg, - } + }, ], } @@ -182,7 +196,7 @@ def test_settings_missing_lib_config(config, monkeypatch): base_rc_config = _base_rc_config({}) # Delete "lib_config" from the remote config - del base_rc_config["config"][0]["lib_config"] + del base_rc_config["config"][1]["lib_config"] assert "lib_config" not in base_rc_config["config"][0] config._handle_remoteconfig(base_rc_config, None)