Skip to content

Commit

Permalink
fix: capturing extra-http-headers from agent config
Browse files Browse the repository at this point in the history
Signed-off-by: Cagri Yonca <[email protected]>
  • Loading branch information
CagriYonca committed Feb 10, 2025
1 parent 202f144 commit 0966594
Showing 1 changed file with 45 additions and 19 deletions.
64 changes: 45 additions & 19 deletions src/instana/agent/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,46 @@ def can_send(self) -> bool:

return False

def set_secrets(self, secrets: Dict[str, Any]) -> None:
"""
Setting secret options from agent config
@param secrets: dictionary of secrets
@return: None
"""
self.options.secrets_matcher = secrets["matcher"]
self.options.secrets_list = secrets["list"]

def set_extra_headers(self, extra_headers: Dict[str, Any]) -> None:
"""
Setting extra headers options from agent config, uses legacy configuration setting
@param extra_headers: dictionary of headers
@return: None
"""
if self.options.extra_http_headers is None:
self.options.extra_http_headers = extra_headers
else:
self.options.extra_http_headers.extend(extra_headers)
logger.info(
f"Will also capture these custom headers: {self.options.extra_http_headers}"
)

def set_tracing(self, tracing: Dict[str, Any]) -> None:
"""
Setting ignore-endpoints and extra-http-headers from agent config
@param tracing: tracing configuration dictionary
@return: None
"""
if (
"ignore-endpoints" in tracing
and "INSTANA_IGNORE_ENDPOINTS" not in os.environ
and "tracing" not in config
):
self.options.ignore_endpoints = parse_ignored_endpoints(
tracing["ignore-endpoints"]
)
if "extra-http-headers" in tracing:
self.options.extra_http_headers = tracing["extra-http-headers"]

def set_from(
self,
res_data: Dict[str, Any],
Expand All @@ -135,27 +175,13 @@ def set_from(
@return: None
"""
if "secrets" in res_data:
self.options.secrets_matcher = res_data["secrets"]["matcher"]
self.options.secrets_list = res_data["secrets"]["list"]

if "extraHeaders" in res_data:
if self.options.extra_http_headers is None:
self.options.extra_http_headers = res_data["extraHeaders"]
else:
self.options.extra_http_headers.extend(res_data["extraHeaders"])
logger.info(
f"Will also capture these custom headers: {self.options.extra_http_headers}"
)
self.set_secrets(res_data["secrets"])

if "tracing" in res_data:
if (
"ignore-endpoints" in res_data["tracing"]
and "INSTANA_IGNORE_ENDPOINTS" not in os.environ
and "tracing" not in config
):
self.options.ignore_endpoints = parse_ignored_endpoints(
res_data["tracing"]["ignore-endpoints"]
)
self.set_tracing(res_data["tracing"])
else:
if "extraHeaders" in res_data:
self.set_extra_headers(res_data["extraHeaders"])

self.announce_data = AnnounceData(
pid=res_data["pid"],
Expand Down

0 comments on commit 0966594

Please sign in to comment.