def test_header_type_error(self):
        header = 1234

        propagator = jaeger_format.JaegerFormatPropagator()

        with self.assertRaises(TypeError):
            propagator.from_header(header)
    def test_from_headers_empty(self):
        from opencensus.trace.span_context import SpanContext

        propagator = jaeger_format.JaegerFormatPropagator()
        span_context = propagator.from_headers({})

        assert isinstance(span_context, SpanContext)
    def test_header_not_match(self):
        header = 'invalid_trace_id:66666::1'
        trace_id = 'invalid_trace_id'

        propagator = jaeger_format.JaegerFormatPropagator()
        span_context = propagator.from_header(header)

        self.assertNotEqual(span_context.trace_id, trace_id)
    def test_headers_match(self):
        # Trace option is enabled.
        headers = {
            'Uber-Trace-Id':
            '6e0c63257de34c92bf9efcd03927272e:00f067aa0ba902b7::01',
        }
        expected_trace_id = '6e0c63257de34c92bf9efcd03927272e'
        expected_span_id = '00f067aa0ba902b7'

        propagator = jaeger_format.JaegerFormatPropagator()
        span_context = propagator.from_headers(headers)

        self.assertEqual(span_context.trace_id, expected_trace_id)
        self.assertEqual(span_context.span_id, expected_span_id)
        self.assertTrue(span_context.trace_options.enabled)
    def test_to_header(self):
        from opencensus.trace import span_context
        from opencensus.trace import trace_options

        trace_id = '6e0c63257de34c92bf9efcd03927272e'
        span_id = '00f067aa0ba902b7'
        span_context = span_context.SpanContext(
            trace_id=trace_id,
            span_id=span_id,
            trace_options=trace_options.TraceOptions('1'))

        propagator = jaeger_format.JaegerFormatPropagator()

        header = propagator.to_header(span_context)
        expected_header = '{}:{}::{:02x}'.format(trace_id, span_id, 1)

        self.assertEqual(header, expected_header)
Exemplo n.º 6
0
from qubit.opencensus.trace import asyncio_context
from qubit.opencensus.trace.exporters import jaeger_exporter
from qubit.opencensus.trace.ext.aiohttp.trace import trace_integration as aiohttp_integration
from qubit.opencensus.trace.ext.aioredis.trace import trace_integration as aioredis_integration
from qubit.opencensus.trace.ext.sanic.sanic_middleware import SanicMiddleware
from qubit.opencensus.trace.propagation import jaeger_format
from qubit.opencensus.trace.samplers import probability
from qubit.opencensus.trace.tracers import asyncio_context_tracer

import asyncio
import aiotask_context as context
import aiohttp
import aioredis

sampler = probability.ProbabilitySampler(rate=0.9)
propagator = jaeger_format.JaegerFormatPropagator()
exporter = jaeger_exporter.JaegerExporter(service_name="recs")

aiohttp_integration(propagator=propagator)
aioredis_integration(tracer=None)

app = Sanic()
middleware = SanicMiddleware(app,
                             sampler=sampler,
                             exporter=exporter,
                             propagator=propagator)


@app.listener('before_server_start')
async def init_host(_app, loop):
    _app.conn = await aioredis.create_connection('redis://localhost',