/opencensus-python

A stats collection and distributed tracing framework

Primary LanguagePythonApache License 2.0Apache-2.0

OpenCensus - A stats collection and distributed tracing framework

gitter circleci pypi compat_check_pypi compat_check_github

OpenCensus for Python. OpenCensus provides a framework to measure a server's resource usage and collect performance stats. This repository contains Python related utilities and supporting software needed by OpenCensus.

Tracing

Installation & basic usage

  1. Install the opencensus package using pip or pipenv:

    pip install opencensus
    pipenv install opencensus
  2. Initialize a tracer for your application:

  3. Initialize a view_manager and a stats_recorder for your application:

Usage

You can collect traces using the Tracer context manager:

OpenCensus will collect everything within the with statement as a single span.

Alternatively, you can explicitly start and end a span:

Customization

There are several things you can customize in OpenCensus:

  • Blacklist, which excludes certain hosts and paths from being tracked. By default, the health check path for the App Engine flexible environment is not tracked, you can turn it on by excluding it from the blacklist setting.
  • Exporter, which sends the traces. By default, the traces are printed to stdout in JSON format. You can choose different exporters to send the traces to. There are three built-in exporters, which are PrintExporter, FileExporter and LoggingExporter, the other exporters are provided as extensions.
  • Sampler, which determines how traces are sampled. The default sampler is the ProbabilitySampler, which samples (i.e. enables tracing for) a percentage of all requests. Sampling is deterministic according to the trace ID. To force sampling for all requests, or to prevent any request from being sampled, see AlwaysOnSampler and AlwaysOffSampler.
  • Propagator, which serializes and deserializes the SpanContext and its headers. The default propagator is TraceContextPropagator, other propagators include BinaryFormatPropagator, GoogleCloudFormatPropagator and TextFormatPropagator.

You can customize while initializing a tracer.

You can use a configuration file for Flask/Django/Pyramid. For more information, please read the individual integration documentation.

Extensions

Integration

OpenCensus supports integration with popular web frameworks, client libraries and built-in libraries.

Log Exporter

Metrics Exporter

Stats Exporter

Trace Exporter

Versioning

This library follows Semantic Versioning.

GA: Libraries defined at a GA quality level are stable, and will not introduce backwards-incompatible changes in any minor or patch releases. We will address issues and requests with the highest priority. If we were to make a backwards-incompatible changes on an API, we will first mark the existing API as deprecated and keep it for 18 months before removing it.

Beta: Libraries defined at a Beta quality level are expected to be mostly stable and we're working towards their release candidate. We will address issues and requests with a higher priority. There may be backwards incompatible changes in a minor version release, though not in a patch release. If an element is part of an API that is only meant to be used by exporters or other opencensus libraries, then there is no deprecation period. Otherwise, we will deprecate it for 18 months before removing it, if possible.