Registry / testing / pytest-opentelemetry

pytest-opentelemetry

JSON →
library1.1.0pypypi✓ verified 24d ago

pytest-opentelemetry is a pytest plugin that instruments your test runs, exporting detailed span data and timing information via OpenTelemetry. It transforms traditional pass/fail test results into rich, queryable telemetry data, allowing users to analyze test performance, identify slow or flaky tests, and visualize the full test session as a distributed trace. The library is actively maintained, currently at version 1.1.0, with frequent minor releases to add features and improve stability.

pip install pytest-opentelemetry opentelemetry-sdk opentelemetry-exporter-otlp
INSTALL
IMPORT
SIG · PYTEST-OPENTELEMET
P
pytest-opentelemetry
testingpythonv1.1.0
Install
6.5s avg
Import
Disk
63MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 65MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 6.5s · import 0.000s · 63MB
63MB installed
● package 63MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pytest-opentelemetry
This is a pytest plugin and automatically registers upon installation. No direct Python imports are typically needed in your test files or conftest.py to enable its core functionality.
Interaction is primarily via pytest CLI flags or OpenTelemetry environment variables.

To quickly get started, install the plugin along with the OpenTelemetry SDK and an OTLP exporter. Create a simple test file. The plugin registers automatically. To activate tracing and export spans, run `pytest` with the `--export-traces` flag. By default, it attempts to export to an OpenTelemetry Collector at `http://localhost:4317` using OTLP gRPC. For a basic demonstration without a collector, configure the `OTEL_TRACES_EXPORTER` environment variable to `console`.

import pytest import os # A simple test file (e.g., test_example.py) def test_success(): assert True def test_failure(): assert False @pytest.mark.skip(reason="demonstrating skip") def test_skipped(): assert True # To run and see console output: # Set environment variables for console exporter for demonstration # In a real scenario, you'd point to an OpenTelemetry Collector # os.environ['OTEL_TRACES_EXPORTER'] = 'console' # os.environ['OTEL_SERVICE_NAME'] = 'my-pytest-suite' # Then run from your terminal: # pytest --export-traces test_example.py -s -v
Debug
Known issues
gotchapytest-opentelemetry itself only instruments; it requires the OpenTelemetry SDK and at least one exporter (e.g., `opentelemetry-exporter-otlp`) to be installed and configured to actually send traces. Without an exporter, spans will be collected in memory but not sent anywhere.
fix
Ensure you `pip install opentelemetry-sdk opentelemetry-exporter-otlp` (or another desired exporter) alongside `pytest-opentelemetry`. Configure the exporter endpoint and protocol using standard OpenTelemetry environment variables (e.g., `OTEL_EXPORTER_OTLP_ENDPOINT`, `OTEL_EXPORTER_OTLP_PROTOCOL`) or CLI flags.
affects: All versions
gotchaConfiguration can be done via standard OpenTelemetry environment variables (e.g., `OTEL_SERVICE_NAME`, `OTEL_EXPORTER_OTLP_ENDPOINT`) or specific `pytest` CLI flags (e.g., `--otel-service-name`, `--otel-endpoint`). Command-line arguments always take precedence over environment variables, which can lead to unexpected behavior if both are set conflictingly.
fix
Standardize your configuration method. If using environment variables, ensure no conflicting CLI flags are used. If using CLI flags, verify they are correctly applied and override any environment variables as intended.
affects: All versions
breakingThe OpenTelemetry Python SDK, which `pytest-opentelemetry` relies upon, frequently introduces breaking changes or deprecations, especially for experimental features or during its stabilization phase for metrics and logs. Upgrading the underlying `opentelemetry-sdk` or related `opentelemetry-exporter-*` packages might introduce incompatibilities.
fix
Always review the OpenTelemetry Python SDK changelogs when updating `opentelemetry-sdk` or related packages. Pin your `opentelemetry-*` package versions in your `requirements.txt` to ensure consistent behavior.
affects: Any `opentelemetry-sdk` version updates, especially across major/minor boundaries in OpenTelemetry SDK.
gotchaThe plugin has a dependency on `pytest>=7.x`. Using it with older versions of `pytest` may result in unexpected behavior or errors.
fix
Ensure your project's `pytest` version is 7.0 or newer. Upgrade `pytest` if necessary: `pip install --upgrade pytest`.
affects: <1.0.0 (and implied for 1.x.x)
gotchaThe `pytest-opentelemetry` README (as of version 1.x) states that it defaults to OTLP over gRPC for trace export. If your OpenTelemetry Collector or backend expects HTTP/protobuf, you must explicitly configure the `OTEL_EXPORTER_OTLP_PROTOCOL` environment variable.
fix
Set `OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf` if your collector expects HTTP. Also ensure the corresponding exporter package is installed (e.g., `opentelemetry-exporter-otlp-proto-http`).
affects: All versions
Upgrade
Version history
1.1.0latest on PyPI · released Apr 25, 2025
Audit
Dependencies
pytestrequiredCore testing framework that the plugin extends.
opentelemetry-sdkrequiredOpenTelemetry Python SDK for tracing and span management.
opentelemetry-exporter-otlprequiredRequired to export telemetry data using the OpenTelemetry Protocol (OTLP). Other exporters like `opentelemetry-exporter-jaeger` can also be used.
opentelemetry-exporter-otlp-proto-grpcoptionalSpecific OTLP exporter for gRPC protocol, often required by default for OTLP.
opentelemetry-exporter-otlp-proto-httpoptionalSpecific OTLP exporter for HTTP/protobuf protocol, if chosen.
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
2
Resources
pytest-opentelemetry — pip install pytest-opentelemetry · libregistry