Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/instana/collector/helpers/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@

from .base import BaseHelper

PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT = '/tmp/.instana/python'
PATH_OF_AUTOTRACE_WEBHOOK_SITEDIR = '/opt/instana/instrumentation/python/'

def is_autowrapt_instrumented():
return 'instana' in os.environ.get('AUTOWRAPT_BOOTSTRAP', ())


def is_webhook_instrumented():
return any(map(lambda p: PATH_OF_AUTOTRACE_WEBHOOK_SITEDIR in p, sys.path))


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

if 'AUTOWRAPT_BOOTSTRAP' in os.environ:
if is_autowrapt_instrumented():
snapshot_payload['m'] = 'Autowrapt'
elif PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT in sys.path:
elif is_webhook_instrumented():
snapshot_payload['m'] = 'AutoTrace'
else:
snapshot_payload['m'] = 'Manual'
Expand Down
10 changes: 5 additions & 5 deletions tests/platforms/test_host_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from instana.tracer import InstanaTracer
from instana.recorder import StanRecorder
from instana.agent.host import HostAgent
from instana.collector.helpers.runtime import PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT
from instana.collector.helpers.runtime import PATH_OF_AUTOTRACE_WEBHOOK_SITEDIR
from instana.collector.host import HostCollector
from instana.singletons import get_agent, set_agent, get_tracer, set_tracer
from instana.version import VERSION
Expand All @@ -26,7 +26,7 @@ def __init__(self, methodName='runTest'):
self.original_tracer = get_tracer()

def setUp(self):
pass
self.webhook_sitedir_path = PATH_OF_AUTOTRACE_WEBHOOK_SITEDIR + '3.8.0'

def tearDown(self):
""" Reset all environment variables of consequence """
Expand All @@ -44,8 +44,8 @@ def tearDown(self):

set_agent(self.original_agent)
set_tracer(self.original_tracer)
if PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT in sys.path:
sys.path.remove(PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT)
if self.webhook_sitedir_path in sys.path:
sys.path.remove(self.webhook_sitedir_path)

def create_agent_and_setup_tracer(self):
self.agent = HostAgent()
Expand Down Expand Up @@ -223,7 +223,7 @@ def test_prepare_payload_with_autowrapt(self, mock_should_send_snapshot_data):
def test_prepare_payload_with_autotrace(self, mock_should_send_snapshot_data):
mock_should_send_snapshot_data.return_value = True

sys.path.append(PATH_OF_DEPRECATED_INSTALLATION_VIA_HOST_AGENT)
sys.path.append(self.webhook_sitedir_path)

self.create_agent_and_setup_tracer()

Expand Down