Skip to main content

otel-extensions-pytest: A pytest extension for OpenTelemetry

otel-extensions-pytest is a pytest plugin that will automatically instrument a pytest-based test session, wrapping the test session in a span and wrapping each test in a child span.

Dependencies

  • Python >= 3.6
  • pytest >= 6.2

Installation

pip install

You can install through pip using:

pip install otel-extensions-pytest

(you may need to run pip with root permission: sudo pip install otel-extensions-pytest)

Setuptools

Install via Setuptools.

python setup.py install --user

(or sudo python setup.py install to install the package for all users)

Usage

Enable the plugin by adding

pytest_plugins = ("otel_extensions_pytest",)

to your conftest.py, or by adding the option -p otel_extensions_pytest to the pytest command line.

For tracing to be enabled, you need to specify a trace receiver endpoint using the command-line option --otel-endpoint or by setting the environment variable OTEL_EXPORTER_OTLP_ENDPOINT. e.g. --otel-endpoint http://localhost:4317/

The full set of options are shown here:

Command-line Option Environment Variable Description
--otel_service_name OTEL_SERVICE_NAME Name of resource/service for traces
--otel_session_name OTEL_SESSION_NAME Name of parent session span
--otel_endpoint OTEL_EXPORTER_OTLP_ENDPOINT OTLP Receiver Endpoint
--otel_protocol OTEL_EXPORTER_OTLP_PROTOCOL protocol for OTLP receiver (supported: gprc , http/protobuf , custom)
--otel_processor_type OTEL_PROCESSOR_TYPE Span Processor type (batch: use BatchSpanProcessor, simple: use SimpleSpanProcessor
--otel_traceparent TRACEPARENT Parent span id. Will be injected into current context (useful when running automated tests using the OpenTelemetry Jenkins plugin)
n/a OTEL_EXPORTER_OTLP_CERTIFICATE path to CA bundle for verifying TLS cert of receiver endpoint
n/a OTEL_EXPORTER_CUSTOM_SPAN_EXPORTER_TYPE Custom span exporter class (needed if protocol set to custom)

Additional Features

@instrumented_fixture decorator

You can decorate fixtures by using the @instrumented_fixture decorator. If the fixture is a generator (i.e. has a yield statement), separate spans will be created for the setup and teardown phases.

from otel_extensions_pytest import instrumented_fixture

# note: all options of pytest.fixture() are supported (autouse, etc)
@instrumented_fixture(scope="function")
def my_fixture():
    """ Span is automatically created using `my_fixture` as span name """
    return "foo"

@instrumented_fixture(scope="function")
def my_generator_fixture():
    # A span named `my_generator_fixture (setup)` is automatically created for this section
    time.sleep(5)
    
    yield "foo"
    
    # A span named `my_generator_fixture (teardown)` is automatically created for this section
    time.sleep(5)
    

Metadata

Release files for otel-extensions-pytest 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for otel-extensions-pytest 0.2.1
File Size Uploaded
otel-extensions-pytest-0.2.1.tar.gz 12.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for otel-extensions-pytest 0.2.1
File Interpreter ABI Platform
otel_extensions_pytest-0.2.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 24.4 kB

Release files / otel-extensions-pytest-0.2.1.tar.gz

Download URL otel-extensions-pytest-0.2.1.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2812572eed594c7e7e0e526d186aeb83be698e45b1130f15c280c094b805bfdd
BLAKE2b-256 checksum
How to use checksums
842da31966cba1e0946e7e833c8be2d15d5039c6cace1c773651fd5491bbd4b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.5

Release files / otel_extensions_pytest-0.2.1-py2.py3-none-any.whl

Download URL otel_extensions_pytest-0.2.1-py2.py3-none-any.whl
Size 11.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e7ab3adbc0ff469eb8e04e973e4a197265fd929c95f35781e1e9fff91a1ea0ea
BLAKE2b-256 checksum
How to use checksums
3e59f21d5b5896516de3270d5f537da0aaee8e3245b44bfdb33906746ae8f123
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page