diff --git a/tests/platforms/test_host_collector.py b/tests/platforms/test_host_collector.py index e8b998b39..d58c32c10 100644 --- a/tests/platforms/test_host_collector.py +++ b/tests/platforms/test_host_collector.py @@ -6,6 +6,7 @@ import os import json import unittest +import sys import mock from mock import patch @@ -36,7 +37,8 @@ def tearDown(self): "AWS_EXECUTION_ENV", "INSTANA_EXTRA_HTTP_HEADERS", "INSTANA_ENDPOINT_URL", "INSTANA_AGENT_KEY", "INSTANA_ZONE", "INSTANA_TAGS", "INSTANA_DISABLE_METRICS_COLLECTION", - "INSTANA_DISABLE_PYTHON_PACKAGE_COLLECTION" + "INSTANA_DISABLE_PYTHON_PACKAGE_COLLECTION", + "AUTOWRAPT_BOOTSTRAP" ) for variable_name in variable_names: @@ -45,6 +47,8 @@ def tearDown(self): set_agent(self.original_agent) set_tracer(self.original_tracer) + if '/tmp/.instana/python' in sys.path: + sys.path.remove('/tmp/.instana/python') def create_agent_and_setup_tracer(self): self.agent = HostAgent() @@ -195,3 +199,49 @@ def test_prepare_payload_with_snapshot_disabled_python_packages(self, mock_shoul self.assertIn('version', snapshot) self.assertEqual(len(snapshot['versions']), 1) self.assertEqual(snapshot['versions']['instana'], VERSION) + + + @patch.object(HostCollector, "should_send_snapshot_data") + def test_prepare_payload_with_autowrapt(self, mock_should_send_snapshot_data): + mock_should_send_snapshot_data.return_value = True + os.environ["AUTOWRAPT_BOOTSTRAP"] = "instana" + self.create_agent_and_setup_tracer() + + payload = self.agent.collector.prepare_payload() + self.assertTrue(payload) + self.assertIn('snapshot', payload['metrics']['plugins'][0]['data']) + snapshot = payload['metrics']['plugins'][0]['data']['snapshot'] + self.assertTrue(snapshot) + self.assertIn('m', snapshot) + self.assertEqual('Autowrapt', snapshot['m']) + self.assertIn('version', snapshot) + self.assertGreater(len(snapshot['versions']), 5) + self.assertEqual(snapshot['versions']['instana'], VERSION) + self.assertIn('wrapt', snapshot['versions']) + self.assertIn('fysom', snapshot['versions']) + self.assertIn('opentracing', snapshot['versions']) + self.assertIn('basictracer', snapshot['versions']) + + + @patch.object(HostCollector, "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('/tmp/.instana/python') + + self.create_agent_and_setup_tracer() + + payload = self.agent.collector.prepare_payload() + self.assertTrue(payload) + self.assertIn('snapshot', payload['metrics']['plugins'][0]['data']) + snapshot = payload['metrics']['plugins'][0]['data']['snapshot'] + self.assertTrue(snapshot) + self.assertIn('m', snapshot) + self.assertEqual('AutoTrace', snapshot['m']) + self.assertIn('version', snapshot) + self.assertGreater(len(snapshot['versions']), 5) + self.assertEqual(snapshot['versions']['instana'], VERSION) + self.assertIn('wrapt', snapshot['versions']) + self.assertIn('fysom', snapshot['versions']) + self.assertIn('opentracing', snapshot['versions']) + self.assertIn('basictracer', snapshot['versions'])