Description
OpenCensus - A stats collection and distributed tracing framework ================================================================= |gitter| |travisci| |circleci| |pypi| |compat_check_pypi| |compat_check_github| .. |travisci| image:: https://travis-ci.org/census-instrumentation/opencensus-python.svg?branch=master :target: https://travis-ci.org/census-instrumentation/opencensus-python .. |circleci| image:: https://circleci.com/gh/census-instrumentation/opencensus-python.svg?style=shield :target: https://circleci.com/gh/census-instrumentation/opencensus-python .. |gitter| image:: https://badges.gitter.im/census-instrumentation/lobby.svg :target: https://gitter.im/census-instrumentation/lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge .. |pypi| image:: https://badge.fury.io/py/opencensus.svg :target: https://pypi.org/project/opencensus/ .. |compat_check_pypi| image:: https://python-compatibility-tools.appspot.com/one_badge_image?package=opencensus :target: https://python-compatibility-tools.appspot.com/one_badge_target?package=opencensus .. |compat_check_github| image:: https://python-compatibility-tools.appspot.com/one_badge_image?package=git%2Bgit%3A//github.com/census-instrumentation/opencensus-python.git :target: https://python-compatibility-tools.appspot.com/one_badge_target?package=git%2Bgit%3A//github.com/census-instrumentation/opencensus-python.git `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. .. _OpenCensus: https://github.com/census-instrumentation - `API Documentation`_ .. _API Documentation: https://opencensus.io/api/python/trace/usage.html -------- 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: .. code:: python from opencensus.trace.tracer import Tracer from opencensus.trace.samplers import AlwaysOnSampler tracer = Tracer(sampler=AlwaysOnSampler()) .. _pip: https://pip.pypa.io .. _pipenv: https://docs.pipenv.org/ 3. Initialize a view_manager and a stats_recorder for your application: .. code:: python from opencensus.stats import stats as stats_module stats = stats_module.stats view_manager = stats.view_manager stats_recorder = stats.stats_recorder Usage ----- You can collect traces using the ``Tracer`` `context manager`_: .. code:: python from opencensus.trace.tracer import Tracer from opencensus.trace.samplers import AlwaysOnSampler # Initialize a tracer, by default using the `PrintExporter` tracer = Tracer(sampler=AlwaysOnSampler()) # Example for creating nested spans with tracer.span(name='span1'): do_something_to_trace() with tracer.span(name='span1_child1'): do_something_to_trace() with tracer.span(name='span1_child2'): do_something_to_trace() with tracer.span(name='span2'): do_something_to_trace() OpenCensus will collect everything within the ``with`` statement as a single span. Alternatively, you can explicitly start and end a span: .. code:: python from opencensus.trace.tracer import Tracer from opencensus.trace.samplers import AlwaysOnSampler # Initialize a tracer, by default using the `PrintExporter` tracer = Tracer(sampler=AlwaysOnSampler()) tracer.start_span(name='span1') do_something_to_trace() tracer.end_span() .. _context manager: https://docs.python.org/3/reference/datamodel.html#context-managers Customization ------------- There are several things you can customize in OpenCensus: * **Excludelist**, 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 excludelist 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 <#trace-exporter>`__. * **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 ``Tr
Release History
| Version | Changes | Urgency | Date |
|---|---|---|---|
| 0.11.4 | Imported from PyPI (0.11.4) | Low | 4/21/2026 |
| opencensus-ext-azure@1.1.15 | Switch ordering for Statsbeat Attach detection to prioritize Azure Functions ([#1251](https://github.com/census-instrumentation/opencensus-python/pull/1251)) | Low | 6/3/2025 |
| v0.11.4-1.1.14 | - Remove status code `206` from retry code + only count batch level for statsbeat ([#1247](https://github.com/census-instrumentation/opencensus-python/pull/1247)) | Low | 1/6/2025 |
| v0.11.4-1.1.13 | - Changed bit-mapping for `httpx` and `fastapi` integrations ([#1239](https://github.com/census-instrumentation/opencensus-python/pull/1239)) | Low | 1/3/2024 |
| v0.11.3-1.1.12 | - Updated `azure` modules ## opencensus-ext-azure 1.1.12 - Fix missing/None fields in `ExceptionDetails` ([#1232](https://github.com/census-instrumentation/opencensus-python/pull/1232)) - Fix missing/None typeName field in `ExceptionDetails` ([#1234](https://github.com/census-instrumentation/opencensus-python/pull/1234)) | Low | 11/28/2023 |
| v0.11.3 | - Updated `azure` modules ## opencensus-ext-azure 1.1.11 - Add str fallback to envelope serialization ([#1196](https://github.com/census-instrumentation/opencensus-python/pull/1196)) - Remove outerId from exceptiondata ([#1221](https://github.com/census-instrumentation/opencensus-python/pull/1221)) ## opencensus-ext-azure 1.1.10 - Various bug fixes | Low | 10/12/2023 |
| v0.11.2 | - Updated `azure`, `fastapi`, `flask` modules - ## opencensus-ext-azure 1.1.9 - Fix export of exception information in traces ([#1187](https://github.com/census-instrumentation/opencensus-python/pull/1187)) - Modify metrics exporter to include setting export interval to 60s ([#1193](https://github.com/census-instrumentation/opencensus-python/pull/1193)) ## opencensus-ext-fastapi 0.1.0 - Initial version ([#1124](https://github.com/census-instrumentation/opencensus-python/pull/1124 | Low | 3/10/2023 |
| v0.11.1 | - Updated `azure` and `httpx` modules ## opencensus-ext-azure 1.1.8 - Disable storage for statsbeat if storage is disabled for exporter ([#1155](https://github.com/census-instrumentation/opencensus-python/pull/1155)) - Add UK to eu statsbeats ([#1181](https://github.com/census-instrumentation/opencensus-python/pull/1181)) ## opencensus-ext-httpx 0.1.0 - Initial release ([#1098](https://github.com/census-instrumentation/opencensus-python/pull/1098)) | Low | 1/19/2023 |
| opencensus-ext-django@0.8.0 | - Fixed support for Django 4.1 ([#1159](https://github.com/census-instrumentation/opencensus-python/pull/1159)) | Low | 10/17/2022 |
| opencensus-ext-azure@1.1.7 | - Add storage existence checks to storing and transmitting in exporter ([#1150](https://github.com/census-instrumentation/opencensus-python/pull/1150)) - Add 502 and 504 status codes as retriable ([#1153](https://github.com/census-instrumentation/opencensus-python/pull/1153)) - Fix statsbeat bug - exporting zero values for network statsbeat ([#1155](https://github.com/census-instrumentation/opencensus-python/pull/1155)) | Low | 8/18/2022 |
| v0.11.0 | - Updated `azure`, `context`, `flask`, `requests` modules ## opencensus-context 0.1.3 - Move `version.py` file into `runtime_context` folder ([#1143](https://github.com/census-instrumentation/opencensus-python/pull/1143)) ## opencensus-ext-azure 1.1.6 - Add statusCode and exceptionType to network statsbeat ([#1138](https://github.com/census-instrumentation/opencensus-python/pull/1138)) ## opencensus-ext-flask 0.8.1 - Move `version.py` file into `common` folder ([#1143](https:/ | Low | 8/3/2022 |
| v0.10.0 | - Add kwargs to derived gauge ([#1135](https://github.com/census-instrumentation/opencensus-python/pull/1135)) ## opencensus-ext-azure 1.1.5 - Allow specifying metrics (custom_measurements) for Azure custom events ([#1117](https://github.com/census-instrumentation/opencensus-python/pull/1117)) - Shutdown Statsbeat when hitting error/exception threshold ([#1127](https://github.com/census-instrumentation/opencensus-python/pull/1127)) - Fix failure counting statsbeat - refactor status co | Low | 7/5/2022 |
| v0.9.0 | - Make sure handler.flush() doesn't deadlock. ([#1112](https://github.com/census-instrumentation/opencensus-python/pull/1112)) ## opencensus-ext-azure 1.1.4 - Statsbeat bug fixes - status codes ([#1113](https://github.com/census-instrumentation/opencensus-python/pull/1113)) - Statsbeat bug fixes - do not log if statsbeat ([#1116](https://github.com/census-instrumentation/opencensus-python/pull/1116)) - Add deprecation warning for explicitly using instrumentation key ([#1118](https:/ | Low | 4/20/2022 |
| opencensus-ext-azure@1.1.3 | - Hotfix for version number ([#1108](https://github.com/census-instrumentation/opencensus-python/pull/1108)) | Low | 3/3/2022 |
| opencensus-ext-azure@1.1.2 | ## opencensus-ext-azure 1.1.2 - Statsbeat bug fixes, shorten host in network stats ([#1100](https://github.com/census-instrumentation/opencensus-python/pull/1100)) - Support statsbeat in EU regions ([#1105](https://github.com/census-instrumentation/opencensus-python/pull/1105)) | Low | 3/3/2022 |
| opencensus-ext-azure@1.1.1 | ## opencensus-ext-azure 1.1.1 - Fix statsbeats metric names ([#1089](https://github.com/census-instrumentation/opencensus-python/pull/1089)) - Add AAD statsbeat feature, fix incorrect counting of retry ([#1093](https://github.com/census-instrumentation/opencensus-python/pull/1093)) | Low | 1/19/2022 |
| v0.8.0 | - Added integration tracking functionality, includes `django`, `flask`, `http-lib`, `logging`, `mysql`, `postgresql`, `pymongo`, `pymysql`, `pyramid`, `requests`, `sqlalchemy` modules ([#1065](https://github.com/census-instrumentation/opencensus-python/pull/1065)) - Support Python 3.8, 3.9 ([#1048](https://github.com/census-instrumentation/opencensus-python/pull/1048)) ## opencensus-ext-azure 1.1.0 - Enable AAD authorization via TokenCredential ([#1021](https://github.com/census-instru | Low | 10/5/2021 |
| opencensus-ext-stackdriver@v0.8.0 | This release only contains `opencensus-ext-stackdriver`. Given the inactivity in OpenCensus, we will be releasing packages individually going forward. ## opencensus-ext-stackdriver 0.8.0 - Upgrade google-cloud-monitoring dep to v2.X, update usage [#1060](https://github.com/census-instrumentation/opencensus-python/pull/1060) - Drop python <3.6 in opencensus-ext-stackdriver [#1056](https://github.com/census-instrumentation/opencensus-python/pull/1056) | Low | 8/16/2021 |
| v0.7.13 | ## opencensus-ext-azure 1.0.8 - Fix `logger.exception` with no exception info throwing error ([#1006](https://github.com/census-instrumentation/opencensus-python/pull/1006)) - Add `enable_local_storage` to turn on/off local storage + retry + flushing logic ([#1006](https://github.com/census-instrumentation/opencensus-python/pull/1006)) ## opencensus-ext-django 0.7.5 - Add exception tracing to django middleware ([#885](https://github.com/census-instrumentation/opencensus-python/pull/885 | Low | 5/14/2021 |
| v0.7.12 | ## Breaking changes - Change blacklist to excludelist ([#977](https://github.com/census-instrumentation/opencensus-python/pull/977)) ## opencensus-ext-azure 1.0.7 - Hotfix ([#1004](https://github.com/census-instrumentation/opencensus-python/pull/1004)) ## opencensus-ext-azure 1.0.6 - Disable heartbeat metrics in exporters ([#984](https://github.com/census-instrumentation/opencensus-python/pull/984)) - Loosen instrumentation key validation to GUID ([#984](https://github.com/census-i | Low | 1/15/2021 |
| v0.7.11 | - PeriodicMetricTask flush on exit ([#943](https://github.com/census-instrumentation/opencensus-python/pull/943)) ## opencensus-ext-azure 1.0.5 - Attach rate metrics via Heartbeat for Web and Function apps ([#930](https://github.com/census-instrumentation/opencensus-python/pull/930)) - Attach rate metrics for VM ([#935](https://github.com/census-instrumentation/opencensus-python/pull/935)) - Add links in properties for trace exporter envelopes ([#936](https://github.com/census-instrument | Low | 10/13/2020 |
| v0.7.10 | ## opencensus-ext-azure 1.0.4 - Remove dependency rate from standard metrics ([#903](https://github.com/census-instrumentation/opencensus-python/pull/903)) - Implement customEvents using AzureEventHandler ([#925](https://github.com/census-instrumentation/opencensus-python/pull/925)) ## opencensus-ext-context 0.1.2 - Release source distribution ## opencensus-ext-stackdriver 0.7.3 - Add mean property for distribution values ([#919](https://github.com/census-instrumentation/opencens | Low | 6/29/2020 |
| v0.7.9 | - Hotfix ([#915](https://github.com/census-instrumentation/opencensus-python/pull/915)) | Low | 6/18/2020 |
| 0.7.8 | - Updated `azure` module ([#903](https://github.com/census-instrumentation/opencensus-python/pull/903), [#902](https://github.com/census-instrumentation/opencensus-python/pull/902)) ## opencensus-ext-azure 1.0.3 - Change default path of local storage ([#903](https://github.com/census-instrumentation/opencensus-python/pull/903)) - Add support to initialize azure exporters with proxies ([#902](https://github.com/census-instrumentation/opencensus-python/pull/902)) | Low | 6/17/2020 |
| v0.7.7 | - Updated `azure` module ([#837](https://github.com/census-instrumentation/opencensus-python/pull/837), [#845](https://github.com/census-instrumentation/opencensus-python/pull/845), [#848](https://github.com/census-instrumentation/opencensus-python/pull/848), [#851](https://github.com/census-instrumentation/opencensus-python/pull/851)) ## opencensus-ext-azure 1.0.2 - Add local storage and retry logic for Azure Metrics Exporter ([#845](https://github.com/census-instrumentation/opencensus-py | Low | 2/4/2020 |
| v0.7.6 | - Updated `azure` module ([#773](https://github.com/census-instrumentation/opencensus-python/pull/773), [#767](https://github.com/census-instrumentation/opencensus-python/pull/767)) - Released `datadog` module ([#793](https://github.com/census-instrumentation/opencensus-python/pull/793)) ## opencensus-ext-azure 1.0.1 - Validate instrumentation key in Azure Exporters ([#789](https://github.com/census-instrumentation/opencensus-python/pull/789)) - Add optional custom properties to loggin | Low | 11/26/2019 |
| v0.7.5 | - Updated `flask` module ([#781](https://github.com/census-instrumentation/opencensus-python/pull/781)) ## opencensus-ext-flask 0.7.3 - Check that `url_rule` is not `None` before dereferencing property ([#781](https://github.com/census-instrumentation/opencensus-python/pull/781)) | Low | 10/1/2019 |
| v0.7.4 | - Updated `azure` module ([#773](https://github.com/census-instrumentation/opencensus-python/pull/773), [#767](https://github.com/census-instrumentation/opencensus-python/pull/767)) - Updated `django` module ([#775](https://github.com/census-instrumentation/opencensus-python/pull/775)) ## opencensus-ext-azure 1.0.0 - Standard Metrics - Incoming requests execution time ([#773](https://github.com/census-instrumentation/opencensus-python/pull/773)) - Implement connection strings ([#767](h | Low | 10/1/2019 |
| v0.7.3 | - Added `http code` to `grpc code` status code mapping on `utils` ([#746](https://github.com/census-instrumentation/opencensus-python/pull/746)) - Updated `django`, `flask`, `httplib`, `requests` and `pyramid` modules ([#755](https://github.com/census-instrumentation/opencensus-python/pull/755)) - Updated `requests` module ([#771](https://github.com/census-instrumentation/opencensus-python/pull/771)) ## opencensus-ext-azure 0.7.1 - Standard metrics incoming requests per second ([#758](ht | Low | 8/26/2019 |
| v0.7.2 | - Fix GCP resource loading for certain environments ([#761](https://github.com/census-instrumentation/opencensus-python/pull/761)) | Low | 8/16/2019 |
| v0.7.1 | - Added `set_status` to `span` ([#738](https://github.com/census-instrumentation/opencensus-python/pull/738)) - Update released stackdriver exporter version ## opencensus-ext-flask 0.7.1 - Update for core library changes ## opencensus-ext-grpc 0.7.1 - Update for core library changes ## opencensus-ext-httplib 0.7.1 - Support exporter changes in `opencensus>=0.7.0` ## opencensus-ext-jaeger 0.7.1 - Update for core library changes ## opencensus-ext-ocagent 0.7.1 - Up | Low | 8/6/2019 |
| v0.7.0 | - Fix exporting int-valued stats with sum and lastvalue aggregations ([#696](https://github.com/census-instrumentation/opencensus-python/pull/696)) - Fix cloud format propagator to use decimal span_id encoding instead of hex ([#719](https://github.com/census-instrumentation/opencensus-python/pull/719)) ## opencensus-ext-azure 0.7.0 - Added standard metrics ([#708](https://github.com/census-instrumentation/opencensus-python/pull/708), [#718](https://github.com/census-instrumentation/opence | Low | 8/1/2019 |
| v0.6.0 | - Refactored PeriodicTask ([#632](https://github.com/census-instrumentation/opencensus-python/pull/632)) - Make ProbabilitySampler default, change default sampling rate - Pass span context to samplers, allow samplers to override parent sampling decision ## opencensus-context 0.1.1 - Updated docs and examples ## opencensus-ext-azure 0.2.1 - Support span attributes ([#682](https://github.com/census-instrumentation/opencensus-python/pull/682)) ## opencensus-ext-azure 0.2.0 - | Low | 6/1/2019 |
| v0.5.0 | - Add cumulative API ([#626](https://github.com/census-instrumentation/opencensus-python/pull/626)) ## opencensus-ext-django 0.3.0 - Decouple exporter logic from configuration - Prevent anonymous user error on old django versions ([#603](https://github.com/census-instrumentation/opencensus-python/pull/603)) ## opencensus-ext-flask 0.3.0 - Decouple exporter logic from configuration ## opencensus-ext-grpc 0.2.0 - Create WrappedResponseIterator for intercepted bi-directional rpc | Low | 4/24/2019 |
| v0.4.1 | - Allow for metrics with empty label keys and values ([#611](https://github.com/census-instrumentation/opencensus-python/pull/611), [#614](https://github.com/census-instrumentation/opencensus-python/pull/614)) | Low | 4/12/2019 |
| v0.4.0 | - Multiple bugfixes - Use separate context package instead of threadlocals for execution context ([#573](https://github.com/census-instrumentation/opencensus-python/pull/573)) - Release multiple new versions of ext packages | Low | 4/9/2019 |
| v0.3.1 | - Release 0.1.0 versions of exporter and integration packages | Low | 3/19/2019 |
| v0.3.0 | - Fix gRPC client tracer reuse bug ([#539](https://github.com/census-instrumentation/opencensus-python/pull/539)) - Update prometheus client and fix multiple bugs in the exporter ([#492](https://github.com/census-instrumentation/opencensus-python/pull/492)) - Remove min and max from `Distribution` ([#501](https://github.com/census-instrumentation/opencensus-python/pull/501)) - Replace stackdriver `gke_container` resources, see the [GKE migration notes](https://cloud.google.com/monitoring/kube | Low | 3/12/2019 |
| v0.2.0 | - Fix multiple stackdriver and prometheus exporter bugs - Increase size of trace batches and change transport behavior on exit ([#452](https://github.com/census-instrumentation/opencensus-python/pull/452)) | Low | 1/22/2019 |
| v0.1.11 | - Fix a bug in the stackdriver exporter that caused spans to be exported individually ([#425](https://github.com/census-instrumentation/opencensus-python/pull/425)) | Low | 1/17/2019 |
| v0.1.10 | Fix memory leak in stackdriver exporter (#429) | Low | 12/10/2018 |
| v0.1.9 | Release v0.1.9 | Low | 11/28/2018 |
| 0.1.8 | - Auto-populate k8s_container MonitoredResource (#319) - JaegerExporter : handle annotations (#324) - Exporter/Zipkin: Add annotations (#327) - JaegerExporter: Fix incorrect log timestamps (#330) - Refactor code timestampStr to microseconds (#332) - Add Metrics: LabelKey and LabelValue (#336) | Low | 10/8/2018 |
| 0.1.5 | - Attach stack traces and exceptions to Flask traces (#151) - Update gRPC span names to match spec (#152) - Implement Jaeger Trace Exporter (#154) - Allow for Flask `init_app` Pattern (#160) - trace: Span.add_annotation method (#165) - Update the should_sample logic for tracer (#166) - Add streaming support and message events to gRPC interceptors (#169) - Fix bug preventing unicode attributes from being set in python 2.7 (#171) - Support the 0.19 version of google-cloud-trace (#174) - | Low | 5/23/2018 |
| 0.1.4 | - Improve the integration modules to share tracer between threads (#133) - Add SpanData class (#136) - Attach stack traces and status to the current span on gRPC server failures (#140) - Refactor exporters to accept SpanData objects instead of Spans (#144) - Sync examples/trace/grpc proto file with other opencensus projects (#146) - Update span ids to be 16 char hex strings (#147) Big thanks to @wkiser for the contributions! | Low | 4/9/2018 |
| 0.1.2 | - Update StackdriverExporter to use Stackdriver Trace V2 API. - Support gRPC trace integration using grpc interceptors. - Support Google Cloud client libraries integration via instrumenting the transport (http and/or grpc) level. - Restructure tracers. | Low | 2/6/2018 |
