Esempio n. 1
0
    def test_application_lb_trigger_tracing(self):
        with open(self.pwd + '/../data/lambda/api_gateway_event.json', 'r') as json_file:
            event = json.load(json_file)

        self.create_agent_and_setup_tracer()

        # Call the Instana Lambda Handler as we do in the real world.  It will initiate tracing and then
        # figure out the original (the users') Lambda Handler and execute it.
        # The original Lambda handler is set in os.environ["LAMBDA_HANDLER"]
        result = lambda_handler(event, self.context)

        assert isinstance(result, dict)
        assert 'headers' in result
        assert 'Server-Timing' in result['headers']

        payload = self.agent.collector.prepare_payload()

        self.assertTrue("metrics" in payload)
        self.assertTrue("spans" in payload)
        self.assertEqual(2, len(payload.keys()))

        self.assertTrue(isinstance(payload['metrics']['plugins'], list))
        self.assertTrue(len(payload['metrics']['plugins']) == 1)
        plugin_data = payload['metrics']['plugins'][0]

        self.assertEqual('com.instana.plugin.aws.lambda', plugin_data['name'])
        self.assertEqual('arn:aws:lambda:us-east-2:12345:function:TestPython:1', plugin_data['entityId'])

        self.assertEqual(1, len(payload['spans']))

        span = payload['spans'][0]
        self.assertEqual('aws.lambda.entry', span.n)
        self.assertEqual('d5cb361b256413a9', span.t)
        self.assertIsNotNone(span.s)
        self.assertEqual('0901d8ae4fbf1529', span.p)
        self.assertIsNotNone(span.ts)
        self.assertIsNotNone(span.d)

        server_timing_value = "intid;desc=%s" % span.t
        assert result['headers']['Server-Timing'] == server_timing_value

        self.assertEqual({'hl': True, 'cp': 'aws', 'e': 'arn:aws:lambda:us-east-2:12345:function:TestPython:1'},
                         span.f)

        self.assertTrue(span.sy)

        self.assertIsNone(span.ec)
        self.assertIsNone(span.data['lambda']['error'])

        self.assertEqual('arn:aws:lambda:us-east-2:12345:function:TestPython:1', span.data['lambda']['arn'])
        self.assertEqual(None, span.data['lambda']['alias'])
        self.assertEqual('python', span.data['lambda']['runtime'])
        self.assertEqual('TestPython', span.data['lambda']['functionName'])
        self.assertEqual('1', span.data['lambda']['functionVersion'])
        self.assertIsNone(span.data['service'])

        self.assertEqual('aws:api.gateway', span.data['lambda']['trigger'])
        self.assertEqual('POST', span.data['http']['method'])
        self.assertEqual('/path/to/resource', span.data['http']['url'])
        if sys.version[:3] == '2.7':
            self.assertEqual(u"foo=[u'bar']", span.data['http']['params'])
        else:
            self.assertEqual("foo=['bar']", span.data['http']['params'])
Esempio n. 2
0
    def test_sqs_trigger_tracing(self):
        with open(self.pwd + '/../data/lambda/sqs_event.json', 'r') as json_file:
            event = json.load(json_file)

        self.create_agent_and_setup_tracer()

        # Call the Instana Lambda Handler as we do in the real world.  It will initiate tracing and then
        # figure out the original (the users') Lambda Handler and execute it.
        # The original Lambda handler is set in os.environ["LAMBDA_HANDLER"]
        result = lambda_handler(event, self.context)

        assert isinstance(result, dict)
        assert 'headers' in result
        assert 'Server-Timing' in result['headers']

        payload = self.agent.collector.prepare_payload()

        self.assertTrue("metrics" in payload)
        self.assertTrue("spans" in payload)
        self.assertEqual(2, len(payload.keys()))

        self.assertTrue(isinstance(payload['metrics']['plugins'], list))
        self.assertTrue(len(payload['metrics']['plugins']) == 1)
        plugin_data = payload['metrics']['plugins'][0]

        self.assertEqual('com.instana.plugin.aws.lambda', plugin_data['name'])
        self.assertEqual('arn:aws:lambda:us-east-2:12345:function:TestPython:1', plugin_data['entityId'])

        self.assertEqual(1, len(payload['spans']))

        span = payload['spans'][0]
        self.assertEqual('aws.lambda.entry', span.n)
        self.assertIsNotNone(span.t)
        self.assertIsNotNone(span.s)
        self.assertIsNone(span.p)
        self.assertIsNotNone(span.ts)
        self.assertIsNotNone(span.d)

        server_timing_value = "intid;desc=%s" % span.t
        assert result['headers']['Server-Timing'] == server_timing_value

        self.assertEqual({'hl': True, 'cp': 'aws', 'e': 'arn:aws:lambda:us-east-2:12345:function:TestPython:1'},
                         span.f)

        self.assertIsNone(span.sy)

        self.assertIsNone(span.ec)
        self.assertIsNone(span.data['lambda']['error'])

        self.assertEqual('arn:aws:lambda:us-east-2:12345:function:TestPython:1', span.data['lambda']['arn'])
        self.assertEqual(None, span.data['lambda']['alias'])
        self.assertEqual('python', span.data['lambda']['runtime'])
        self.assertEqual('TestPython', span.data['lambda']['functionName'])
        self.assertEqual('1', span.data['lambda']['functionVersion'])
        self.assertIsNone(span.data['service'])

        self.assertEqual('aws:sqs', span.data['lambda']['trigger'])
        self.assertTrue(isinstance(span.data["lambda"]["sqs"]["messages"], list))
        messages = span.data["lambda"]["sqs"]["messages"]
        self.assertEqual(1, len(messages))
        message = messages[0]
        self.assertEqual('arn:aws:sqs:us-west-1:123456789012:MyQueue', message['queue'])
