opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentati...
Leighton Chen f7ba3ba516
update (#337)
2021-02-16 14:27:31 -08:00
..
src/opentelemetry/instrumentation/aiohttp_client update (#337) 2021-02-16 14:27:31 -08:00
tests Remove 'component' span attribute in instrumentations (#301) 2021-01-29 13:15:26 -08:00
LICENSE Rename web framework packages from "ext" to "instrumentation" (#961) 2020-08-03 10:10:45 -07:00
MANIFEST.in Rename web framework packages from "ext" to "instrumentation" (#961) 2020-08-03 10:10:45 -07:00
README.rst Aiohttp instrumentation readme (#286) 2021-01-28 09:12:31 -08:00
setup.cfg update (#337) 2021-02-16 14:27:31 -08:00
setup.py Rename web framework packages from "ext" to "instrumentation" (#961) 2020-08-03 10:10:45 -07:00

README.rst

OpenTelemetry aiohttp client Integration
========================================

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-aiohttp-client.svg
   :target: https://pypi.org/project/opentelemetry-instrumentation-aiohttp-client/

This library allows tracing HTTP requests made by the
`aiohttp client <https://docs.aiohttp.org/en/stable/client.html>`_ library.

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

::

     pip install opentelemetry-instrumentation-aiohttp-client


Example
-------

.. code:: python

   import asyncio
   
   import aiohttp

   from opentelemetry.instrumentation.aiohttp_client import AioHttpClientInstrumentor
   from opentelemetry import trace
   from opentelemetry.exporter import jaeger
   from opentelemetry.sdk.trace import TracerProvider
   from opentelemetry.sdk.trace.export import BatchExportSpanProcessor


   _JAEGER_EXPORTER = jaeger.JaegerSpanExporter(
      service_name="example-xxx",
      agent_host_name="localhost",
      agent_port=6831,
   )

   _TRACE_PROVIDER = TracerProvider()
   _TRACE_PROVIDER.add_span_processor(BatchExportSpanProcessor(_JAEGER_EXPORTER))
   trace.set_tracer_provider(_TRACE_PROVIDER)

   AioHttpClientInstrumentor().instrument()


   async def span_emitter():
      async with aiohttp.ClientSession() as session:
         async with session.get("https://example.com") as resp:
               print(resp.status)


   asyncio.run(span_emitter())


References
----------

* `OpenTelemetry Project <https://opentelemetry.io/>`_
* `aiohttp client Tracing <https://docs.aiohttp.org/en/stable/tracing_reference.html>`_