Skip to content

Commit 8eec93f

Browse files
committed
fix: Set AutoTrace method when the webhook is active
So do not look for the sideffects of the removed injector. Signed-off-by: Ferenc Géczi <[email protected]>
1 parent 4040b13 commit 8eec93f

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/instana/collector/helpers/runtime.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@
1818

1919
from .base import BaseHelper
2020

21-
PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT = '/tmp/.instana/python'
21+
PATH_OF_AUTOTRACE_WEBHOOK_SITEDIR = '/opt/instana/instrumentation/python/'
22+
23+
def is_autowrapt_instrumented():
24+
return 'instana' in os.environ.get('AUTOWRAPT_BOOTSTRAP', ())
25+
26+
27+
def is_webhook_instrumented():
28+
return any(map(lambda p: PATH_OF_AUTOTRACE_WEBHOOK_SITEDIR in p, sys.path))
29+
2230

2331
class RuntimeHelper(BaseHelper):
2432
""" Helper class to collect snapshot and metrics for this Python runtime """
@@ -180,9 +188,9 @@ def _collect_runtime_snapshot(self, plugin_data):
180188
snapshot_payload['versions'] = self.gather_python_packages()
181189
snapshot_payload['iv'] = VERSION
182190

183-
if 'AUTOWRAPT_BOOTSTRAP' in os.environ:
191+
if is_autowrapt_instrumented():
184192
snapshot_payload['m'] = 'Autowrapt'
185-
elif PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT in sys.path:
193+
elif is_webhook_instrumented():
186194
snapshot_payload['m'] = 'AutoTrace'
187195
else:
188196
snapshot_payload['m'] = 'Manual'

tests/platforms/test_host_collector.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from instana.tracer import InstanaTracer
1111
from instana.recorder import StanRecorder
1212
from instana.agent.host import HostAgent
13-
from instana.collector.helpers.runtime import PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT
13+
from instana.collector.helpers.runtime import PATH_OF_AUTOTRACE_WEBHOOK_SITEDIR
1414
from instana.collector.host import HostCollector
1515
from instana.singletons import get_agent, set_agent, get_tracer, set_tracer
1616
from instana.version import VERSION
@@ -26,7 +26,7 @@ def __init__(self, methodName='runTest'):
2626
self.original_tracer = get_tracer()
2727

2828
def setUp(self):
29-
pass
29+
self.webhook_sitedir_path = PATH_OF_AUTOTRACE_WEBHOOK_SITEDIR + '3.8.0'
3030

3131
def tearDown(self):
3232
""" Reset all environment variables of consequence """
@@ -44,8 +44,8 @@ def tearDown(self):
4444

4545
set_agent(self.original_agent)
4646
set_tracer(self.original_tracer)
47-
if PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT in sys.path:
48-
sys.path.remove(PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT)
47+
if self.webhook_sitedir_path in sys.path:
48+
sys.path.remove(self.webhook_sitedir_path)
4949

5050
def create_agent_and_setup_tracer(self):
5151
self.agent = HostAgent()
@@ -223,7 +223,7 @@ def test_prepare_payload_with_autowrapt(self, mock_should_send_snapshot_data):
223223
def test_prepare_payload_with_autotrace(self, mock_should_send_snapshot_data):
224224
mock_should_send_snapshot_data.return_value = True
225225

226-
sys.path.append(PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT)
226+
sys.path.append(self.webhook_sitedir_path)
227227

228228
self.create_agent_and_setup_tracer()
229229

0 commit comments

Comments
 (0)