pytest extensions for OpenTelemetry
Project description
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",)
to your conftest.py
, or by adding the option -p otel_extensions
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 span 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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file otel-extensions-pytest-0.1.2.tar.gz
.
File metadata
- Download URL: otel-extensions-pytest-0.1.2.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1a27b83797e9d303a04c32edc615f6974e0e7550a44a42d9ff3e89b99398694 |
|
MD5 | eab6ea84eac198c3864f89addd8c7e58 |
|
BLAKE2b-256 | 71c249f205628dc842b6d2aee3ad817e79b9c6cb93c4ef1eb0093efb71d90a4e |
File details
Details for the file otel_extensions_pytest-0.1.2-py2.py3-none-any.whl
.
File metadata
- Download URL: otel_extensions_pytest-0.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49dbb5523384a512feedea87dcedd356816516d29e8f171f398d3dc545964374 |
|
MD5 | 2f5cf01b6443e7eddef8156126973aa4 |
|
BLAKE2b-256 | bfa959a1d74d6400b20b429d18584294731c0f1764e31ec0a3a272fb8a5f1740 |