Skip to main content

dagger-pytest-otel

A pytest plugin for OpenTelemetry instrumentation with Dagger.

This plugin automatically instruments pytest tests with OpenTelemetry spans, enabling test visibility in Dagger's TUI and Dagger Cloud.

Features

  • Zero configuration: Automatically creates spans for each test
  • TRACEPARENT propagation: Inherits trace context from Dagger
  • Session spans: Creates a parent span for the entire test session
  • Test hierarchy: Captures module, class, and function information
  • Outcome tracking: Records test pass/fail/skip status
  • Log capture: Forwards Python logs to OpenTelemetry
  • Exception recording: Records test exceptions on spans

Installation

pip install dagger-pytest-otel

Usage

Once installed, the plugin is automatically enabled. No code changes are required in your tests.

With Dagger

When running tests through Dagger, the TRACEPARENT environment variable is automatically set, and test spans will appear in the Dagger TUI and Dagger Cloud.

The pytest module bundles this plugin. A module that builds its own test container installs it:

# In your Dagger module
@function
async def test(self, source: dagger.Directory) -> str:
    return await (
        dag.container()
        .from_("python:3.11-slim")
        .with_directory("/src", source)
        .with_workdir("/src")
        .with_exec(["pip", "install", "pytest", "dagger-pytest-otel"])
        .with_exec(["pytest", "-v"])
        .stdout()
    )

Standalone

You can also use the plugin standalone with any OTLP-compatible backend:

export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318"
export TRACEPARENT="00-abc123...-def456...-01"  # Optional parent trace
pytest

The plugin sends OTLP over HTTP to an http:// or https:// endpoint, and over gRPC to an endpoint without a scheme. OTEL_EXPORTER_OTLP_PROTOCOL (grpc or http/protobuf) overrides that choice, and OTEL_EXPORTER_OTLP_TRACES_PROTOCOL or OTEL_EXPORTER_OTLP_LOGS_PROTOCOL overrides it for one signal; any other value sends http/protobuf with a warning. gRPC needs the opentelemetry-exporter-otlp-proto-grpc package; without it, the plugin warns and exports nothing.

Disabling

To disable instrumentation:

pytest --no-otel

Span Attributes

Each test span includes the following attributes:

Attribute Description
dagger.io/ui.boundary Prevents log bubbling in Dagger TUI
test.case.name Fully qualified pytest test case name
test.case.result.status Test result (pass/fail/skipped)
test.suite.name Pytest suite containing the test case

Session spans also include test.suite.run.status. Their test.suite.name is the pytest rootdir relative to the nearest directory holding .git, or the rootdir's name at that directory or outside Git; 0.3.0 used the absolute path.

Spans and logs report the service name pytest, unless OTEL_SERVICE_NAME or OTEL_RESOURCE_ATTRIBUTES sets one.

Test output

Captured stdout and stderr output is exported as OpenTelemetry logs on the active test span using Dagger's stdio.stream attribute. Python logging records are also forwarded as OpenTelemetry logs and mapped to stdout or stderr by severity.

Python's root logger drops records below WARNING before the plugin sees them. Set pytest's log_level, for example with --log-level=INFO, to forward INFO records too.

Development

cd pytest/dagger_pytest_otel
uv run pytest

License

Apache-2.0

Metadata

Release files for dagger-pytest-otel 0.3.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 dagger-pytest-otel 0.3.1
File Size Uploaded Provenance
dagger_pytest_otel-0.3.1.tar.gz 25.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dagger-pytest-otel 0.3.1
File Interpreter ABI Platform
dagger_pytest_otel-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 45.6 kB

Release files / dagger_pytest_otel-0.3.1.tar.gz

Download URL dagger_pytest_otel-0.3.1.tar.gz
Size 25.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e5e7e0a54f8fc6ac0e97b3b3134c374e80aa1001120ca1016807fb228a1e9543
BLAKE2b-256 checksum
How to use checksums
f8933ddbc349e74e520f78f019b87845e821578256235533cd5b2c57ae000083
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / dagger_pytest_otel-0.3.1-py3-none-any.whl

Download URL dagger_pytest_otel-0.3.1-py3-none-any.whl
Size 19.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7083d9600231c80d031e1dce01d8144ed5f4f8797587169a105b840a461ddd19
BLAKE2b-256 checksum
How to use checksums
77605c34a87f0195f39ed9b7b35738145508e7ab392c638e0f04887b7a2b5753
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for dagger-pytest-otel 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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