diff --git a/ddtrace/internal/remoteconfig/client.py b/ddtrace/internal/remoteconfig/client.py index 2fc02392227..9e8729a0242 100644 --- a/ddtrace/internal/remoteconfig/client.py +++ b/ddtrace/internal/remoteconfig/client.py @@ -162,8 +162,7 @@ def __init__(self): tracer_version = _pep440_to_semver() self.id = str(uuid.uuid4()) - self.agent_url = agent_url = agent.get_trace_url() - self._conn = agent.get_connection(agent_url, timeout=agent.get_trace_agent_timeout()) + self.agent_url = agent.get_trace_url() self._headers = {"content-type": "application/json"} additional_header_str = os.environ.get("_DD_REMOTE_CONFIGURATION_ADDITIONAL_HEADERS") @@ -257,14 +256,15 @@ def _send_request(self, payload): log.debug( "[%s][P: %s] Requesting RC data from products: %s", os.getpid(), os.getppid(), str(self._products) ) # noqa: G200 - self._conn.request("POST", REMOTE_CONFIG_AGENT_ENDPOINT, payload, self._headers) - resp = self._conn.getresponse() + conn = agent.get_connection(self.agent_url, timeout=agent.get_trace_agent_timeout()) + conn.request("POST", REMOTE_CONFIG_AGENT_ENDPOINT, payload, self._headers) + resp = conn.getresponse() data = resp.read() except OSError as e: log.debug("Unexpected connection error in remote config client request: %s", str(e)) # noqa: G200 return None finally: - self._conn.close() + conn.close() if resp.status == 404: # Remote configuration is not enabled or unsupported by the agent