prefect-otel
prefect-otel is an experimental Prefect integration for OpenTelemetry.
This package provides a Prefect plugin hook that bootstraps OpenTelemetry Python auto-instrumentation in Prefect flow-run subprocesses.
Experimental Status
This package is experimental. Public settings, behavior, and compatibility guarantees may change in breaking ways at any time.
Installation
pip install prefect-otel
OpenTelemetry automatic instrumentation still requires the normal OpenTelemetry packages and instrumentation libraries. The package depends on the OpenTelemetry distro and OTLP exporter, but users should still run bootstrap in their target environment when they want library-specific instrumentation:
opentelemetry-bootstrap -a install
Usage
No flow code changes are required. The environment that actually executes your flow must have:
prefect-otelinstalled.- Prefect plugins enabled with
PREFECT_PLUGINS_ENABLED=1. - Standard OpenTelemetry
OTEL_*environment variables configured.
For deployed flows, this usually means the worker environment, job image, virtual environment, or work pool job configuration used by the deployment.
Enable Prefect plugins in that same runtime:
export PREFECT_PLUGINS_ENABLED=1
Once Prefect loads this plugin, OpenTelemetry auto-instrumentation is enabled by default.
Configure OpenTelemetry with standard OTEL_* environment variables in that
same runtime:
export OTEL_SERVICE_NAME=my-prefect-flow
export OTEL_TRACES_EXPORTER=otlp
export OTEL_METRICS_EXPORTER=none
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
For a flow run directly from Python, set the same variables before starting the process:
python my_flow.py
The plugin runs when Prefect is imported. By default, it calls OpenTelemetry's
programmatic auto-instrumentation initializer in each Prefect process. This
allows spawned flow-run subprocesses to configure OpenTelemetry from inherited
OTEL_* variables even though the parent process's in-memory SDK setup is not
inherited across Python spawn.
You do not need to call opentelemetry-instrument in a custom Prefect command
to use this package. If you already wrap a worker or application entrypoint
with opentelemetry-instrument, you can keep that wrapper; this integration
handles Prefect processes that are started later from the inherited
environment.
Deployment Job Variables
For deployments, set these variables in job_variables.env so the process that
runs your flow receives them:
deployments:
- name: my-deployment
entrypoint: flows.py:my_flow
work_pool:
name: my-pool
job_variables:
env:
PREFECT_PLUGINS_ENABLED: "1"
OTEL_SERVICE_NAME: "my-prefect-flow"
OTEL_TRACES_EXPORTER: "otlp"
OTEL_METRICS_EXPORTER: "none"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector:4317"
If you create deployments from Python, pass the same environment variables in
job_variables:
from prefect import flow
@flow
def my_flow() -> None:
...
if __name__ == "__main__":
my_flow.deploy(
name="my-deployment",
work_pool_name="my-pool",
job_variables={
"env": {
"PREFECT_PLUGINS_ENABLED": "1",
"OTEL_SERVICE_NAME": "my-prefect-flow",
"OTEL_TRACES_EXPORTER": "otlp",
"OTEL_METRICS_EXPORTER": "none",
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://otel-collector:4317",
}
},
)
These examples configure OTLP trace export and disable metric export. Adjust the
OTEL_* values for your collector, exporter, and telemetry pipeline.
Common places to set them:
- Deployment
job_variables.env. - Work pool default job variables.
- Container image entrypoints or Kubernetes, Docker, ECS, Cloud Run, or other job environment settings.
For a container image, install the package and OpenTelemetry instrumentation in the image that will run flows:
FROM prefecthq/prefect:3-python3.12
RUN pip install prefect-otel \
&& opentelemetry-bootstrap -a install
The image installs the package and instrumentation libraries. The deployment
or work pool still needs the job_variables.env values shown above so the
flow process can configure OpenTelemetry at runtime.
Disable Auto-Instrumentation
To disable the integration without uninstalling it, set:
export PREFECT_INTEGRATIONS_OTEL_AUTO_INSTRUMENT=false
Settings
Settings follow Prefect integration naming conventions and can be configured
with environment variables, .env, prefect.toml, or pyproject.toml.
| Setting | Environment variable | Default |
|---|---|---|
auto_instrument |
PREFECT_INTEGRATIONS_OTEL_AUTO_INSTRUMENT |
true |
require_auto_instrument |
PREFECT_INTEGRATIONS_OTEL_REQUIRE_AUTO_INSTRUMENT |
false |
prefect.toml:
[integrations.otel]
auto_instrument = false
require_auto_instrument = false
pyproject.toml:
[tool.prefect.integrations.otel]
auto_instrument = false
require_auto_instrument = false
If require_auto_instrument is true, initialization failures are re-raised.
Use this with PREFECT_PLUGINS_STRICT=1 when startup should fail instead of
running without OpenTelemetry auto-instrumentation:
export PREFECT_PLUGINS_STRICT=1
export PREFECT_INTEGRATIONS_OTEL_REQUIRE_AUTO_INSTRUMENT=true
Diagnostics
Prefect can show plugin discovery and hook results:
prefect plugins diagnose
If traces are missing, check that:
prefect-otelis installed in the environment that runs the flow, not just in the environment where the deployment was built.PREFECT_PLUGINS_ENABLED=1is set where the flow code runs.- The
OTEL_*variables are inherited by the flow-run process. - The relevant OpenTelemetry instrumentation libraries are installed.
- Your collector or exporter endpoint is reachable from the flow-run environment.
Metadata
Release files for prefect-otel 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| prefect_otel-0.0.1.tar.gz | 214.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| prefect_otel-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 223.3 kB
Release files / prefect_otel-0.0.1.tar.gz
| Download URL | prefect_otel-0.0.1.tar.gz |
|---|---|
| Size | 214.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6586f6dbddab845f5b6b425a6bbce4ed9813e8aa722a72fb72f9edf25d3222c5
|
|
BLAKE2b-256 checksum How to use checksums |
41e5c51f296fbd13c063c168072c89642e773579ed0dff23c4d66729a834829b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 5, 2026.
Transparency logRelease files / prefect_otel-0.0.1-py3-none-any.whl
| Download URL | prefect_otel-0.0.1-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c3e07156f32064acec3509bf620ba2cb03041ae1526f5de306ad9d9cc346cf0e
|
|
BLAKE2b-256 checksum How to use checksums |
727a326fd96adf07ce261bde3de9f1f9507a147d2869188169b380ca076b3b9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 5, 2026.
Transparency log