Esempio n. 3
0
    def test_cloudwatch_logs_trigger_tracing(self):
        with open(self.pwd + '/../data/lambda/cloudwatch_logs_event.json',
                  'r') as json_file:
            event = json.load(json_file)

        self.create_agent_and_setup_tracer()

        # Call the Instana Lambda Handler as we do in the real world.  It will initiate tracing and then
        # figure out the original (the users') Lambda Handler and execute it.
        # The original Lambda handler is set in os.environ["LAMBDA_HANDLER"]
        result = lambda_handler(event, self.context)

        assert isinstance(result, dict)
        assert 'headers' in result
        assert 'Server-Timing' in result['headers']

        time.sleep(1)
        payload = self.agent.collector.prepare_payload()

        self.assertTrue("metrics" in payload)
        self.assertTrue("spans" in payload)
        self.assertEqual(2, len(payload.keys()))

        self.assertTrue(isinstance(payload['metrics']['plugins'], list))
        self.assertTrue(len(payload['metrics']['plugins']) == 1)
        plugin_data = payload['metrics']['plugins'][0]

        self.assertEqual('com.instana.plugin.aws.lambda', plugin_data['name'])
        self.assertEqual(
            'arn:aws:lambda:us-east-2:12345:function:TestPython:1',
            plugin_data['entityId'])

        self.assertEqual(1, len(payload['spans']))

        span = payload['spans'][0]
        self.assertEqual('aws.lambda.entry', span.n)
        self.assertIsNotNone(span.t)
        self.assertIsNotNone(span.s)
        self.assertIsNone(span.p)
        self.assertIsNotNone(span.ts)
        self.assertIsNotNone(span.d)

        server_timing_value = "intid;desc=%s" % span.t
        assert result['headers']['Server-Timing'] == server_timing_value

        self.assertEqual(
            {
                'hl': True,
                'cp': 'aws',
                'e': 'arn:aws:lambda:us-east-2:12345:function:TestPython:1'
            }, span.f)

        self.assertIsNone(span.sy)

        self.assertIsNone(span.ec)
        self.assertIsNone(span.data['lambda']['error'])

        self.assertEqual(
            'arn:aws:lambda:us-east-2:12345:function:TestPython:1',
            span.data['lambda']['arn'])
        self.assertEqual(None, span.data['lambda']['alias'])
        self.assertEqual('python', span.data['lambda']['runtime'])
        self.assertEqual('TestPython', span.data['lambda']['functionName'])
        self.assertEqual('1', span.data['lambda']['functionVersion'])
        self.assertIsNone(span.data['service'])

        self.assertEqual('aws:cloudwatch.logs', span.data['lambda']['trigger'])
        self.assertFalse("decodingError" in span.data['lambda']['cw']['logs'])
        self.assertEqual('testLogGroup',
                         span.data['lambda']['cw']['logs']['group'])
        self.assertEqual('testLogStream',
                         span.data['lambda']['cw']['logs']['stream'])
        self.assertEqual(None, span.data['lambda']['cw']['logs']['more'])
        self.assertTrue(
            isinstance(span.data['lambda']['cw']['logs']['events'], list))
        self.assertEqual(2, len(span.data['lambda']['cw']['logs']['events']))
        self.assertEqual('[ERROR] First test message',
                         span.data['lambda']['cw']['logs']['events'][0])
        self.assertEqual('[ERROR] Second test message',
                         span.data['lambda']['cw']['logs']['events'][1])