Experimental Prefect integration for OpenTelemetry auto-instrumentation.
Project description
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.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prefect_otel-0.0.1.tar.gz.
File metadata
- Download URL: prefect_otel-0.0.1.tar.gz
- Upload date:
- Size: 214.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6586f6dbddab845f5b6b425a6bbce4ed9813e8aa722a72fb72f9edf25d3222c5
|
|
| MD5 |
0b0441a16790719ce344c6dad69fa1aa
|
|
| BLAKE2b-256 |
41e5c51f296fbd13c063c168072c89642e773579ed0dff23c4d66729a834829b
|
Provenance
The following attestation bundles were made for prefect_otel-0.0.1.tar.gz:
Publisher:
publish.yml on prefectlabs/prefect-otel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prefect_otel-0.0.1.tar.gz -
Subject digest:
6586f6dbddab845f5b6b425a6bbce4ed9813e8aa722a72fb72f9edf25d3222c5 - Sigstore transparency entry: 1735827427
- Sigstore integration time:
-
Permalink:
prefectlabs/prefect-otel@71b609a904b5d3afaecbd0523e0bad3c1685660b -
Branch / Tag:
refs/tags/prefect-otel-0.0.1 - Owner: https://github.com/prefectlabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@71b609a904b5d3afaecbd0523e0bad3c1685660b -
Trigger Event:
release
-
Statement type:
File details
Details for the file prefect_otel-0.0.1-py3-none-any.whl.
File metadata
- Download URL: prefect_otel-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3e07156f32064acec3509bf620ba2cb03041ae1526f5de306ad9d9cc346cf0e
|
|
| MD5 |
b89491ec73f8b541772d2fb2798490d1
|
|
| BLAKE2b-256 |
727a326fd96adf07ce261bde3de9f1f9507a147d2869188169b380ca076b3b9d
|
Provenance
The following attestation bundles were made for prefect_otel-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on prefectlabs/prefect-otel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prefect_otel-0.0.1-py3-none-any.whl -
Subject digest:
c3e07156f32064acec3509bf620ba2cb03041ae1526f5de306ad9d9cc346cf0e - Sigstore transparency entry: 1735827551
- Sigstore integration time:
-
Permalink:
prefectlabs/prefect-otel@71b609a904b5d3afaecbd0523e0bad3c1685660b -
Branch / Tag:
refs/tags/prefect-otel-0.0.1 - Owner: https://github.com/prefectlabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@71b609a904b5d3afaecbd0523e0bad3c1685660b -
Trigger Event:
release
-
Statement type: