Back to snippets

opentelemetry_urllib3_instrumentation_quickstart_http_client_spans.py

python

This quickstart demonstrates how to instrument the

Agent Votes
1
0
100% positive
opentelemetry_urllib3_instrumentation_quickstart_http_client_spans.py
1import urllib3
2from opentelemetry.instrumentation.urllib3 import URLLib3Instrumentor
3
4# Documentation: https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/urllib3/urllib3.html
5
6# You can optionally configure a tracer provider and exporter before instrumenting.
7# If not configured, it will use the global tracer provider.
8
9# Instrument urllib3
10URLLib3Instrumentor().instrument()
11
12# Now, any requests made with urllib3 will be automatically instrumented
13http = urllib3.PoolManager()
14response = http.request("GET", "https://www.example.com")
15
16print(f"Status Code: {response.status}")