Exporter - Logging Exporter

Export the spans data to python logging.

class opencensus.trace.logging_exporter.LoggingExporter(handler=None, transport=<class 'opencensus.common.transports.sync.SyncTransport'>)[source]

Bases: opencensus.trace.base_exporter.Exporter

A exporter to export the spans data to python logging. Also can use handlers like CloudLoggingHandler to log to Stackdriver Logging API.

Parameters
  • handler (logging.handler) -- the handler to attach to the global handler

  • transport (type) -- Class for creating new transport objects. It should extend from the base_exporter Transport type and implement Transport.export(). Defaults to SyncTransport. The other option is AsyncTransport.

Example:

import google.cloud.logging
from google.cloud.logging.handlers import CloudLoggingHandler
from opencensus.trace import logging_exporter

client = google.cloud.logging.Client()
cloud_handler = CloudLoggingHandler(client)
exporter = logging_exporter.LoggingExporter(handler=cloud_handler)

exporter.export(your_spans_list)

Or initialize a context tracer with the logging exporter, then the traces will be exported to logging when finished.

emit(span_datas)[source]
Parameters

of opencensus.trace.span_data.SpanData span_datas (list) -- SpanData tuples to emit

export(span_datas)[source]
Parameters

of opencensus.trace.span_data.SpanData span_datas (list) -- SpanData tuples to export