13
13
- AWSFargateOptions - Options class for AWS Fargate. Holds settings specific to AWS Fargate.
14
14
- GCROptions - Options class for Google cloud Run. Holds settings specific to GCR.
15
15
"""
16
+
16
17
import os
17
18
import logging
19
+ from typing import Any , Dict
18
20
19
- from .log import logger
20
- from .util .runtime import determine_service_name
21
+ from instana .log import logger
22
+ from instana .util .config import parse_ignored_endpoints
23
+ from instana .util .runtime import determine_service_name
24
+ from instana .configurator import config
21
25
22
26
23
27
class BaseOptions (object ):
24
- """ Base class for all option classes. Holds items common to all """
28
+ """Base class for all option classes. Holds items common to all"""
25
29
26
- def __init__ (self , ** kwds ) :
30
+ def __init__ (self , ** kwds : Dict [ str , Any ]) -> None :
27
31
self .debug = False
28
32
self .log_level = logging .WARN
29
33
self .service_name = determine_service_name ()
30
34
self .extra_http_headers = None
31
35
self .allow_exit_as_root = False
36
+ self .ignore_endpoints = []
32
37
33
38
if "INSTANA_DEBUG" in os .environ :
34
39
self .log_level = logging .DEBUG
35
40
self .debug = True
36
41
37
42
if "INSTANA_EXTRA_HTTP_HEADERS" in os .environ :
38
- self .extra_http_headers = str (os .environ ["INSTANA_EXTRA_HTTP_HEADERS" ]).lower ().split (';' )
39
-
40
- if os .environ .get ("INSTANA_ALLOW_EXIT_AS_ROOT" , None ) == '1' :
43
+ self .extra_http_headers = (
44
+ str (os .environ ["INSTANA_EXTRA_HTTP_HEADERS" ]).lower ().split (";" )
45
+ )
46
+
47
+ if "INSTANA_IGNORE_ENDPOINTS" in os .environ :
48
+ self .ignore_endpoints = parse_ignored_endpoints (
49
+ os .environ ["INSTANA_IGNORE_ENDPOINTS" ]
50
+ )
51
+ else :
52
+ if (
53
+ isinstance (config .get ("tracing" ), dict )
54
+ and "ignore_endpoints" in config ["tracing" ]
55
+ ):
56
+ self .ignore_endpoints = parse_ignored_endpoints (
57
+ config ["tracing" ]["ignore_endpoints" ],
58
+ )
59
+
60
+ if os .environ .get ("INSTANA_ALLOW_EXIT_AS_ROOT" , None ) == "1" :
41
61
self .allow_exit_as_root = True
42
62
43
63
# Defaults
44
- self .secrets_matcher = ' contains-ignore-case'
45
- self .secrets_list = [' key' , ' pass' , ' secret' ]
64
+ self .secrets_matcher = " contains-ignore-case"
65
+ self .secrets_list = [" key" , " pass" , " secret" ]
46
66
47
67
# Env var format: <matcher>:<secret>[,<secret>]
48
68
self .secrets = os .environ .get ("INSTANA_SECRETS" , None )
49
69
50
70
if self .secrets is not None :
51
- parts = self .secrets .split (':' )
71
+ parts = self .secrets .split (":" )
52
72
if len (parts ) == 2 :
53
73
self .secrets_matcher = parts [0 ]
54
- self .secrets_list = parts [1 ].split (',' )
74
+ self .secrets_list = parts [1 ].split ("," )
55
75
else :
56
- logger .warning ("Couldn't parse INSTANA_SECRETS env var: %s" , self .secrets )
76
+ logger .warning (
77
+ f"Couldn't parse INSTANA_SECRETS env var: { self .secrets } "
78
+ )
57
79
58
80
self .__dict__ .update (kwds )
59
81
60
82
61
83
class StandardOptions (BaseOptions ):
62
- """ The options class used when running directly on a host/node with an Instana agent """
84
+ """The options class used when running directly on a host/node with an Instana agent"""
85
+
63
86
AGENT_DEFAULT_HOST = "localhost"
64
87
AGENT_DEFAULT_PORT = 42699
65
88
66
- def __init__ (self , ** kwds ) :
89
+ def __init__ (self , ** kwds : Dict [ str , Any ]) -> None :
67
90
super (StandardOptions , self ).__init__ ()
68
91
69
92
self .agent_host = os .environ .get ("INSTANA_AGENT_HOST" , self .AGENT_DEFAULT_HOST )
@@ -74,9 +97,9 @@ def __init__(self, **kwds):
74
97
75
98
76
99
class ServerlessOptions (BaseOptions ):
77
- """ Base class for serverless environments. Holds settings common to all serverless environments. """
100
+ """Base class for serverless environments. Holds settings common to all serverless environments."""
78
101
79
- def __init__ (self , ** kwds ) :
102
+ def __init__ (self , ** kwds : Dict [ str , Any ]) -> None :
80
103
super (ServerlessOptions , self ).__init__ ()
81
104
82
105
self .agent_key = os .environ .get ("INSTANA_AGENT_KEY" , None )
@@ -86,7 +109,7 @@ def __init__(self, **kwds):
86
109
if self .endpoint_url is not None and self .endpoint_url [- 1 ] == "/" :
87
110
self .endpoint_url = self .endpoint_url [:- 1 ]
88
111
89
- if ' INSTANA_DISABLE_CA_CHECK' in os .environ :
112
+ if " INSTANA_DISABLE_CA_CHECK" in os .environ :
90
113
self .ssl_verify = False
91
114
else :
92
115
self .ssl_verify = True
@@ -95,7 +118,7 @@ def __init__(self, **kwds):
95
118
if proxy is None :
96
119
self .endpoint_proxy = {}
97
120
else :
98
- self .endpoint_proxy = {' https' : proxy }
121
+ self .endpoint_proxy = {" https" : proxy }
99
122
100
123
timeout_in_ms = os .environ .get ("INSTANA_TIMEOUT" , None )
101
124
if timeout_in_ms is None :
@@ -105,9 +128,13 @@ def __init__(self, **kwds):
105
128
try :
106
129
self .timeout = int (timeout_in_ms ) / 1000
107
130
except ValueError :
108
- logger .warning ("Likely invalid INSTANA_TIMEOUT=%s value. Using default." , timeout_in_ms )
109
- logger .warning ("INSTANA_TIMEOUT should specify timeout in milliseconds. See "
110
- "https://www.instana.com/docs/reference/environment_variables/#serverless-monitoring" )
131
+ logger .warning (
132
+ f"Likely invalid INSTANA_TIMEOUT={ timeout_in_ms } value. Using default."
133
+ )
134
+ logger .warning (
135
+ "INSTANA_TIMEOUT should specify timeout in milliseconds. See "
136
+ "https://www.instana.com/docs/reference/environment_variables/#serverless-monitoring"
137
+ )
111
138
self .timeout = 0.8
112
139
113
140
value = os .environ .get ("INSTANA_LOG_LEVEL" , None )
@@ -123,49 +150,52 @@ def __init__(self, **kwds):
123
150
elif value == "error" :
124
151
self .log_level = logging .ERROR
125
152
else :
126
- logger .warning ("Unknown INSTANA_LOG_LEVEL specified: %s" , value )
153
+ logger .warning (f "Unknown INSTANA_LOG_LEVEL specified: { value } " )
127
154
except Exception :
128
155
logger .debug ("BaseAgent.update_log_level: " , exc_info = True )
129
156
130
157
131
158
class AWSLambdaOptions (ServerlessOptions ):
132
- """ Options class for AWS Lambda. Holds settings specific to AWS Lambda. """
159
+ """Options class for AWS Lambda. Holds settings specific to AWS Lambda."""
133
160
134
- def __init__ (self , ** kwds ) :
161
+ def __init__ (self , ** kwds : Dict [ str , Any ]) -> None :
135
162
super (AWSLambdaOptions , self ).__init__ ()
136
163
137
164
138
165
class AWSFargateOptions (ServerlessOptions ):
139
- """ Options class for AWS Fargate. Holds settings specific to AWS Fargate. """
166
+ """Options class for AWS Fargate. Holds settings specific to AWS Fargate."""
140
167
141
- def __init__ (self , ** kwds ) :
168
+ def __init__ (self , ** kwds : Dict [ str , Any ]) -> None :
142
169
super (AWSFargateOptions , self ).__init__ ()
143
170
144
171
self .tags = None
145
172
tag_list = os .environ .get ("INSTANA_TAGS" , None )
146
173
if tag_list is not None :
147
174
try :
148
175
self .tags = dict ()
149
- tags = tag_list .split (',' )
176
+ tags = tag_list .split ("," )
150
177
for tag_and_value in tags :
151
- parts = tag_and_value .split ('=' )
178
+ parts = tag_and_value .split ("=" )
152
179
length = len (parts )
153
180
if length == 1 :
154
181
self .tags [parts [0 ]] = None
155
182
elif length == 2 :
156
183
self .tags [parts [0 ]] = parts [1 ]
157
184
except Exception :
158
- logger .debug ("Error parsing INSTANA_TAGS env var: %s" , tag_list )
185
+ logger .debug (f "Error parsing INSTANA_TAGS env var: { tag_list } " )
159
186
160
187
self .zone = os .environ .get ("INSTANA_ZONE" , None )
161
188
189
+
162
190
class EKSFargateOptions (AWSFargateOptions ):
163
- """ Options class for EKS Pods on AWS Fargate. Holds settings specific to EKS Pods on AWS Fargate. """
164
- def __init__ (self , ** kwds ):
191
+ """Options class for EKS Pods on AWS Fargate. Holds settings specific to EKS Pods on AWS Fargate."""
192
+
193
+ def __init__ (self , ** kwds : Dict [str , Any ]) -> None :
165
194
super (EKSFargateOptions , self ).__init__ ()
166
195
196
+
167
197
class GCROptions (ServerlessOptions ):
168
- """ Options class for Google Cloud Run. Holds settings specific to Google Cloud Run. """
198
+ """Options class for Google Cloud Run. Holds settings specific to Google Cloud Run."""
169
199
170
- def __init__ (self , ** kwds ) :
200
+ def __init__ (self , ** kwds : Dict [ str , Any ]) -> None :
171
201
super (GCROptions , self ).__init__ ()
0 commit comments