Skip to content

Commit 5dd2412

Browse files
authored
Aiohttp instrumentation readme (#286)
1 parent fcc260c commit 5dd2412

File tree

1 file changed

+38
-0
lines changed
  • instrumentation/opentelemetry-instrumentation-aiohttp-client

1 file changed

+38
-0
lines changed

instrumentation/opentelemetry-instrumentation-aiohttp-client/README.rst

+38
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,44 @@ Installation
1717
pip install opentelemetry-instrumentation-aiohttp-client
1818

1919

20+
Example
21+
-------
22+
23+
.. code:: python
24+
25+
import asyncio
26+
27+
import aiohttp
28+
29+
from opentelemetry.instrumentation.aiohttp_client import AioHttpClientInstrumentor
30+
from opentelemetry import trace
31+
from opentelemetry.exporter import jaeger
32+
from opentelemetry.sdk.trace import TracerProvider
33+
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
34+
35+
36+
_JAEGER_EXPORTER = jaeger.JaegerSpanExporter(
37+
service_name="example-xxx",
38+
agent_host_name="localhost",
39+
agent_port=6831,
40+
)
41+
42+
_TRACE_PROVIDER = TracerProvider()
43+
_TRACE_PROVIDER.add_span_processor(BatchExportSpanProcessor(_JAEGER_EXPORTER))
44+
trace.set_tracer_provider(_TRACE_PROVIDER)
45+
46+
AioHttpClientInstrumentor().instrument()
47+
48+
49+
async def span_emitter():
50+
async with aiohttp.ClientSession() as session:
51+
async with session.get("https://example.com") as resp:
52+
print(resp.status)
53+
54+
55+
asyncio.run(span_emitter())
56+
57+
2058
References
2159
----------
2260

0 commit comments

Comments
 (0)