opentelemetry-python-contrib/util/opentelemetry-util-http
Srikanth Chekuri b2923e02fa
updating changelogs and version to 1.13.0-0.34b0 (#1352)
2022-09-27 03:12:18 +05:30
..
src/opentelemetry/util/http updating changelogs and version to 1.13.0-0.34b0 (#1352) 2022-09-27 03:12:18 +05:30
tests Add support for sanitizing HTTP header values. (#1253) 2022-09-13 08:19:05 +00:00
README.rst Remove Configuration from instrumentations (#285) 2021-02-04 08:02:37 -08:00
pyproject.toml Update package metadata opentelemetry-util-http (#1309) 2022-09-07 17:38:04 +00:00

README.rst

OpenTelemetry Util HTTP
=======================

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opentelemetry-util-http.svg
   :target: https://pypi.org/project/opentelemetry-util-http/


This library provides ASGI, WSGI middleware and other HTTP-related
functionality that is common to instrumented web frameworks (such as Django,
Starlette, FastAPI, etc.) to track requests timing through OpenTelemetry.

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

::

    pip install opentelemetry-util-http


Usage (Quart)
-------------

.. code-block:: python

    from quart import Quart
    from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware

    app = Quart(__name__)
    app.asgi_app = OpenTelemetryMiddleware(app.asgi_app)

    @app.route("/")
    async def hello():
        return "Hello!"

    if __name__ == "__main__":
        app.run(debug=True)


Usage (Django 3.0)
------------------

Modify the application's ``asgi.py`` file as shown below.

.. code-block:: python

    import os
    from django.core.asgi import get_asgi_application
    from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware

    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'asgi_example.settings')

    application = get_asgi_application()
    application = OpenTelemetryMiddleware(application)


Usage (Raw ASGI)
----------------

.. code-block:: python

    from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware

    app = ...  # An ASGI application.
    app = OpenTelemetryMiddleware(app)


References
----------

* `OpenTelemetry Project <https://opentelemetry.io/>`_