Пример #1
0
    def test_emit(self):
        exporter = logging_exporter.LoggingExporter()
        logger = mock.Mock()
        exporter.logger = logger

        span_datas = [
            span_data_module.SpanData(
                name='span',
                context=span_context.SpanContext(trace_id='1'),
                span_id='1111',
                parent_span_id=None,
                attributes=None,
                start_time=None,
                end_time=None,
                child_span_count=None,
                stack_trace=None,
                annotations=None,
                message_events=None,
                links=None,
                status=None,
                same_process_as_parent_span=None,
                span_kind=0,
            )
        ]
        exporter.emit(span_datas)

        logger.info.assert_called_once_with(
            span_data_module.format_legacy_trace_json(span_datas))
Пример #2
0
def initialize_tracer(request: 'flask.Request') -> tracer.Tracer:
    if TRACE_PROPAGATE == "google":
        propagator = google_cloud_format.GoogleCloudFormatPropagator()
    else:
        propagator = trace_context_http_header_format.TraceContextPropagator()
    if TRACE_EXPORTER == "stackdriver":
        exporter = trace_exporter.StackdriverExporter(transport=AsyncTransport)
        sampler = samplers.AlwaysOnSampler()
    elif TRACE_EXPORTER == "log":
        exporter = logging_exporter.LoggingExporter(
            handler=py_logging.NullHandler(), transport=AsyncTransport)
        sampler = samplers.AlwaysOnSampler()
    elif TRACE_EXPORTER == "stdout":
        exporter = print_exporter.PrintExporter(transport=AsyncTransport)
        sampler = samplers.AlwaysOnSampler()
    else:
        exporter = print_exporter.PrintExporter(transport=AsyncTransport)
        sampler = samplers.AlwaysOffSampler()
    span_context = propagator.from_headers(request.headers)
    return tracer.Tracer(exporter=exporter,
                         sampler=sampler,
                         propagator=propagator,
                         span_context=span_context)
Пример #3
0
    def test_export(self):
        exporter = logging_exporter.LoggingExporter(transport=MockTransport)
        exporter.export({})

        self.assertTrue(exporter.transport.export_called)
Пример #4
0
    def test_constructor_explicit(self):
        handler = _Handler(logging.INFO)
        exporter = logging_exporter.LoggingExporter(handler=handler)

        self.assertIn(exporter.handler, logging.getLogger().handlers)
Пример #5
0
    def test_constructor_default(self):
        exporter = logging_exporter.LoggingExporter()

        self.assertIn(exporter.handler, logging.getLogger().handlers)
        assert isinstance(exporter.handler, logging.StreamHandler)