Skip to content

Commit 6e678a6

Browse files
committed
fix: capturing extra-http-headers from agent config
Signed-off-by: Cagri Yonca <[email protected]>
1 parent 7df6275 commit 6e678a6

File tree

3 files changed

+417
-25
lines changed

3 files changed

+417
-25
lines changed

src/instana/agent/host.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717

1818
from instana.agent.base import BaseAgent
1919
from instana.collector.host import HostCollector
20-
from instana.configurator import config
2120
from instana.fsm import Discovery, TheMachine
2221
from instana.log import logger
2322
from instana.options import StandardOptions
2423
from instana.util import to_json
25-
from instana.util.config import parse_ignored_endpoints
2624
from instana.util.runtime import get_py_source
2725
from instana.version import VERSION
2826

@@ -134,29 +132,7 @@ def set_from(
134132
@param res_data: source identifiers provided as announce response
135133
@return: None
136134
"""
137-
if "secrets" in res_data:
138-
self.options.secrets_matcher = res_data["secrets"]["matcher"]
139-
self.options.secrets_list = res_data["secrets"]["list"]
140-
141-
if "extraHeaders" in res_data:
142-
if self.options.extra_http_headers is None:
143-
self.options.extra_http_headers = res_data["extraHeaders"]
144-
else:
145-
self.options.extra_http_headers.extend(res_data["extraHeaders"])
146-
logger.info(
147-
f"Will also capture these custom headers: {self.options.extra_http_headers}"
148-
)
149-
150-
if "tracing" in res_data:
151-
if (
152-
"ignore-endpoints" in res_data["tracing"]
153-
and "INSTANA_IGNORE_ENDPOINTS" not in os.environ
154-
and "tracing" not in config
155-
):
156-
self.options.ignore_endpoints = parse_ignored_endpoints(
157-
res_data["tracing"]["ignore-endpoints"]
158-
)
159-
135+
self.options.set_from(res_data)
160136
self.announce_data = AnnounceData(
161137
pid=res_data["pid"],
162138
agentUuid=res_data["agentUuid"],

src/instana/options.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,59 @@ def __init__(self, **kwds: Dict[str, Any]) -> None:
9595
if not isinstance(self.agent_port, int):
9696
self.agent_port = int(self.agent_port)
9797

98+
def set_secrets(self, secrets: Dict[str, Any]) -> None:
99+
"""
100+
Set the secret option from the agent config.
101+
@param secrets: dictionary of secrets
102+
@return: None
103+
"""
104+
self.secrets_matcher = secrets["matcher"]
105+
self.secrets_list = secrets["list"]
106+
107+
def set_extra_headers(self, extra_headers: Dict[str, Any]) -> None:
108+
"""
109+
Set the extra headers option from the agent config, which uses the legacy configuration setting.
110+
@param extra_headers: dictionary of headers
111+
@return: None
112+
"""
113+
if self.extra_http_headers is None:
114+
self.extra_http_headers = extra_headers
115+
else:
116+
self.extra_http_headers.extend(extra_headers)
117+
logger.info(
118+
f"Will also capture these custom headers: {self.extra_http_headers}"
119+
)
120+
121+
def set_tracing(self, tracing: Dict[str, Any]) -> None:
122+
"""
123+
Set tracing options from the agent config.
124+
@param tracing: tracing configuration dictionary
125+
@return: None
126+
"""
127+
if (
128+
"ignore-endpoints" in tracing
129+
and "INSTANA_IGNORE_ENDPOINTS" not in os.environ
130+
and "tracing" not in config
131+
):
132+
self.ignore_endpoints = parse_ignored_endpoints(tracing["ignore-endpoints"])
133+
if "extra-http-headers" in tracing:
134+
self.extra_http_headers = tracing["extra-http-headers"]
135+
136+
def set_from(self, res_data: Dict[str, Any]) -> None:
137+
"""
138+
Set the source identifiers given to use by the Instana Host agent.
139+
@param res_data: source identifiers provided as announce response
140+
@return: None
141+
"""
142+
if "secrets" in res_data:
143+
self.set_secrets(res_data["secrets"])
144+
145+
if "tracing" in res_data:
146+
self.set_tracing(res_data["tracing"])
147+
else:
148+
if "extraHeaders" in res_data:
149+
self.set_extra_headers(res_data["extraHeaders"])
150+
98151

99152
class ServerlessOptions(BaseOptions):
100153
"""Base class for serverless environments. Holds settings common to all serverless environments."""

0 commit comments

Comments
 (0)