|
22 | 22 | from threading import Timer |
23 | 23 | import pkg_resources |
24 | 24 |
|
| 25 | +from .version import VERSION |
| 26 | + |
25 | 27 | __author__ = 'Instana Inc.' |
26 | 28 | __copyright__ = 'Copyright 2020 Instana Inc.' |
27 | 29 | __credits__ = ['Pavlo Baron', 'Peter Giacomo Lombardo', 'Andrey Slotin'] |
28 | 30 | __license__ = 'MIT' |
29 | 31 | __maintainer__ = 'Peter Giacomo Lombardo' |
30 | 32 | |
| 33 | +__version__ = VERSION |
| 34 | + |
| 35 | +# User configurable EUM API key for instana.helpers.eum_snippet() |
| 36 | +# pylint: disable=invalid-name |
| 37 | +eum_api_key = '' |
31 | 38 |
|
32 | | -try: |
33 | | - __version__ = pkg_resources.get_distribution('instana').version |
34 | | -except pkg_resources.DistributionNotFound: |
35 | | - __version__ = 'unknown' |
| 39 | +# This Python package can be loaded into Python processes one of three ways: |
| 40 | +# 1. manual import statement |
| 41 | +# 2. autowrapt hook |
| 42 | +# 3. dynamically injected remotely |
| 43 | +# |
| 44 | +# With such magic, we may get pulled into Python processes that we have no interest being in. |
| 45 | +# As a safety measure, we maintain a "do not load list" and if this process matches something |
| 46 | +# in that list, then we go sit in a corner quietly and don't load anything at all. |
| 47 | +do_not_load_list = ["pip", "pip2", "pip3", "pipenv", "docker-compose", "easy_install", "easy_install-2.7", |
| 48 | + "smtpd.py", "twine", "ufw", "unattended-upgrade"] |
36 | 49 |
|
37 | 50 |
|
38 | 51 | def load(_): |
39 | 52 | """ |
40 | 53 | Method used to activate the Instana sensor via AUTOWRAPT_BOOTSTRAP |
41 | 54 | environment variable. |
42 | 55 | """ |
43 | | - if "INSTANA_DEBUG" in os.environ: |
44 | | - print("Instana: activated via AUTOWRAPT_BOOTSTRAP") |
45 | | - |
| 56 | + return None |
46 | 57 |
|
47 | 58 | def get_lambda_handler_or_default(): |
48 | 59 | """ |
@@ -95,7 +106,7 @@ def lambda_handler(event, context): |
95 | 106 | def boot_agent_later(): |
96 | 107 | """ Executes <boot_agent> in the future! """ |
97 | 108 | if 'gevent' in sys.modules: |
98 | | - import gevent |
| 109 | + import gevent # pylint: disable=import-outside-toplevel |
99 | 110 | gevent.spawn_later(2.0, boot_agent) |
100 | 111 | else: |
101 | 112 | Timer(2.0, boot_agent).start() |
@@ -148,42 +159,20 @@ def boot_agent(): |
148 | 159 | # Hooks |
149 | 160 | from .hooks import hook_uwsgi |
150 | 161 |
|
151 | | - |
152 | | -if "INSTANA_MAGIC" in os.environ: |
153 | | - pkg_resources.working_set.add_entry("/tmp/.instana/python") |
154 | | - # The following path is deprecated: To be removed at a future date |
155 | | - pkg_resources.working_set.add_entry("/tmp/instana/python") |
156 | | - |
157 | | - if "INSTANA_DEBUG" in os.environ: |
158 | | - print("Instana: activated via AutoTrace") |
159 | | -else: |
160 | | - if ("INSTANA_DEBUG" in os.environ) and ("AUTOWRAPT_BOOTSTRAP" not in os.environ): |
161 | | - print("Instana: activated via manual import") |
162 | | - |
163 | | -# User configurable EUM API key for instana.helpers.eum_snippet() |
164 | | -# pylint: disable=invalid-name |
165 | | -eum_api_key = '' |
166 | | - |
167 | | -# This Python package can be loaded into Python processes one of three ways: |
168 | | -# 1. manual import statement |
169 | | -# 2. autowrapt hook |
170 | | -# 3. dynamically injected remotely |
171 | | -# |
172 | | -# With such magic, we may get pulled into Python processes that we have no interest being in. |
173 | | -# As a safety measure, we maintain a "do not load list" and if this process matches something |
174 | | -# in that list, then we go sit in a corner quietly and don't load anything at all. |
175 | | -do_not_load_list = ["pip", "pip2", "pip3", "pipenv", "docker-compose", "easy_install", "easy_install-2.7", |
176 | | - "smtpd.py", "twine", "ufw", "unattended-upgrade"] |
177 | | - |
178 | | -# There are cases when sys.argv may not be defined at load time. Seems to happen in embedded Python, |
179 | | -# and some Pipenv installs. If this is the case, it's best effort. |
180 | | -if hasattr(sys, 'argv') and len(sys.argv) > 0 and (os.path.basename(sys.argv[0]) in do_not_load_list): |
181 | | - if "INSTANA_DEBUG" in os.environ: |
182 | | - print("Instana: No use in monitoring this process type (%s). " |
183 | | - "Will go sit in a corner quietly." % os.path.basename(sys.argv[0])) |
184 | | -else: |
185 | | - if "INSTANA_MAGIC" in os.environ: |
186 | | - # If we're being loaded into an already running process, then delay agent initialization |
187 | | - boot_agent_later() |
| 162 | +if 'INSTANA_DISABLE' not in os.environ: |
| 163 | + # There are cases when sys.argv may not be defined at load time. Seems to happen in embedded Python, |
| 164 | + # and some Pipenv installs. If this is the case, it's best effort. |
| 165 | + if hasattr(sys, 'argv') and len(sys.argv) > 0 and (os.path.basename(sys.argv[0]) in do_not_load_list): |
| 166 | + if "INSTANA_DEBUG" in os.environ: |
| 167 | + print("Instana: No use in monitoring this process type (%s). " |
| 168 | + "Will go sit in a corner quietly." % os.path.basename(sys.argv[0])) |
188 | 169 | else: |
189 | | - boot_agent() |
| 170 | + if "INSTANA_MAGIC" in os.environ: |
| 171 | + pkg_resources.working_set.add_entry("/tmp/.instana/python") |
| 172 | + # The following path is deprecated: To be removed at a future date |
| 173 | + pkg_resources.working_set.add_entry("/tmp/instana/python") |
| 174 | + |
| 175 | + # If we're being loaded into an already running process, then delay agent initialization |
| 176 | + boot_agent_later() |
| 177 | + else: |
| 178 | + boot_agent() |
0 commit comments