@@ -37,36 +37,9 @@ def __init__(self, **kwds: Dict[str, Any]) -> None:
3737 self .extra_http_headers = None
3838 self .allow_exit_as_root = False
3939 self .ignore_endpoints = []
40+ self .kafka_trace_correlation = True
4041
41- if "INSTANA_DEBUG" in os .environ :
42- self .log_level = logging .DEBUG
43- self .debug = True
44-
45- if "INSTANA_EXTRA_HTTP_HEADERS" in os .environ :
46- self .extra_http_headers = (
47- str (os .environ ["INSTANA_EXTRA_HTTP_HEADERS" ]).lower ().split (";" )
48- )
49-
50- if "INSTANA_IGNORE_ENDPOINTS_PATH" in os .environ :
51- self .ignore_endpoints = parse_ignored_endpoints_from_yaml (
52- os .environ ["INSTANA_IGNORE_ENDPOINTS_PATH" ]
53- )
54- else :
55- if "INSTANA_IGNORE_ENDPOINTS" in os .environ :
56- self .ignore_endpoints = parse_ignored_endpoints (
57- os .environ ["INSTANA_IGNORE_ENDPOINTS" ]
58- )
59- else :
60- if (
61- isinstance (config .get ("tracing" ), dict )
62- and "ignore_endpoints" in config ["tracing" ]
63- ):
64- self .ignore_endpoints = parse_ignored_endpoints (
65- config ["tracing" ]["ignore_endpoints" ],
66- )
67-
68- if os .environ .get ("INSTANA_ALLOW_EXIT_AS_ROOT" , None ) == "1" :
69- self .allow_exit_as_root = True
42+ self .set_trace_configurations ()
7043
7144 # Defaults
7245 self .secrets_matcher = "contains-ignore-case"
@@ -87,6 +60,56 @@ def __init__(self, **kwds: Dict[str, Any]) -> None:
8760
8861 self .__dict__ .update (kwds )
8962
63+ def set_trace_configurations (self ) -> None :
64+ """
65+ Set tracing configurations from the environment variables and config file.
66+ @return: None
67+ """
68+ # Use self.configurations to not read local configuration file
69+ # in set_tracing method
70+ if "INSTANA_DEBUG" in os .environ :
71+ self .log_level = logging .DEBUG
72+ self .debug = True
73+
74+ if "INSTANA_EXTRA_HTTP_HEADERS" in os .environ :
75+ self .extra_http_headers = (
76+ str (os .environ ["INSTANA_EXTRA_HTTP_HEADERS" ]).lower ().split (";" )
77+ )
78+
79+ if "1" in [
80+ os .environ .get ("INSTANA_ALLOW_EXIT_AS_ROOT" , None ), # deprecated
81+ os .environ .get ("INSTANA_ALLOW_ROOT_EXIT_SPAN" , None ),
82+ ]:
83+ self .allow_exit_as_root = True
84+
85+ # The priority is as follows:
86+ # environment variables > in-code configuration >
87+ # > agent config (configuration.yaml) > default value
88+ if "INSTANA_IGNORE_ENDPOINTS" in os .environ :
89+ self .ignore_endpoints = parse_ignored_endpoints (
90+ os .environ ["INSTANA_IGNORE_ENDPOINTS" ]
91+ )
92+ elif "INSTANA_IGNORE_ENDPOINTS_PATH" in os .environ :
93+ self .ignore_endpoints = parse_ignored_endpoints_from_yaml (
94+ os .environ ["INSTANA_IGNORE_ENDPOINTS_PATH" ]
95+ )
96+ elif (
97+ isinstance (config .get ("tracing" ), dict )
98+ and "ignore_endpoints" in config ["tracing" ]
99+ ):
100+ self .ignore_endpoints = parse_ignored_endpoints (
101+ config ["tracing" ]["ignore_endpoints" ],
102+ )
103+
104+ if "INSTANA_KAFKA_TRACE_CORRELATION" in os .environ :
105+ self .kafka_trace_correlation = (
106+ os .environ ["INSTANA_KAFKA_TRACE_CORRELATION" ].lower () == "true"
107+ )
108+ elif isinstance (config .get ("tracing" ), dict ) and "kafka" in config ["tracing" ]:
109+ self .kafka_trace_correlation = config ["tracing" ]["kafka" ].get (
110+ "trace_correlation" , True
111+ )
112+
90113
91114class StandardOptions (BaseOptions ):
92115 """The options class used when running directly on a host/node with an Instana agent"""
@@ -132,12 +155,30 @@ def set_tracing(self, tracing: Dict[str, Any]) -> None:
132155 @param tracing: tracing configuration dictionary
133156 @return: None
134157 """
135- if (
136- "ignore-endpoints" in tracing
137- and "INSTANA_IGNORE_ENDPOINTS" not in os .environ
138- and "tracing" not in config
139- ):
158+ if "ignore-endpoints" in tracing and not self .ignore_endpoints :
140159 self .ignore_endpoints = parse_ignored_endpoints (tracing ["ignore-endpoints" ])
160+
161+ if "kafka" in tracing :
162+ if (
163+ "INSTANA_KAFKA_TRACE_CORRELATION" not in os .environ
164+ and not (
165+ isinstance (config .get ("tracing" ), dict )
166+ and "kafka" in config ["tracing" ]
167+ )
168+ and "trace-correlation" in tracing ["kafka" ]
169+ ):
170+ self .kafka_trace_correlation = (
171+ str (tracing ["kafka" ].get ("trace-correlation" , True )) == "true"
172+ )
173+
174+ if (
175+ "header-format" in tracing ["kafka" ]
176+ and tracing ["kafka" ]["header-format" ] == "binary"
177+ ):
178+ logger .warning (
179+ "Binary header format for Kafka is deprecated. Please use string header format."
180+ )
181+
141182 if "extra-http-headers" in tracing :
142183 self .extra_http_headers = tracing ["extra-http-headers" ]
143184
@@ -156,6 +197,7 @@ def set_from(self, res_data: Dict[str, Any]) -> None:
156197
157198 if "tracing" in res_data :
158199 self .set_tracing (res_data ["tracing" ])
200+
159201 else :
160202 if "extraHeaders" in res_data :
161203 self .set_extra_headers (res_data ["extraHeaders" ])
0 commit comments