Requests Instrumentation
Snippets related to Requests python package
Configuring environment
Development Environment
You can run otel-tui as OpenTelemetry Collector, which acts as a terminal OpenTelemetry viewer
docker run -p 4317:4317 -p 4318:4318 --rm -it --name otel-tui ymtdzzz/otel-tui:latest
Install packages
Create the virtual environment and install the dependencies:
uv venv && source .venv/bin/activate
requirements.txt
opentelemetry-distro
opentelemetry-exporter-otlp
requests
Quick install with uv
uv pip install -r https://emdneto.github.io/opentelemetry-by-example/python/requests/requirements.txt
opentelemetry-bootstrap -a requirements | uv pip install -r -
Zero-code Instrumentation
snippet_zerocode.py | |
---|---|
1 2 3 |
|
Run this snippet
pentelemetry-instrument --service_name=snippet-zerocode python snippet_zerocode.py
Using Instrumentors
snippet_manual.py | |
---|---|
1 |
|
Run this Python snippet
uv run https://emdneto.github.io/opentelemetry-by-example/python/requests/snippet_manual.py
Using Stable HTTP Semantic Conventions
By default opentelemetry-instrumentation-requests
emit telemetry using an old Semantic Convention version.
If you want to use new attributes defined in the OpenTelemetry HTTP Stable Semantic Convetions, you should opt-in as following:
snippet_zerocode.py | |
---|---|
1 |
|
Run this snippet
OTEL_SEMCONV_STABILITY_OPT_IN="http" opentelemetry-instrument --service_name=snippet-zerocode-stable-semconv python snippet_zerocode.py