{ "info": { "author": "OpenCensus Authors", "author_email": "census-developers@googlegroups.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "OpenCensus for Python - A stats collection and distributed tracing framework\n============================================================================\n\n `Census`_ for Python. Census provides a framework to measure a server's resource\n usage and collect performance stats. This repository contains Python related\n utilities and supporting software needed by Census.\n\n .. _Census: https://github.com/census-instrumentation\n\n|circleci|\n\n.. |circleci| image:: https://circleci.com/gh/census-instrumentation/opencensus-python.svg?style=shield\n :target: https://circleci.com/gh/census-instrumentation/opencensus-python\n\n- `API Documentation`_\n\n.. _API Documentation: https://opencensus.io/api/python/trace/usage.html\n\nInstallation & basic usage\n--------------------------\n\n1. Install the opencensus-trace package using `pip`_ or `pipenv`_:\n\n ::\n\n pip install opencensus\n pipenv install opencensus\n\n2. Initialize a tracer for your application:\n\n .. code:: python\n\n from opencensus.trace import tracer as tracer_module\n\n tracer = tracer_module.Tracer()\n\n .. _pip: https://pip.pypa.io\n .. _pipenv: https://docs.pipenv.org/\n\n3. If you want to use the unreleased packages (like stats and tags), you need to build the package from source using the below commands: (The stats and tags packages are expected to be released in 0.1.6)\n\n ::\n\n git clone https://github.com/census-instrumentation/opencensus-python.git\n cd opencensus-python\n python setup.py bdist_wheel\n pip install dist/*\n\nUsage\n-----\n\nYou can collect traces using the ``Tracer`` `context manager`_:\n\n.. code:: python\n\n from opencensus.trace import tracer as tracer_module\n\n # Initialize a tracer, by default using the `PrintExporter`\n tracer = tracer_module.Tracer()\n\n # Example for creating nested spans\n with tracer.span(name='span1') as span1:\n do_something_to_trace()\n with span1.span(name='span1_child1') as span1_child1:\n do_something_to_trace()\n with span1.span(name='span1_child2') as span1_child2:\n do_something_to_trace()\n with tracer.span(name='span2') as span2:\n do_something_to_trace()\n\nCensus will collect everything within the ``with`` statement as a single span.\n\nAlternatively, you can explicitly start and end a span:\n\n.. code:: python\n\n from opencensus.trace import tracer as tracer_module\n\n # Initialize a tracer, by default using the `PrintExporter`\n tracer = tracer_module.Tracer()\n\n tracer.start_span(name='span1')\n do_something_to_trace()\n tracer.end_span()\n\n\n.. _context manager: https://docs.python.org/3/reference/datamodel.html#context-managers\n\n\nCustomization\n-------------\n\nSamplers\n~~~~~~~~\n\nYou can specify different samplers when initializing a tracer, default\nis using ``AlwaysOnSampler``, the other options are ``AlwaysOffSampler``\nand ``ProbabilitySampler``\n\n.. code:: python\n\n from opencensus.trace.samplers import probability\n from opencensus.trace import tracer as tracer_module\n\n # Sampling the requests at the rate equals 0.5\n sampler = probability.ProbabilitySampler(rate=0.5)\n tracer = tracer_module.Tracer(sampler=sampler)\n\nExporters\n~~~~~~~~~\n\nYou can choose different exporters to send the traces to. By default,\nthe traces are printed to stdout in JSON format. Other options include\nwriting to a file, sending to Python logging, or reporting to\nStackdriver.\n\nThis example shows how to configure Census to save the traces to a\nfile:\n\n.. code:: python\n\n from opencensus.trace.exporters import file_exporter\n from opencensus.trace.tracers import context_tracer\n\n exporter = file_exporter.FileExporter(file_name='traces')\n tracer = context_tracer.ContextTracer(exporter=exporter)\n\nThis example shows how to report the traces to Stackdriver Trace:\n\n.. code:: python\n\n from opencensus.trace.exporters import stackdriver_exporter\n from opencensus.trace import tracer as tracer_module\n\n exporter = stackdriver_exporter.StackdriverExporter(\n project_id='your_cloud_project')\n tracer = tracer_module.Tracer(exporter=exporter)\n\nPropagators\n~~~~~~~~~~~\n\nYou can specify the propagator type for serializing and deserializing the\n``SpanContext`` and its headers. There are currently two built in propagators:\n``GoogleCloudFormatPropagator`` and ``TextFormatPropagator``.\n\nThis example shows how to use the ``GoogleCloudFormatPropagator``:\n\n.. code:: python\n\n from opencensus.trace.propagation import google_cloud_format\n\n propagator = google_cloud_format.GoogleCloudFormatPropagator()\n\n # Deserialize\n span_context = propagator.from_header(header)\n\n # Serialize\n header = propagator.to_header(span_context)\n\nBlacklist Paths\n~~~~~~~~~~~~~~~\n\nYou can specify which paths you do not want to trace by configuring the\nblacklist paths.\n\nThis example shows how to configure the blacklist to ignore the `_ah/health` endpoint\nfor a Flask application:\n\n.. code:: python\n\n from opencensus.trace.ext.flask.flask_middleware import FlaskMiddleware\n\n app = flask.Flask(__name__)\n\n blacklist_paths = ['_ah/health']\n middleware = FlaskMiddleware(app, blacklist_paths=blacklist_paths)\n\nFor Django, you can configure the blacklist in the ``OPENCENSUS_PARAMS`` in ``settings.py``:\n\n.. code:: python\n\n OPENCENSUS_PARAMS: {\n ...\n 'BLACKLIST_PATHS': ['_ah/health',],\n }\n\n\n.. note:: By default the health check path for the App Engine flexible environment is not traced,\n but you can turn it on by excluding it from the blacklist setting.\n\nFramework Integration\n---------------------\n\nCensus supports integration with popular web frameworks including\nDjango, Flask, Pyramid, and Webapp2. When the application receives a HTTP request,\nthe tracer will automatically generate a span context using the trace\ninformation extracted from the request headers, and propagated to the\nchild spans.\n\nFlask\n~~~~~\n\nIn your application, use the middleware to wrap your app and the\nrequests will be automatically traced.\n\n.. code:: python\n\n from opencensus.trace.ext.flask.flask_middleware import FlaskMiddleware\n\n app = flask.Flask(__name__)\n\n # You can also specify the sampler, exporter, propagator in the middleware,\n # default is using `AlwaysOnSampler` as sampler, `PrintExporter` as exporter,\n # `GoogleCloudFormatPropagator` as propagator.\n middleware = FlaskMiddleware(app)\n\nDjango\n~~~~~~\n\nFor tracing Django requests, you will need to add the following line to\nthe ``MIDDLEWARE_CLASSES`` section in the Django ``settings.py`` file.\n\n.. code:: python\n\n MIDDLEWARE_CLASSES = [\n ...\n 'opencensus.trace.ext.django.middleware.OpencensusMiddleware',\n ]\n\nAnd add this line to the ``INSTALLED_APPS`` section:\n\n.. code:: python\n\n INSTALLED_APPS = [\n ...\n 'opencensus.trace.ext.django',\n ]\n\nYou can configure the sampler, exporter, propagator using the ``OPENCENSUS_TRACE`` setting in\n``settings.py``:\n\n.. code:: python\n\n OPENCENSUS_TRACE = {\n 'SAMPLER': 'opencensus.trace.samplers.probability.ProbabilitySampler',\n 'EXPORTER': 'opencensus.trace.exporters.print_exporter.PrintExporter',\n 'PROPAGATOR': 'opencensus.trace.propagation.google_cloud_format.'\n 'GoogleCloudFormatPropagator',\n }\n\nYou can configure the sampling rate and other parameters using the ``OPENCENSUS_TRACE_PARAMS``\nsetting in ``settings.py``:\n\n.. code:: python\n\n OPENCENSUS_TRACE_PARAMS = {\n 'BLACKLIST_PATHS': ['/_ah/health'],\n 'GCP_EXPORTER_PROJECT': None,\n 'SAMPLING_RATE': 0.5,\n 'ZIPKIN_EXPORTER_SERVICE_NAME': 'my_service',\n 'ZIPKIN_EXPORTER_HOST_NAME': 'localhost',\n 'ZIPKIN_EXPORTER_PORT': 9411,\n }\n\n\nPyramid\n~~~~~~~\n\nIn your application, add the pyramid tween and your requests will be\ntraced.\n\n.. code:: python\n\n def main(global_config, **settings):\n config = Configurator(settings=settings)\n\n config.add_tween('opencensus.trace.ext.pyramid'\n '.pyramid_middleware.OpenCensusTweenFactory')\n\nTo configure the sampler, exporter, and propagator, pass the instances\ninto the pyramid settings\n\n.. code:: python\n\n from opencensus.trace.exporters import print_exporter\n from opencensus.trace.propagation import google_cloud_format\n from opencensus.trace.samplers import probability\n\n settings = {}\n settings['OPENCENSUS_TRACE'] = {\n 'EXPORTER': print_exporter.PrintExporter(),\n 'SAMPLER': probability.ProbabilitySampler(rate=0.5),\n 'PROPAGATOR': google_cloud_format.GoogleCloudFormatPropagator(),\n }\n\n config = Configurator(settings=settings)\n\ngRPC Integration\n----------------\n\nOpenCensus provides the implementation of interceptors for both the client side\nand server side to instrument the gRPC requests and responses. The client\ninterceptors are used to create a decorated channel that intercepts client\ngRPC calls and server interceptors act as decorators over handlers.\n\ngRPC interceptor is a new feature in the grpcio1.8.0 release, please upgrade\nyour grpcio to the latest version to use this feature.\n\nFor sample usage, please refer to the hello world example in the examples\ndirectory.\n\nMore information about the gRPC interceptors please see the `proposal`_.\n\n.. _proposal: https://github.com/mehrdada/proposal/blob/python-interceptors/L13-Python-Interceptors.md\n\nService Integration\n-------------------\n\nOpencensus supports integration with various popular outbound services such as\nMySQL and Requests. To enable integration you will need to pass the list of\nservices to census:\n\n.. code:: python\n\n from opencensus.trace import config_integration\n from opencensus.trace import tracer as tracer_module\n\n import mysql.connector\n\n # Trace both mysql-connection and psycopg2\n integration = ['mysql', 'postgresql']\n\n config_integration.trace_integrations(integration)\n\n\nMySQL\n~~~~~\n\nThe integration with MySQL supports the `mysql-connector`_ library and is specified\nto ``trace_integrations`` using ``'mysql'``.\n\n.. _mysql-connector: https://pypi.org/project/mysql-connector\n\nPostgreSQL\n~~~~~~~~~~\n\nThe integration with PostgreSQL supports the `psycopg2`_ library and is specified\nto ``trace_integrations`` using ``'postgresql'``.\n\n.. _psycopg2: https://pypi.org/project/psycopg2\n\n\nSQLAlchemy\n~~~~~~~~~~\n\nYou can trace usage of the `sqlalchemy package`_, regardless of the underlying\ndatabase, by specifying ``'sqlalchemy'`` to ``trace_integrations``.\n\n.. _SQLAlchemy package: https://pypi.org/project/SQLAlchemy\n\n.. note:: If you enable tracing of SQLAlchemy as well as the underlying database\n driver, you will get duplicate spans. Instead, just trace SQLAlchemy.\n\nRequests\n~~~~~~~~\n\nCensus can trace HTTP requests made with the `Requests package`_. The request URL,\nmethod, and status will be collected.\n\nYou can enable Requests integration by specifying ``'requests'`` to ``trace_integrations``.\n\n.. _Requests package: https://pypi.python.org/pypi/requests\n\n\nContributing\n------------\n\nContributions to this library are always welcome and highly encouraged.\n\nSee `CONTRIBUTING `__ for more information on how to\nget started.\n\n\nDevelopment\n-----------\n\nTests\n~~~~~\n\n::\n\n cd trace\n tox -e py34\n source .tox/py34/bin/activate\n\n # Run the unit test\n pip install nox-automation\n\n # See what's available in the nox suite\n nox -l\n\n # Run a single nox command\n nox -s \"unit_tests(python_version='2.7')\"\n\n # Run all the nox commands\n nox\n\n # Integration test\n # We don't have script for integration test yet, but can test as below.\n python setup.py bdist_wheel\n cd dist\n pip install opencensus-0.0.1-py2.py3-none-any.whl\n\n # Then just run the tracers normally as you want to test.\n\nLicense\n-------\n\nApache 2.0 - See `LICENSE `__ for more information.\n\nDisclaimer\n----------\n\nThis is not an official Google product.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/felippe-mendonca/opencensus-python", "keywords": "", "license": "Apache-2.0", "maintainer": "", "maintainer_email": "", "name": "is-opencensus", "package_url": "https://pypi.org/project/is-opencensus/", "platform": "", "project_url": "https://pypi.org/project/is-opencensus/", "project_urls": { "Homepage": "https://github.com/felippe-mendonca/opencensus-python" }, "release_url": "https://pypi.org/project/is-opencensus/0.1.5.3/", "requires_dist": null, "requires_python": "", "summary": "A stats collection and distributed tracing framework", "version": "0.1.5.3" }, "last_serial": 4143870, "releases": { "0.1.5": [ { "comment_text": "", "digests": { "md5": "714827cf66f4af80e254b0167c57e195", "sha256": "9c5d5cbed2a8dd37c8b60234aabe439a92a69e39c296df48bcd89dd521398e37" }, "downloads": -1, "filename": "is_opencensus-0.1.5.tar.gz", "has_sig": false, "md5_digest": "714827cf66f4af80e254b0167c57e195", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 62209, "upload_time": "2018-05-29T13:27:16", "url": "https://files.pythonhosted.org/packages/bf/77/653af7faaef197166e195deef02971e16a3dabfe7f103d50c66d0dbe9dd0/is_opencensus-0.1.5.tar.gz" } ], "0.1.5.1": [ { "comment_text": "", "digests": { "md5": "97267a18f31ced76e10dba733c979868", "sha256": "6f6dd24bf56467e0a917df37293b61ac1c4ce6fe4fe79532fd5546b2800298fc" }, "downloads": -1, "filename": "is_opencensus-0.1.5.1.tar.gz", "has_sig": false, "md5_digest": "97267a18f31ced76e10dba733c979868", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 63966, "upload_time": "2018-08-02T10:37:35", "url": "https://files.pythonhosted.org/packages/ab/7c/fdcad0780b32404de17addcfa47bd46afaef23273d3dba4a2f6f3788ad85/is_opencensus-0.1.5.1.tar.gz" } ], "0.1.5.2": [ { "comment_text": "", "digests": { "md5": "ba428402553cab791ac6c883d83207d9", "sha256": "a6f06b2bdecc0d9e63736623045d67caafc91d10ba675fcb15467a6c3c9aaa55" }, "downloads": -1, "filename": "is_opencensus-0.1.5.2.tar.gz", "has_sig": false, "md5_digest": "ba428402553cab791ac6c883d83207d9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 64189, "upload_time": "2018-08-03T10:22:22", "url": "https://files.pythonhosted.org/packages/cc/52/51efa09dbb4aae7a533ef749ea0a4011c653c1ad2b6bca9df04efc0ce6b4/is_opencensus-0.1.5.2.tar.gz" } ], "0.1.5.3": [ { "comment_text": "", "digests": { "md5": "9cd5f1c1592d820978778dd844e2ed5a", "sha256": "32af78e682f8ee8d1dddb79032f33b4920d82aefe04e7fbb8c44e62904170fba" }, "downloads": -1, "filename": "is_opencensus-0.1.5.3.tar.gz", "has_sig": false, "md5_digest": "9cd5f1c1592d820978778dd844e2ed5a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 64216, "upload_time": "2018-08-07T11:53:39", "url": "https://files.pythonhosted.org/packages/11/89/2e95b83ca7d45956752fccea43b793524ee24d73618861311c23c50653ea/is_opencensus-0.1.5.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9cd5f1c1592d820978778dd844e2ed5a", "sha256": "32af78e682f8ee8d1dddb79032f33b4920d82aefe04e7fbb8c44e62904170fba" }, "downloads": -1, "filename": "is_opencensus-0.1.5.3.tar.gz", "has_sig": false, "md5_digest": "9cd5f1c1592d820978778dd844e2ed5a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 64216, "upload_time": "2018-08-07T11:53:39", "url": "https://files.pythonhosted.org/packages/11/89/2e95b83ca7d45956752fccea43b793524ee24d73618861311c23c50653ea/is_opencensus-0.1.5.3.tar.gz" } ] }