Skip to main content

OpenTelemetry plugin for Pytest

Project description



pytest-otel plugin for reporting OpenTelemetry spans of tests executed.



  • opentelemetry-api == 1.15.0
  • opentelemetry-exporter-otlp == 1.15.0
  • opentelemetry-sdk == 1.15.0
  • pytest >= 7.1.3


You can install "pytest-otel" via pip or using the script.

pip install pytest-otel


pytest_otel is configured by adding some parameters to the pytest command line. Below are the descriptions:

  • --otel-endpoint: URL for the OpenTelemetry server. (Required). Env variable: OTEL_EXPORTER_OTLP_ENDPOINT
  • --otel-headers: Additional headers to send (i.e.: key1=value1,key2=value2). Env variable: OTEL_EXPORTER_OTLP_HEADERS
  • --otel-service-name: Name of the service. Env variable: OTEL_SERVICE_NAME
  • --otel-session-name: Name for the main span.
  • --otel-traceparent: Trace parent ID. Env variable: TRACEPARENT. See
  • --otel-insecure: Disables TLS. Env variable: OTEL_EXPORTER_OTLP_INSECURE
pytest --otel-endpoint \
       --otel-headers "authorization=Bearer ASWDCcCRFfr" \
       --otel-service-name pytest_otel \
       --otel-session-name='My_Test_cases' \
       --otel-traceparent=00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01 \

IMPORTANT: If you use --otel-headers the transaction metadata might expose those arguments with their values. In order to avoid any credentials to be exposed, it's recommended to use the environment variables. For instance, given the above example, a similar one with environment variables can be seen below:

OTEL_SERVICE_NAME=pytest_otel \
TRACEPARENT=00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01 \
pytest --otel-session-name='My_Test_cases'



Distributed under the terms of the Apache License Version 2.0_ license, "pytest-otel" is free and open source software

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_otel-1.5.0.tar.gz (17.8 kB view hashes)

Uploaded source

Built Distribution

pytest_otel-1.5.0-py2.py3-none-any.whl (14.5 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page