Skip to content

Commit

Permalink
test: Cover AutoTrace and Autowrap instrumentation methods
Browse files Browse the repository at this point in the history
Signed-off-by: Ferenc Géczi <ferenc.geczi@ibm.com>
  • Loading branch information
Ferenc- committed Oct 20, 2023
1 parent d44efda commit 999ba11
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion tests/platforms/test_host_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import json
import unittest
import sys
import mock
from mock import patch

Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand Down Expand Up @@ -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'])

0 comments on commit 999ba11

Please sign in to comment.