semvec/pypi-packages huggingface dataset:
opencensus-ext-requests 0.8.0
OpenCensus Requests Integration
License: Apache-2.0

OpenCensus requests Integration
============================================================================

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opencensus-ext-requests.svg
   :target: https://pypi.org/project/opencensus-ext-requests/

OpenCensus can trace HTTP requests made with the `requests package`_. The request URL,
method, and status will be collected.

You can enable requests integration by specifying ``'requests'`` to ``trace_integrations``.

It's possible to configure a list of URL you don't want traced. By default the request to exporter
won't be traced. It's configurable by giving an array of hostname/port to the attribute
``excludelist_hostnames`` in OpenCensus context's attributes:

Only the hostname must be specified if only the hostname is specified in the URL request.

.. _Requests package: https://pypi.python.org/pypi/requests

Installation
------------

::

    pip install opencensus-ext-requests

Usage
-----

.. code:: python

    import requests
    from opencensus.trace import config_integration
    from opencensus.trace.tracer import Tracer

    if __name__ == '__main__':
        config_integration.trace_integrations(['requests'])
        tracer = Tracer()
        with tracer.span(name='parent'):
            response = requests.get(url='https://www.wikipedia.org/wiki/Rabbit')

References
----------

* `OpenCensus Project <https://opencensus.io/>`_
opencensus-context 0.1.3
OpenCensus Runtime Context
License: Apache-2.0

OpenCensus Runtime Context
============================================================================

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opencensus-context.svg
   :target: https://pypi.org/project/opencensus-context/

The **OpenCensus Runtime Context** provides in-process context propagation.
By default, ``thread local storage`` is used for Python 2.7, 3.4 and 3.5;
``contextvars`` is used for Python >= 3.6, which provides ``asyncio`` support.

Installation
------------

This library is installed by default with ``opencensus``, there is no need
to install it explicitly.

Usage
-----

In most cases context propagation happens automatically within a process,
following the control flow of threads and asynchronous coroutines. The runtime
context is a dictionary stored in a `context variable <https://docs.python.org/3/library/contextvars.html>`_
when available, and in `thread local storage <https://docs.python.org/2/library/threading.html#threading.local>`_
otherwise.

There are cases where you may want to propagate the context explicitly:

Explicit Thread Creation
~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    from threading import Thread
    from opencensus.common.runtime_context import RuntimeContext

    def work(name):
        # here you will get the context from the parent thread
        print(RuntimeContext)

    thread = Thread(
        # propagate context explicitly
        target=RuntimeContext.with_current_context(work),
        args=('foobar',),
    )
    thread.start()
    thread.join()

Thread Pool
~~~~~~~~~~~

.. code:: python

    from multiprocessing.dummy import Pool as ThreadPool
    from opencensus.common.runtime_context import RuntimeContext

    def work(name):
        # here you will get the context from the parent thread
        print(RuntimeContext)

    pool = ThreadPool(2)
    # propagate context explicitly
    pool.map(RuntimeContext.with_current_context(work), [
        'bear',
        'cat',
        'dog',
        'horse',
        'rabbit',
    ])
    pool.close()
    pool.join()

References
----------

* `Examples <https://github.com/census-instrumentation/opencensus-python/tree/master/context/opencensus-context/examples>`_
* `OpenCensus Project <https://opencensus.io/>`_