Exemplo n.º 1
0
    def test_tracer_none(self, tracer):
        tracing = tornado_opentracing.TornadoTracing()
        self.assertEqual(tracing.tracer, opentracing.tracer)

        opentracing.tracer = mock.MagicMock()
        self.assertEqual(tracing.tracer, opentracing.tracer)
Exemplo n.º 2
0
 def test_start_span_cb_invalid(self):
     with self.assertRaises(ValueError):
         tornado_opentracing.TornadoTracing(start_span_cb=[])
Exemplo n.º 3
0
 def test_tracer(self):
     tracer = MockTracer()
     tracing = tornado_opentracing.TornadoTracing(tracer)
     self.assertEqual(tracing.tracer, tracer)
Exemplo n.º 4
0
# Your OpenTracing-compatible tracer here.
tracer = opentracing.Tracer(scope_manager=TornadoScopeManager())


class MainHandler(RequestHandler):
    def get(self):
        self.write({'status': 'ok'})


class StoryHandler(RequestHandler):

    @gen.coroutine
    def get(self, story_id):
        if int(story_id) == 0:
            raise ValueError('invalid value passed')

        tracer.active_span.set_tag('processed', True)
        self.write({'status': 'fetched'})


app = Application([
        (r'/', MainHandler),
        (r'/story/([0-9]+)', StoryHandler),
    ],
    opentracing_tracing=tornado_opentracing.TornadoTracing(tracer),
    opentracing_trace_all=True,
    opentracing_traced_attributes=['protocol', 'method'],
)
app.listen(8080)
IOLoop.current().start()
Exemplo n.º 5
0
import sys

import tornado_opentracing
from opentracing.mocktracer import MockTracer
from tornado_opentracing.scope_managers import ScopeManager


if sys.version_info >= (3, 3):
    from ._test_case_gen import AsyncHTTPTestCase  # noqa
else:
    from ._test_case import AsyncHTTPTestCase  # noqa


tracing = tornado_opentracing.TornadoTracing(MockTracer(ScopeManager()))
Exemplo n.º 6
0
from tornado.web import Application, RequestHandler
from tornado import gen

import opentracing
import tornado_opentracing
from tornado_opentracing.scope_managers import TornadoScopeManager


def client_start_span_cb(span, request):
    span.operation_name = 'client/%s' % request.method
    span.set_tag('headers', request.headers)


# Pass your OpenTracing-compatible tracer here
# using TornadoScopeManager.
tracing = tornado_opentracing.TornadoTracing(opentracing.tracer)

# Since we are not doing a full tornado_opentracing.init_tracing(),
# we need to manually call init_client_tracing() if we want to do
# HTTP client tracing too.
tornado_opentracing.init_client_tracing(opentracing.tracer,
                                        start_span_cb=client_start_span_cb)


class ClientLogHandler(RequestHandler):
    @tracing.trace()
    @gen.coroutine
    def get(self):
        yield AsyncHTTPClient().fetch('http://127.0.0.1:8080/server/log')
        self.write({'message': 'Sent a request to log'})
Exemplo n.º 7
0
 def test_tracer_none(self):
     tracing = tornado_opentracing.TornadoTracing()
     self.assertEqual(tracing.tracer, opentracing.tracer)