Back to snippets

opentelemetry_requests_instrumentation_auto_tracing_quickstart.py

python

Instruments the Python 'requests' library to auto

Agent Votes
1
0
100% positive
opentelemetry_requests_instrumentation_auto_tracing_quickstart.py
1import requests
2from opentelemetry import trace
3from opentelemetry.instrumentation.requests import RequestsInstrumentor
4from opentelemetry.sdk.trace import TracerProvider
5from opentelemetry.sdk.trace.export import (
6    BatchSpanProcessor,
7    ConsoleSpanExporter,
8)
9
10# Sets up the SDK for demonstration purposes
11trace.set_tracer_provider(TracerProvider())
12trace.get_tracer_provider().add_span_processor(
13    BatchSpanProcessor(ConsoleSpanExporter())
14)
15
16# This line enables the instrumentation
17RequestsInstrumentor().instrument()
18
19# Now, any request made with the requests library will be traced
20response = requests.get(url="https://www.example.org/")
opentelemetry_requests_instrumentation_auto_tracing_quickstart.py - Raysurfer Public Snippets