Пример #1
0
    def test_get_trace_ids_sqs_attributes(self):
        ''' ensure that we extract SQS data from message attributes'''
        event = {
            "Records": [
                {
                    "body": "Hello from SQS!",
                    "messageAttributes": {
                        'X-HoNEyComb-TrACE': {
                            "Type":
                            "String",
                            "stringValue":
                            "1;trace_id=bloop,parent_id=scoop,context=e30K",
                        },
                        'foo': {
                            "Type": "String",
                            "stringValue": "bar",
                        },
                    },
                    "eventSource": "aws:sqs",
                },
            ],
        }

        trace_id, parent_id, context = awslambda._get_trace_data(event)
        self.assertEqual(trace_id, 'bloop')
        self.assertEqual(parent_id, 'scoop')
        self.assertEqual(context, {})
Пример #2
0
    def test_get_trace_ids_no_header(self):
        ''' ensure that we handle events with no header key '''
        event = {
            'foo': 1,
        }

        trace_id, parent_id, context = awslambda._get_trace_data(event)
        self.assertIsNone(trace_id)
        self.assertIsNone(parent_id)
        self.assertIsNone(context)
Пример #3
0
    def test_get_trace_ids_from_header(self):
        ''' test that trace_id and parent_id are extracted regardless of case '''
        event = {
            'headers': {
                # case shouldn't matter
                'X-HoNEyComb-TrACE':
                '1;trace_id=bloop,parent_id=scoop,context=e30K',
            },
        }

        trace_id, parent_id, context = awslambda._get_trace_data(event)
        self.assertEqual(trace_id, 'bloop')
        self.assertEqual(parent_id, 'scoop')
        self.assertEqual(context, {})
Пример #4
0
    def test_get_trace_ids_sqs_none(self):
        ''' ensure that we handle SQS events with no honeycomb key '''
        event = {
            "Records": [
                {
                    "body": "Hello from SQS!",
                    "messageAttributes": {},
                    "eventSource": "aws:sqs",
                },
            ],
        }

        trace_id, parent_id, context = awslambda._get_trace_data(event)
        self.assertIsNone(trace_id)
        self.assertIsNone(parent_id)
        self.assertIsNone(context)
Пример #5
0
    def test_get_trace_ids_sns_none(self):
        ''' ensure that we handle SNS events with no honeycomb key '''
        event = {
            "Records": [{
                "EventSource": "aws:sns",
                "Sns": {
                    "Message": "Hello from SNS!",
                    "MessageAttributes": {}
                }
            }],
        }

        trace_id, parent_id, context = awslambda._get_trace_data(event)
        self.assertIsNone(trace_id)
        self.assertIsNone(parent_id)
        self.assertIsNone(context)
Пример #6
0
    def test_message_batch_is_ignored(self):
        ''' ensure that we don't process batches'''
        event = {
            "Records": [
                {
                    "body": "Hello from SQS!",
                    "messageAttributes": {
                        'X-HoNEyComb-TrACE': {
                            "Type":
                            "String",
                            "stringValue":
                            "1;trace_id=beep,parent_id=moop,context=e29K",
                        },
                        'foo': {
                            "Type": "String",
                            "stringValue": "bar",
                        },
                    },
                    "eventSource": "aws:sqs",
                },
                {
                    "body": "Another hello from SQS!",
                    "messageAttributes": {
                        'X-HoNEyComb-TrACE': {
                            "Type":
                            "String",
                            "stringValue":
                            "1;trace_id=bloop,parent_id=scoop,context=e30K",
                        },
                        'foo': {
                            "Type": "String",
                            "stringValue": "baz",
                        },
                    },
                    "eventSource": "aws:sqs",
                },
            ],
        }

        trace_id, parent_id, context = awslambda._get_trace_data(event)
        self.assertIsNone(trace_id)
        self.assertIsNone(parent_id)
        self.assertIsNone(context)
Пример #7
0
    def test_get_trace_ids_sns_attribute(self):
        ''' ensure that we extract SNS data from message attributes'''
        event = {
            "Records": [{
                "EventSource": "aws:sns",
                "Sns": {
                    "Message": "Hello from SNS!",
                    "MessageAttributes": {
                        'X-HoNEyComb-TrACE': {
                            "Type":
                            "String",
                            "Value":
                            "1;trace_id=bloop,parent_id=scoop,context=e30K",
                        }
                    }
                }
            }],
        }

        trace_id, parent_id, context = awslambda._get_trace_data(event)
        self.assertEqual(trace_id, 'bloop')
        self.assertEqual(parent_id, 'scoop')
        self.assertEqual(context, {})