prefect-otel 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- prefect_otel-0.0.1/.github/workflows/ci.yml +51 -0
- prefect_otel-0.0.1/.github/workflows/publish.yml +35 -0
- prefect_otel-0.0.1/.gitignore +11 -0
- prefect_otel-0.0.1/.pre-commit-config.yaml +14 -0
- prefect_otel-0.0.1/.python-version +2 -0
- prefect_otel-0.0.1/LICENSE +161 -0
- prefect_otel-0.0.1/PKG-INFO +239 -0
- prefect_otel-0.0.1/README.md +210 -0
- prefect_otel-0.0.1/justfile +23 -0
- prefect_otel-0.0.1/prefect_opentelemetry/__init__.py +72 -0
- prefect_otel-0.0.1/prefect_opentelemetry/py.typed +1 -0
- prefect_otel-0.0.1/prefect_opentelemetry/settings.py +29 -0
- prefect_otel-0.0.1/prefect_otel.egg-info/PKG-INFO +239 -0
- prefect_otel-0.0.1/prefect_otel.egg-info/SOURCES.txt +23 -0
- prefect_otel-0.0.1/prefect_otel.egg-info/dependency_links.txt +1 -0
- prefect_otel-0.0.1/prefect_otel.egg-info/entry_points.txt +2 -0
- prefect_otel-0.0.1/prefect_otel.egg-info/requires.txt +4 -0
- prefect_otel-0.0.1/prefect_otel.egg-info/top_level.txt +1 -0
- prefect_otel-0.0.1/pyproject.toml +103 -0
- prefect_otel-0.0.1/setup.cfg +4 -0
- prefect_otel-0.0.1/tests/conftest.py +17 -0
- prefect_otel-0.0.1/tests/test_integration.py +190 -0
- prefect_otel-0.0.1/tests/test_plugin.py +219 -0
- prefect_otel-0.0.1/tests/test_settings.py +109 -0
- prefect_otel-0.0.1/uv.lock +3376 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches:
|
|
7
|
+
- main
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
checks:
|
|
11
|
+
name: Python ${{ matrix.python-version }}
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v6
|
|
20
|
+
|
|
21
|
+
- name: Set up uv
|
|
22
|
+
uses: astral-sh/setup-uv@v7
|
|
23
|
+
with:
|
|
24
|
+
enable-cache: true
|
|
25
|
+
python-version: ${{ matrix.python-version }}
|
|
26
|
+
cache-dependency-glob: pyproject.toml
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: uv sync --all-groups
|
|
30
|
+
|
|
31
|
+
- name: Check formatting
|
|
32
|
+
run: uv run ruff format --check .
|
|
33
|
+
|
|
34
|
+
- name: Lint
|
|
35
|
+
run: uv run ruff check .
|
|
36
|
+
|
|
37
|
+
- name: Type check
|
|
38
|
+
run: uv run mypy prefect_opentelemetry tests
|
|
39
|
+
|
|
40
|
+
- name: Test
|
|
41
|
+
run: uv run coverage run -m pytest
|
|
42
|
+
|
|
43
|
+
- name: Coverage
|
|
44
|
+
run: uv run coverage report
|
|
45
|
+
|
|
46
|
+
- name: Documentation coverage
|
|
47
|
+
run: uv run interrogate
|
|
48
|
+
|
|
49
|
+
- name: Build package
|
|
50
|
+
run: uv build
|
|
51
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
id-token: write
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
publish:
|
|
13
|
+
name: Publish to PyPI
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
environment:
|
|
16
|
+
name: pypi
|
|
17
|
+
url: https://pypi.org/p/prefect-otel
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v6
|
|
21
|
+
with:
|
|
22
|
+
fetch-depth: 0
|
|
23
|
+
|
|
24
|
+
- name: Set up uv
|
|
25
|
+
uses: astral-sh/setup-uv@v7
|
|
26
|
+
with:
|
|
27
|
+
enable-cache: true
|
|
28
|
+
python-version: "3.13"
|
|
29
|
+
cache-dependency-glob: pyproject.toml
|
|
30
|
+
|
|
31
|
+
- name: Build package
|
|
32
|
+
run: uv build
|
|
33
|
+
|
|
34
|
+
- name: Publish package
|
|
35
|
+
uses: pypa/gh-action-pypi-publish@v1.13.0
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
+
rev: v0.15.15
|
|
4
|
+
hooks:
|
|
5
|
+
- id: ruff-format
|
|
6
|
+
- id: ruff
|
|
7
|
+
args: [--fix]
|
|
8
|
+
- repo: https://github.com/econchick/interrogate
|
|
9
|
+
rev: 1.7.0
|
|
10
|
+
hooks:
|
|
11
|
+
- id: interrogate
|
|
12
|
+
args: [-vv]
|
|
13
|
+
pass_filenames: false
|
|
14
|
+
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
|
13
|
+
owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
21
|
+
|
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
23
|
+
permissions granted by this License.
|
|
24
|
+
|
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
|
26
|
+
but not limited to software source code, documentation source, and configuration
|
|
27
|
+
files.
|
|
28
|
+
|
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
30
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
31
|
+
generated documentation, and conversions to other media types.
|
|
32
|
+
|
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
34
|
+
made available under the License, as indicated by a copyright notice that is
|
|
35
|
+
included in or attached to the work (an example is provided in the Appendix
|
|
36
|
+
below).
|
|
37
|
+
|
|
38
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
|
39
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
40
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
41
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
42
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
43
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
44
|
+
|
|
45
|
+
"Contribution" shall mean any work of authorship, including the original version
|
|
46
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
|
47
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
|
48
|
+
by the copyright owner or by an individual or Legal Entity authorized to submit
|
|
49
|
+
on behalf of the copyright owner. For the purposes of this definition,
|
|
50
|
+
"submitted" means any form of electronic, verbal, or written communication sent
|
|
51
|
+
to the Licensor or its representatives, including but not limited to
|
|
52
|
+
communication on electronic mailing lists, source code control systems, and
|
|
53
|
+
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
|
54
|
+
the purpose of discussing and improving the Work, but excluding communication
|
|
55
|
+
that is conspicuously marked or otherwise designated in writing by the copyright
|
|
56
|
+
owner as "Not a Contribution."
|
|
57
|
+
|
|
58
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
59
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
60
|
+
incorporated within the Work.
|
|
61
|
+
|
|
62
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
63
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
64
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
65
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
66
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
67
|
+
Object form.
|
|
68
|
+
|
|
69
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
|
70
|
+
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
|
71
|
+
no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
|
72
|
+
license to make, have made, use, offer to sell, sell, import, and otherwise
|
|
73
|
+
transfer the Work, where such license applies only to those patent claims
|
|
74
|
+
licensable by such Contributor that are necessarily infringed by their
|
|
75
|
+
Contribution(s) alone or by combination of their Contribution(s) with the Work
|
|
76
|
+
to which such Contribution(s) was submitted. If You institute patent litigation
|
|
77
|
+
against any entity (including a cross-claim or counterclaim in a lawsuit)
|
|
78
|
+
alleging that the Work or a Contribution incorporated within the Work
|
|
79
|
+
constitutes direct or contributory patent infringement, then any patent licenses
|
|
80
|
+
granted to You under this License for that Work shall terminate as of the date
|
|
81
|
+
such litigation is filed.
|
|
82
|
+
|
|
83
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
84
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
85
|
+
Source or Object form, provided that You meet the following conditions:
|
|
86
|
+
|
|
87
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of
|
|
88
|
+
this License; and
|
|
89
|
+
|
|
90
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
91
|
+
You changed the files; and
|
|
92
|
+
|
|
93
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
94
|
+
distribute, all copyright, patent, trademark, and attribution notices from the
|
|
95
|
+
Source form of the Work, excluding those notices that do not pertain to any part
|
|
96
|
+
of the Derivative Works; and
|
|
97
|
+
|
|
98
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then
|
|
99
|
+
any Derivative Works that You distribute must include a readable copy of the
|
|
100
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
101
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
102
|
+
following places: within a NOTICE text file distributed as part of the
|
|
103
|
+
Derivative Works; within the Source form or documentation, if provided along
|
|
104
|
+
with the Derivative Works; or within a display generated by the Derivative
|
|
105
|
+
Works, if and wherever such third-party notices normally appear. The contents
|
|
106
|
+
of the NOTICE file are for informational purposes only and do not modify the
|
|
107
|
+
License. You may add Your own attribution notices within Derivative Works that
|
|
108
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
|
109
|
+
provided that such additional attribution notices cannot be construed as
|
|
110
|
+
modifying the License.
|
|
111
|
+
|
|
112
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
113
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
114
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
115
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
116
|
+
with the conditions stated in this License.
|
|
117
|
+
|
|
118
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
119
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
120
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
121
|
+
additional terms or conditions. Notwithstanding the above, nothing herein shall
|
|
122
|
+
supersede or modify the terms of any separate license agreement you may have
|
|
123
|
+
executed with Licensor regarding such Contributions.
|
|
124
|
+
|
|
125
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
126
|
+
trademarks, service marks, or product names of the Licensor, except as required
|
|
127
|
+
for reasonable and customary use in describing the origin of the Work and
|
|
128
|
+
reproducing the content of the NOTICE file.
|
|
129
|
+
|
|
130
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
131
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
132
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
133
|
+
KIND, either express or implied, including, without limitation, any warranties or
|
|
134
|
+
conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
135
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
136
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
137
|
+
associated with Your exercise of permissions under this License.
|
|
138
|
+
|
|
139
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
140
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
141
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
|
142
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
143
|
+
direct, indirect, special, incidental, or consequential damages of any character
|
|
144
|
+
arising as a result of this License or out of the use or inability to use the
|
|
145
|
+
Work (including but not limited to damages for loss of goodwill, work stoppage,
|
|
146
|
+
computer failure or malfunction, or any and all other commercial damages or
|
|
147
|
+
losses), even if such Contributor has been advised of the possibility of such
|
|
148
|
+
damages.
|
|
149
|
+
|
|
150
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
151
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
152
|
+
acceptance of support, warranty, indemnity, or other liability obligations
|
|
153
|
+
and/or rights consistent with this License. However, in accepting such
|
|
154
|
+
obligations, You may act only on Your own behalf and on Your sole
|
|
155
|
+
responsibility, not on behalf of any other Contributor, and only if You agree to
|
|
156
|
+
indemnify, defend, and hold each Contributor harmless for any liability incurred
|
|
157
|
+
by, or claims asserted against, such Contributor by reason of your accepting any
|
|
158
|
+
such warranty or additional liability.
|
|
159
|
+
|
|
160
|
+
END OF TERMS AND CONDITIONS
|
|
161
|
+
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: prefect-otel
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Experimental Prefect integration for OpenTelemetry auto-instrumentation.
|
|
5
|
+
Author-email: "Prefect Technologies, Inc." <help@prefect.io>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/prefectlabs/prefect-otel
|
|
8
|
+
Project-URL: Source, https://github.com/prefectlabs/prefect-otel
|
|
9
|
+
Project-URL: Tracker, https://github.com/prefectlabs/prefect-otel/issues
|
|
10
|
+
Keywords: prefect,opentelemetry,otel
|
|
11
|
+
Classifier: Natural Language :: English
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
21
|
+
Requires-Python: <3.15,>=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: prefect>=3.7.0
|
|
25
|
+
Requires-Dist: opentelemetry-distro<1.0.0,>=0.48b0
|
|
26
|
+
Requires-Dist: opentelemetry-exporter-otlp<2.0.0,>=1.27.0
|
|
27
|
+
Requires-Dist: opentelemetry-instrumentation<1.0.0,>=0.48b0
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# prefect-otel
|
|
31
|
+
|
|
32
|
+
`prefect-otel` is an experimental Prefect integration for OpenTelemetry.
|
|
33
|
+
|
|
34
|
+
This package provides a Prefect plugin hook that bootstraps OpenTelemetry
|
|
35
|
+
Python auto-instrumentation in Prefect flow-run subprocesses.
|
|
36
|
+
|
|
37
|
+
## Experimental Status
|
|
38
|
+
|
|
39
|
+
This package is experimental. Public settings, behavior, and compatibility
|
|
40
|
+
guarantees may change in breaking ways at any time.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install prefect-otel
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
OpenTelemetry automatic instrumentation still requires the normal
|
|
49
|
+
OpenTelemetry packages and instrumentation libraries. The package depends on
|
|
50
|
+
the OpenTelemetry distro and OTLP exporter, but users should still run
|
|
51
|
+
bootstrap in their target environment when they want library-specific
|
|
52
|
+
instrumentation:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
opentelemetry-bootstrap -a install
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
No flow code changes are required. The environment that actually executes your
|
|
61
|
+
flow must have:
|
|
62
|
+
|
|
63
|
+
- `prefect-otel` installed.
|
|
64
|
+
- Prefect plugins enabled with `PREFECT_PLUGINS_ENABLED=1`.
|
|
65
|
+
- Standard OpenTelemetry `OTEL_*` environment variables configured.
|
|
66
|
+
|
|
67
|
+
For deployed flows, this usually means the worker environment, job image,
|
|
68
|
+
virtual environment, or work pool job configuration used by the deployment.
|
|
69
|
+
|
|
70
|
+
Enable Prefect plugins in that same runtime:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
export PREFECT_PLUGINS_ENABLED=1
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Once Prefect loads this plugin, OpenTelemetry auto-instrumentation is enabled
|
|
77
|
+
by default.
|
|
78
|
+
|
|
79
|
+
Configure OpenTelemetry with standard `OTEL_*` environment variables in that
|
|
80
|
+
same runtime:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
export OTEL_SERVICE_NAME=my-prefect-flow
|
|
84
|
+
export OTEL_TRACES_EXPORTER=otlp
|
|
85
|
+
export OTEL_METRICS_EXPORTER=none
|
|
86
|
+
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
For a flow run directly from Python, set the same variables before starting the
|
|
90
|
+
process:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
python my_flow.py
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The plugin runs when Prefect is imported. By default, it calls OpenTelemetry's
|
|
97
|
+
programmatic auto-instrumentation initializer in each Prefect process. This
|
|
98
|
+
allows spawned flow-run subprocesses to configure OpenTelemetry from inherited
|
|
99
|
+
`OTEL_*` variables even though the parent process's in-memory SDK setup is not
|
|
100
|
+
inherited across Python `spawn`.
|
|
101
|
+
|
|
102
|
+
You do not need to call `opentelemetry-instrument` in a custom Prefect command
|
|
103
|
+
to use this package. If you already wrap a worker or application entrypoint
|
|
104
|
+
with `opentelemetry-instrument`, you can keep that wrapper; this integration
|
|
105
|
+
handles Prefect processes that are started later from the inherited
|
|
106
|
+
environment.
|
|
107
|
+
|
|
108
|
+
### Deployment Job Variables
|
|
109
|
+
|
|
110
|
+
For deployments, set these variables in `job_variables.env` so the process that
|
|
111
|
+
runs your flow receives them:
|
|
112
|
+
|
|
113
|
+
```yaml
|
|
114
|
+
deployments:
|
|
115
|
+
- name: my-deployment
|
|
116
|
+
entrypoint: flows.py:my_flow
|
|
117
|
+
work_pool:
|
|
118
|
+
name: my-pool
|
|
119
|
+
job_variables:
|
|
120
|
+
env:
|
|
121
|
+
PREFECT_PLUGINS_ENABLED: "1"
|
|
122
|
+
OTEL_SERVICE_NAME: "my-prefect-flow"
|
|
123
|
+
OTEL_TRACES_EXPORTER: "otlp"
|
|
124
|
+
OTEL_METRICS_EXPORTER: "none"
|
|
125
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector:4317"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
If you create deployments from Python, pass the same environment variables in
|
|
129
|
+
`job_variables`:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from prefect import flow
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@flow
|
|
136
|
+
def my_flow() -> None:
|
|
137
|
+
...
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
if __name__ == "__main__":
|
|
141
|
+
my_flow.deploy(
|
|
142
|
+
name="my-deployment",
|
|
143
|
+
work_pool_name="my-pool",
|
|
144
|
+
job_variables={
|
|
145
|
+
"env": {
|
|
146
|
+
"PREFECT_PLUGINS_ENABLED": "1",
|
|
147
|
+
"OTEL_SERVICE_NAME": "my-prefect-flow",
|
|
148
|
+
"OTEL_TRACES_EXPORTER": "otlp",
|
|
149
|
+
"OTEL_METRICS_EXPORTER": "none",
|
|
150
|
+
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://otel-collector:4317",
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
These examples configure OTLP trace export and disable metric export. Adjust the
|
|
157
|
+
`OTEL_*` values for your collector, exporter, and telemetry pipeline.
|
|
158
|
+
|
|
159
|
+
Common places to set them:
|
|
160
|
+
|
|
161
|
+
- Deployment `job_variables.env`.
|
|
162
|
+
- Work pool default job variables.
|
|
163
|
+
- Container image entrypoints or Kubernetes, Docker, ECS, Cloud Run, or other
|
|
164
|
+
job environment settings.
|
|
165
|
+
|
|
166
|
+
For a container image, install the package and OpenTelemetry instrumentation in
|
|
167
|
+
the image that will run flows:
|
|
168
|
+
|
|
169
|
+
```dockerfile
|
|
170
|
+
FROM prefecthq/prefect:3-python3.12
|
|
171
|
+
|
|
172
|
+
RUN pip install prefect-otel \
|
|
173
|
+
&& opentelemetry-bootstrap -a install
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
The image installs the package and instrumentation libraries. The deployment
|
|
177
|
+
or work pool still needs the `job_variables.env` values shown above so the
|
|
178
|
+
flow process can configure OpenTelemetry at runtime.
|
|
179
|
+
|
|
180
|
+
### Disable Auto-Instrumentation
|
|
181
|
+
|
|
182
|
+
To disable the integration without uninstalling it, set:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
export PREFECT_INTEGRATIONS_OTEL_AUTO_INSTRUMENT=false
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Settings
|
|
189
|
+
|
|
190
|
+
Settings follow Prefect integration naming conventions and can be configured
|
|
191
|
+
with environment variables, `.env`, `prefect.toml`, or `pyproject.toml`.
|
|
192
|
+
|
|
193
|
+
| Setting | Environment variable | Default |
|
|
194
|
+
| --- | --- | --- |
|
|
195
|
+
| `auto_instrument` | `PREFECT_INTEGRATIONS_OTEL_AUTO_INSTRUMENT` | `true` |
|
|
196
|
+
| `require_auto_instrument` | `PREFECT_INTEGRATIONS_OTEL_REQUIRE_AUTO_INSTRUMENT` | `false` |
|
|
197
|
+
|
|
198
|
+
`prefect.toml`:
|
|
199
|
+
|
|
200
|
+
```toml
|
|
201
|
+
[integrations.otel]
|
|
202
|
+
auto_instrument = false
|
|
203
|
+
require_auto_instrument = false
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
`pyproject.toml`:
|
|
207
|
+
|
|
208
|
+
```toml
|
|
209
|
+
[tool.prefect.integrations.otel]
|
|
210
|
+
auto_instrument = false
|
|
211
|
+
require_auto_instrument = false
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
If `require_auto_instrument` is true, initialization failures are re-raised.
|
|
215
|
+
Use this with `PREFECT_PLUGINS_STRICT=1` when startup should fail instead of
|
|
216
|
+
running without OpenTelemetry auto-instrumentation:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
export PREFECT_PLUGINS_STRICT=1
|
|
220
|
+
export PREFECT_INTEGRATIONS_OTEL_REQUIRE_AUTO_INSTRUMENT=true
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Diagnostics
|
|
224
|
+
|
|
225
|
+
Prefect can show plugin discovery and hook results:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
prefect plugins diagnose
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
If traces are missing, check that:
|
|
232
|
+
|
|
233
|
+
- `prefect-otel` is installed in the environment that runs the flow, not just
|
|
234
|
+
in the environment where the deployment was built.
|
|
235
|
+
- `PREFECT_PLUGINS_ENABLED=1` is set where the flow code runs.
|
|
236
|
+
- The `OTEL_*` variables are inherited by the flow-run process.
|
|
237
|
+
- The relevant OpenTelemetry instrumentation libraries are installed.
|
|
238
|
+
- Your collector or exporter endpoint is reachable from the flow-run
|
|
239
|
+
environment.
|