Exemple #1
0
    def test_double_instrumentation(self):
        import tests.resources

        self.assertFalse(
            hasattr(tests.resources.regular_function, '_logsense_patched'))
        regular_function = patch_single('tests.resources.regular_function')
        regular_function_2 = patch_single('tests.resources.regular_function')
        self.assertEqual(regular_function, regular_function_2)
Exemple #2
0
    def test_class_method(self):
        patch_single('tests.resources.RegularClass.class_method', arguments=ALL_ARGS)

        obj = resources.RegularClass()
        obj.class_method('a', 'b')
        self.sender.wait_on_data()

        data = [record.data for record in self.sender.get_data()]

        self.assertEqual(data[0]['ot.operation_name'], 'tests.resources.class_method')
        self.assertEqual(data[0].get('ot.kwarg.foo'), 'a')
        self.assertEqual(data[0].get('ot.kwarg.bar'), 'b')
        self.assertEqual(data[0].get('ot.kwarg.cls'), str(obj))

        self.assertEqual(data[1]['message'], 'Here is a and b for RegularClass')
Exemple #3
0
    def test_adding_attr(self):
        import tests.resources

        self.assertFalse(
            hasattr(tests.resources.regular_function, '_logsense_patched'))
        regular_function = patch_single('tests.resources.regular_function')
        self.assertTrue(hasattr(regular_function, '_logsense_patched'))
Exemple #4
0
    def test_function_all_arguments(self):
        regular_function = patch_single('tests.resources.regular_function',
                                        arguments=ALL_ARGS)

        regular_function('a', 'b')
        self.sender.wait_on_data()

        data = [record.data for record in self.sender.get_data()]

        self.assertEqual(data[0].get('ot.kwarg.foo'), 'a')
        self.assertEqual(data[0].get('ot.kwarg.bar'), 'b')
        self.assertEqual(data[1]['message'], 'This is a b')
Exemple #5
0
    def test_function(self):
        regular_function = patch_single('tests.resources.regular_function')

        regular_function('a', 'b')
        self.sender.wait_on_data()

        data = [record.data for record in self.sender.get_data()]

        self.assertEqual(data[0]['ot.operation_name'],
                         'tests.resources.regular_function')
        self.assertEqual(data[0]['_type'], 'trace')
        self.assertIsNone(data[0].get('ot.kwarg.foo'))
        self.assertIsNone(data[0].get('ot.kwarg.bar'))

        self.assertEqual(data[1]['message'], 'This is a b')
Exemple #6
0
import tornado.web

from logsense_opentracing.utils import setup_tracer
from logsense_opentracing.instrumentation import patch_single, tornado_route


# Initialize tracer
setup_tracer(component='tornado server')


class MainHandler(tornado.web.RequestHandler):  # pylint: disable=missing-docstring, abstract-method

    def get(self):
        """
        Just log and send welcome message
        """
        logging.info('Hello, world')
        self.write('Hello, world')


# Patch handler
patch_single('__main__.MainHandler.get', before=tornado_route)


if __name__ == "__main__":
    app = tornado.web.Application([  # pylint: disable=invalid-name
        (r"/", MainHandler),
    ])
    app.listen(8889)
    tornado.ioloop.IOLoop.current().start()
Exemple #7
0
"""
Run `nc -lp 8888` in linux console to see which headers was send exactly
"""
import logging
import requests
import tornado.ioloop
import tornado.web
import opentracing

from logsense_opentracing.utils import setup_tracer
from logsense_opentracing.instrumentation import patch_single, tornado_route, requests_baggage, patch_module

# Initialize tracer
setup_tracer(component='Requests')
patch_single('requests.api.request', before=requests_baggage)

with opentracing.tracer.start_active_span('parent-span') as scope:
    scope.span.set_baggage_item('suitcase',
                                'My docs with important information')
    requests.get('http://localhost:8888/',
                 headers={'my-header': 'I\'m using opentracing'})
import tornado.web

from logsense_opentracing.utils import setup_tracer
from logsense_opentracing.instrumentation import patch_single, tornado_route, requests_baggage, patch_module

# Initialize tracer
setup_tracer(component='Main server')


class MainHandler(tornado.web.RequestHandler):

    def get(self):
        logging.info('Inside main server')
        self.write("Hello, world")
        requests.get('http://localhost:8889/')


patch_single('__main__.MainHandler.get', before=tornado_route)
patch_single('requests.api.request', before=requests_baggage)
patch_module('requests.models.PreparedRequest', recursive=True)

def make_app():
    return tornado.web.Application([
        (r"/", MainHandler)
    ])

if __name__ == "__main__":
    app = make_app()

    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()