Fix: propagate opentelemetry-instrument and ddtrace-run to flow run subprocesses#21041
Open
shnhdan wants to merge 10 commits intoPrefectHQ:mainfrom
Open
Fix: propagate opentelemetry-instrument and ddtrace-run to flow run subprocesses#21041shnhdan wants to merge 10 commits intoPrefectHQ:mainfrom
shnhdan wants to merge 10 commits intoPrefectHQ:mainfrom
Conversation
When OTEL_* or DD_* env vars are detected, prepend the corresponding wrapper command (opentelemetry-instrument or ddtrace-run) to the subprocess command so auto-instrumentation propagates to child processes. Adds PREFECT_WORKER_PROCESS_COMMAND_WRAPPERS setting to configure which wrappers to detect, defaulting to opentelemetry-instrument and ddtrace-run. Closes PrefectHQ#20535
desertaxle
requested changes
Mar 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #20535
Problem
When users run
opentelemetry-instrument prefect flow-run execute, theauto-instrumentation setup does not propagate to the subprocess that
actually runs the flow. This is because the child process is spawned
fresh and doesn't inherit the instrumentation bootstrapped in the parent.
Solution
The process worker now detects active wrapper commands via environment
signals and prepends them to the subprocess command:
OTEL_*env vars → prependsopentelemetry-instrumentDD_*env vars → prependsddtrace-runChanges
_detect_active_wrappers()helper inprocess.pyto detectactive wrappers via env var signals
prepare_for_flow_run()to prepend detected wrappers to thesubprocess command
PREFECT_WORKER_PROCESS_COMMAND_WRAPPERSsetting (default:["opentelemetry-instrument", "ddtrace-run"]) so users can opt in/outor add custom wrappers by configuring this setting
Testing
verify_otel.py