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 26, 2025
1 parent 7df6275 commit 6e678a6
Show file tree
Hide file tree
Showing 3 changed files with 417 additions and 25 deletions.
26 changes: 1 addition & 25 deletions src/instana/agent/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@

from instana.agent.base import BaseAgent
from instana.collector.host import HostCollector
from instana.configurator import config
from instana.fsm import Discovery, TheMachine
from instana.log import logger
from instana.options import StandardOptions
from instana.util import to_json
from instana.util.config import parse_ignored_endpoints
from instana.util.runtime import get_py_source
from instana.version import VERSION

Expand Down Expand Up @@ -134,29 +132,7 @@ def set_from(
@param res_data: source identifiers provided as announce response
@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}"
)

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.options.set_from(res_data)
self.announce_data = AnnounceData(
pid=res_data["pid"],
agentUuid=res_data["agentUuid"],
Expand Down
53 changes: 53 additions & 0 deletions src/instana/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,59 @@ def __init__(self, **kwds: Dict[str, Any]) -> None:
if not isinstance(self.agent_port, int):
self.agent_port = int(self.agent_port)

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

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

def set_tracing(self, tracing: Dict[str, Any]) -> None:
"""
Set tracing options from the 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.ignore_endpoints = parse_ignored_endpoints(tracing["ignore-endpoints"])
if "extra-http-headers" in tracing:
self.extra_http_headers = tracing["extra-http-headers"]

def set_from(self, res_data: Dict[str, Any]) -> None:
"""
Set the source identifiers given to use by the Instana Host agent.
@param res_data: source identifiers provided as announce response
@return: None
"""
if "secrets" in res_data:
self.set_secrets(res_data["secrets"])

if "tracing" in res_data:
self.set_tracing(res_data["tracing"])
else:
if "extraHeaders" in res_data:
self.set_extra_headers(res_data["extraHeaders"])


class ServerlessOptions(BaseOptions):
"""Base class for serverless environments. Holds settings common to all serverless environments."""
Expand Down
Loading

0 comments on commit 6e678a6

Please sign in to comment.