traceAI-temporal 0.1.0__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.
- traceai_temporal-0.1.0/.gitignore +87 -0
- traceai_temporal-0.1.0/LICENSE +201 -0
- traceai_temporal-0.1.0/NOTICE +7 -0
- traceai_temporal-0.1.0/PKG-INFO +191 -0
- traceai_temporal-0.1.0/README.md +168 -0
- traceai_temporal-0.1.0/pyproject.toml +38 -0
- traceai_temporal-0.1.0/tests/conftest.py +40 -0
- traceai_temporal-0.1.0/tests/test_adapter.py +298 -0
- traceai_temporal-0.1.0/tests/test_ceilings.py +75 -0
- traceai_temporal-0.1.0/tests/test_diagnostics.py +77 -0
- traceai_temporal-0.1.0/tests/test_example.py +72 -0
- traceai_temporal-0.1.0/tests/test_native.py +215 -0
- traceai_temporal-0.1.0/tests/test_public_exporter.py +19 -0
- traceai_temporal-0.1.0/tests/test_wire.py +180 -0
- traceai_temporal-0.1.0/tests/workflow_case.py +28 -0
- traceai_temporal-0.1.0/traceai_temporal/__init__.py +14 -0
- traceai_temporal-0.1.0/traceai_temporal/_configure.py +282 -0
- traceai_temporal-0.1.0/traceai_temporal/_privacy.py +298 -0
- traceai_temporal-0.1.0/traceai_temporal/_session.py +58 -0
- traceai_temporal-0.1.0/traceai_temporal/py.typed +0 -0
- traceai_temporal-0.1.0/traceai_temporal/version.py +1 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
*.py[cod]
|
|
2
|
+
|
|
3
|
+
# C extensions
|
|
4
|
+
*.so
|
|
5
|
+
|
|
6
|
+
# IDEs
|
|
7
|
+
.idea/
|
|
8
|
+
.vscode/
|
|
9
|
+
|
|
10
|
+
# Packages
|
|
11
|
+
*.egg
|
|
12
|
+
*.egg-info
|
|
13
|
+
.eggs/
|
|
14
|
+
# build
|
|
15
|
+
parts
|
|
16
|
+
bin
|
|
17
|
+
var
|
|
18
|
+
sdist
|
|
19
|
+
dist
|
|
20
|
+
develop-eggs
|
|
21
|
+
.installed.cfg
|
|
22
|
+
lib
|
|
23
|
+
lib64
|
|
24
|
+
|
|
25
|
+
# Installer logs
|
|
26
|
+
pip-log.txt
|
|
27
|
+
|
|
28
|
+
# Unit test / coverage reports
|
|
29
|
+
.coverage
|
|
30
|
+
.tox
|
|
31
|
+
nosetests.xml
|
|
32
|
+
|
|
33
|
+
# Complexity
|
|
34
|
+
output/*.html
|
|
35
|
+
output/*/index.html
|
|
36
|
+
|
|
37
|
+
# Sphinx
|
|
38
|
+
docs/_build
|
|
39
|
+
|
|
40
|
+
# Cookiecutter
|
|
41
|
+
output/
|
|
42
|
+
|
|
43
|
+
.workon
|
|
44
|
+
|
|
45
|
+
**.wav
|
|
46
|
+
**.joblib
|
|
47
|
+
|
|
48
|
+
**/__pycache__
|
|
49
|
+
|
|
50
|
+
#Excel files
|
|
51
|
+
*.xlsx
|
|
52
|
+
#csv files
|
|
53
|
+
*.csv
|
|
54
|
+
#virtual environments
|
|
55
|
+
**/.venv
|
|
56
|
+
**/env
|
|
57
|
+
**/.env
|
|
58
|
+
*.DS_Store
|
|
59
|
+
*.pdf
|
|
60
|
+
**/node_modules
|
|
61
|
+
**/dist
|
|
62
|
+
*.log
|
|
63
|
+
.DS_Store
|
|
64
|
+
**/package-lock.json
|
|
65
|
+
# Standalone npm example (outside the pnpm workspace): its lockfile pins the tested dependency set.
|
|
66
|
+
!typescript/examples/tanstack-ai/package-lock.json
|
|
67
|
+
**/tsconfig.tsbuildinfo
|
|
68
|
+
**/.fi
|
|
69
|
+
**/.pytest_cache
|
|
70
|
+
planning/
|
|
71
|
+
|
|
72
|
+
# Java build artifacts
|
|
73
|
+
**/target/
|
|
74
|
+
**/.settings/
|
|
75
|
+
**/.project
|
|
76
|
+
**/.classpath
|
|
77
|
+
**/.factorypath
|
|
78
|
+
*.class
|
|
79
|
+
*.jar
|
|
80
|
+
*.war
|
|
81
|
+
|
|
82
|
+
# C# build artifacts
|
|
83
|
+
**/bin/
|
|
84
|
+
**/obj/
|
|
85
|
+
|
|
86
|
+
# Python
|
|
87
|
+
**/uv.lock
|
|
@@ -0,0 +1,201 @@
|
|
|
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,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may accept and charge a
|
|
167
|
+
fee for acceptance of support, warranty, indemnity, or other liability
|
|
168
|
+
obligations and/or rights consistent with this License. However, in
|
|
169
|
+
accepting such obligations, You may act only on Your own behalf and on
|
|
170
|
+
Your sole responsibility, not on behalf of any other Contributor, and
|
|
171
|
+
only if You agree to indemnify, defend, and hold each Contributor
|
|
172
|
+
harmless for any liability incurred by, or claims asserted against,
|
|
173
|
+
such Contributor by reason of your accepting any such warranty or
|
|
174
|
+
additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024-2026 Future AGI, Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
traceAI
|
|
2
|
+
Copyright (c) 2024-2026 Future AGI, Inc.
|
|
3
|
+
|
|
4
|
+
This product is part of the Future AGI open-source ecosystem
|
|
5
|
+
(https://github.com/future-agi/future-agi) and is licensed under the Apache
|
|
6
|
+
License, Version 2.0 (the "License"). See the LICENSE file for the full
|
|
7
|
+
license text, or obtain a copy at http://www.apache.org/licenses/LICENSE-2.0.
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: traceAI-temporal
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Future AGI configuration for Temporal's native replay-safe OpenTelemetry tracing
|
|
5
|
+
Project-URL: Repository, https://github.com/future-agi/traceAI/tree/dev/python/frameworks/temporal
|
|
6
|
+
Project-URL: Documentation, https://docs.futureagi.com/docs/integrations/frameworks/temporal
|
|
7
|
+
Author-email: Future AGI <no-reply@futureagi.com>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: NOTICE
|
|
11
|
+
Requires-Python: <3.14,>=3.10
|
|
12
|
+
Requires-Dist: fi-instrumentation-otel<2,>=1.2.2
|
|
13
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http<2,>=1.39
|
|
14
|
+
Requires-Dist: opentelemetry-sdk<2,>=1.39
|
|
15
|
+
Requires-Dist: temporalio[opentelemetry]<1.36,>=1.34
|
|
16
|
+
Requires-Dist: typing-extensions<5,>=4.5
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: build<2,>=1.2; extra == 'dev'
|
|
19
|
+
Requires-Dist: hatchling<2,>=1.27; extra == 'dev'
|
|
20
|
+
Requires-Dist: mypy<2,>=1.15; extra == 'dev'
|
|
21
|
+
Requires-Dist: pytest<9,>=8; extra == 'dev'
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# traceAI Temporal
|
|
25
|
+
|
|
26
|
+
Send Temporal's native workflow and activity spans to Future AGI, with model and tool spans nested inside the activities that run them. The package configures Temporal's replay-safe OpenTelemetry provider; it does not replace Temporal's instrumentation or create duplicate workflow spans.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
Use Python 3.10–3.13 and Temporal Python SDK 1.34 or 1.35.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install "traceAI-temporal==0.1.0"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Temporal marks its OpenTelemetry plugin and replay-safe provider as experimental. This package restricts the SDK range to the supported minor versions.
|
|
37
|
+
|
|
38
|
+
## Configure
|
|
39
|
+
|
|
40
|
+
Set the same project in the starter and worker processes. Supply your keys through your deployment's environment or secret manager.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
export FI_PROJECT_NAME=temporal-orders
|
|
44
|
+
export FI_API_KEY='<your-api-key>'
|
|
45
|
+
export FI_SECRET_KEY='<your-secret-key>'
|
|
46
|
+
# Optional, for a self-hosted deployment:
|
|
47
|
+
# export FI_BASE_URL=https://your-futureagi-host
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Call `configure()` once in each process, **before connecting the client**. Do not also call `fi_instrumentation.register()` or install another global tracer provider.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from temporalio.client import Client
|
|
54
|
+
from traceai_temporal import configure
|
|
55
|
+
|
|
56
|
+
telemetry = configure()
|
|
57
|
+
client = await Client.connect("localhost:7233", plugins=[telemetry.plugin])
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Workers created from this client inherit the native plugin. Do not add it to the worker again. The plugin enables Temporal's workflow and activity spans by default.
|
|
61
|
+
|
|
62
|
+
## Run a workflow
|
|
63
|
+
|
|
64
|
+
Start your Temporal cluster or a local [Temporal dev server](https://docs.temporal.io/cli):
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
temporal server start-dev
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Keep workflow code deterministic. Save this ordinary workflow as `workflows.py`; it must not import the exporter, this package, or a model SDK.
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from datetime import timedelta
|
|
74
|
+
from temporalio import workflow
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@workflow.defn
|
|
78
|
+
class OrderWorkflow:
|
|
79
|
+
@workflow.run
|
|
80
|
+
async def run(self, quantity: int) -> str:
|
|
81
|
+
return await workflow.execute_activity(
|
|
82
|
+
"price_order",
|
|
83
|
+
quantity,
|
|
84
|
+
start_to_close_timeout=timedelta(seconds=10),
|
|
85
|
+
)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Save the worker and starter as `app.py`. This example runs them in one process; separate deployments use the same `configure()` and client setup in each process.
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
import asyncio
|
|
92
|
+
import uuid
|
|
93
|
+
from opentelemetry import trace
|
|
94
|
+
from temporalio import activity
|
|
95
|
+
from temporalio.client import Client
|
|
96
|
+
from temporalio.worker import Worker
|
|
97
|
+
from traceai_temporal import configure
|
|
98
|
+
from workflows import OrderWorkflow
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@activity.defn
|
|
102
|
+
async def price_order(quantity: int) -> str:
|
|
103
|
+
with trace.get_tracer("orders").start_as_current_span(
|
|
104
|
+
"calculate-price", attributes={"gen_ai.span.kind": "tool"}
|
|
105
|
+
):
|
|
106
|
+
return f"EUR {quantity * 21}"
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
async def main():
|
|
110
|
+
telemetry = configure()
|
|
111
|
+
try:
|
|
112
|
+
client = await Client.connect("localhost:7233", plugins=[telemetry.plugin])
|
|
113
|
+
async with Worker(
|
|
114
|
+
client,
|
|
115
|
+
task_queue="orders",
|
|
116
|
+
workflows=[OrderWorkflow],
|
|
117
|
+
activities=[price_order],
|
|
118
|
+
):
|
|
119
|
+
result = await client.execute_workflow(
|
|
120
|
+
OrderWorkflow.run,
|
|
121
|
+
2,
|
|
122
|
+
id=f"order-{uuid.uuid4().hex}",
|
|
123
|
+
task_queue="orders",
|
|
124
|
+
)
|
|
125
|
+
print(result)
|
|
126
|
+
finally:
|
|
127
|
+
# Stop workers first. These methods return False if the time budget expires.
|
|
128
|
+
if not telemetry.shutdown(timeout_millis=3000):
|
|
129
|
+
print("Tracing shutdown timed out; the final batch may be lost")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
asyncio.run(main())
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
python app.py
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
In Future AGI, open **Observe**, select `temporal-orders`, and open the latest `StartWorkflow:OrderWorkflow` trace. It contains `RunWorkflow`, `StartActivity`, `RunActivity`, and `calculate-price`. The workflow ID is the session ID, including on nested tool/model spans and signal handlers.
|
|
140
|
+
|
|
141
|
+
## Add model tracing inside activities
|
|
142
|
+
|
|
143
|
+
Temporal's plugin does not trace model requests. Install the traceAI package for your model SDK and instrument it **once**, using `telemetry.provider`. For example, with `traceAI-openai` installed:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from traceai_openai import OpenAIInstrumentor
|
|
147
|
+
|
|
148
|
+
OpenAIInstrumentor().instrument(tracer_provider=telemetry.provider)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Make model calls only inside activities, not replayed workflow code. Provider spans keep their model, token usage, and span kind; the adapter does not copy token totals onto workflow or activity parents. Do not instrument the same model call through two packages.
|
|
152
|
+
|
|
153
|
+
## Privacy
|
|
154
|
+
|
|
155
|
+
The default is **metadata only**: workflow/run/activity IDs, span names and timing, status, model/tool identifiers, token counts, and explicit session/user IDs. Unknown attributes, content, arbitrary events, status text, and exception messages are removed before this destination exports. Exception types remain. Exception stack attributes are always removed, including with content enabled. Resource and scope attributes are filtered, and link attributes and trace state are removed.
|
|
156
|
+
|
|
157
|
+
Use opaque workflow IDs and user IDs. Span names, instrumentation-scope names, and allowed metadata values are not secret scanners; do not put prompts, emails, paths, or credentials in them.
|
|
158
|
+
|
|
159
|
+
To include supported input/output and message attributes, opt in in both processes as needed:
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
telemetry = configure(capture_content=True)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Error text needs a second explicit opt-in, `keep_error_text=True`, together with `capture_content=True`. The core `FI_HIDE_*` settings remain privacy ceilings; `FI_HIDE_ERROR_DETAILS=true` still removes error text. Content values are capped at 16,384 characters by default. The adapter cannot recover content that your instrumentor did not record, and opt-in content can contain sensitive data.
|
|
166
|
+
|
|
167
|
+
The policy applies to this exporter only. It does not redact Temporal history, application logs, or other exporters you attach. It does not propagate user identity across Temporal's process boundary: attach explicit user IDs in activities if needed. Application-supplied `session.id` takes precedence over the workflow ID.
|
|
168
|
+
|
|
169
|
+
## Configuration and lifecycle
|
|
170
|
+
|
|
171
|
+
- `project_name`, `api_key`, `secret_key`, `base_url` override the corresponding `FI_*` environment values. `base_url` is the origin (optionally with a deployment prefix), not the traces URL; the package appends `/tracer/v1/traces`.
|
|
172
|
+
- The destination uses upstream OTLP/HTTP **protobuf** with no compression. Set `compression="gzip"` for Future AGI Cloud or self-hosted v1.56.0 and later. Remote endpoints require HTTPS; plain HTTP is allowed only for loopback collectors.
|
|
173
|
+
- `exporter=` accepts an application-supplied OpenTelemetry `SpanExporter` in place of endpoint/auth settings. It still receives filtered spans and is shut down by the handle.
|
|
174
|
+
- The batch queue holds at most 2,048 spans, with batches of at most 512 and a 1-second schedule. Set `max_queue_size`, `max_export_batch_size`, and `schedule_delay_millis` to tune them. A full queue drops spans rather than blocking an activity.
|
|
175
|
+
- `export_timeout` defaults to 3 seconds per HTTP export. `telemetry.force_flush(timeout_millis=3000)` and `telemetry.shutdown(timeout_millis=3000)` bound the caller's wait and return a boolean. On timeout, an in-flight daemon export can finish later; delivery is not guaranteed. Neither method ends unfinished workflow spans.
|
|
176
|
+
- Normal interpreter exit has a bounded shutdown fallback. Explicitly shut down after stopping the worker. Crashes, forced exits, and container freezes can lose buffered spans. In an async server, use `await asyncio.to_thread(telemetry.shutdown)` to avoid blocking its event loop while waiting.
|
|
177
|
+
- Do not configure again after shutdown: OpenTelemetry does not allow replacing its process-global provider. Construct worker processes after forking, then configure each process.
|
|
178
|
+
|
|
179
|
+
## Troubleshooting
|
|
180
|
+
|
|
181
|
+
**The worker rejects the global tracer provider.** Call this package's `configure()` before `Client.connect()`. Do not use the ordinary `register()` provider with Temporal's replay-safe plugin.
|
|
182
|
+
|
|
183
|
+
**Model spans start separate traces.** Configure the plugin on both clients and pass `telemetry.provider` to the model instrumentor. Keep calls inside activities.
|
|
184
|
+
|
|
185
|
+
**A workflow fails sandbox validation.** Move tracing setup and model imports into the worker/activity module. The workflow module should import only deterministic workflow dependencies and refer to activities by name.
|
|
186
|
+
|
|
187
|
+
**No spans appear, or the trace splits across projects.** Check both key headers, the base URL, and that starter and worker use the same `FI_PROJECT_NAME`. Flush short-lived starters before exit. A running workflow's `RunWorkflow` span is exported only when it ends.
|
|
188
|
+
|
|
189
|
+
## Limits
|
|
190
|
+
|
|
191
|
+
This integration covers the Python native plugin's workflow/activity hierarchy, activity retries, signal sessions, and history replay. It does not configure Temporal metrics/logs, cluster authentication, or model instrumentation. Native Temporal spans remain runtime spans rather than being relabeled as model calls. Each activity attempt is a distinct span; no attempt number is synthesized. Temporal owns deterministic IDs and replay suppression, not exactly-once delivery to Future AGI. Child workflows, continue-as-new, Nexus, and standalone activities are not additional compatibility guarantees of this package.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# traceAI Temporal
|
|
2
|
+
|
|
3
|
+
Send Temporal's native workflow and activity spans to Future AGI, with model and tool spans nested inside the activities that run them. The package configures Temporal's replay-safe OpenTelemetry provider; it does not replace Temporal's instrumentation or create duplicate workflow spans.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Use Python 3.10–3.13 and Temporal Python SDK 1.34 or 1.35.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install "traceAI-temporal==0.1.0"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Temporal marks its OpenTelemetry plugin and replay-safe provider as experimental. This package restricts the SDK range to the supported minor versions.
|
|
14
|
+
|
|
15
|
+
## Configure
|
|
16
|
+
|
|
17
|
+
Set the same project in the starter and worker processes. Supply your keys through your deployment's environment or secret manager.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
export FI_PROJECT_NAME=temporal-orders
|
|
21
|
+
export FI_API_KEY='<your-api-key>'
|
|
22
|
+
export FI_SECRET_KEY='<your-secret-key>'
|
|
23
|
+
# Optional, for a self-hosted deployment:
|
|
24
|
+
# export FI_BASE_URL=https://your-futureagi-host
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Call `configure()` once in each process, **before connecting the client**. Do not also call `fi_instrumentation.register()` or install another global tracer provider.
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from temporalio.client import Client
|
|
31
|
+
from traceai_temporal import configure
|
|
32
|
+
|
|
33
|
+
telemetry = configure()
|
|
34
|
+
client = await Client.connect("localhost:7233", plugins=[telemetry.plugin])
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Workers created from this client inherit the native plugin. Do not add it to the worker again. The plugin enables Temporal's workflow and activity spans by default.
|
|
38
|
+
|
|
39
|
+
## Run a workflow
|
|
40
|
+
|
|
41
|
+
Start your Temporal cluster or a local [Temporal dev server](https://docs.temporal.io/cli):
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
temporal server start-dev
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Keep workflow code deterministic. Save this ordinary workflow as `workflows.py`; it must not import the exporter, this package, or a model SDK.
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from datetime import timedelta
|
|
51
|
+
from temporalio import workflow
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@workflow.defn
|
|
55
|
+
class OrderWorkflow:
|
|
56
|
+
@workflow.run
|
|
57
|
+
async def run(self, quantity: int) -> str:
|
|
58
|
+
return await workflow.execute_activity(
|
|
59
|
+
"price_order",
|
|
60
|
+
quantity,
|
|
61
|
+
start_to_close_timeout=timedelta(seconds=10),
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Save the worker and starter as `app.py`. This example runs them in one process; separate deployments use the same `configure()` and client setup in each process.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import asyncio
|
|
69
|
+
import uuid
|
|
70
|
+
from opentelemetry import trace
|
|
71
|
+
from temporalio import activity
|
|
72
|
+
from temporalio.client import Client
|
|
73
|
+
from temporalio.worker import Worker
|
|
74
|
+
from traceai_temporal import configure
|
|
75
|
+
from workflows import OrderWorkflow
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@activity.defn
|
|
79
|
+
async def price_order(quantity: int) -> str:
|
|
80
|
+
with trace.get_tracer("orders").start_as_current_span(
|
|
81
|
+
"calculate-price", attributes={"gen_ai.span.kind": "tool"}
|
|
82
|
+
):
|
|
83
|
+
return f"EUR {quantity * 21}"
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
async def main():
|
|
87
|
+
telemetry = configure()
|
|
88
|
+
try:
|
|
89
|
+
client = await Client.connect("localhost:7233", plugins=[telemetry.plugin])
|
|
90
|
+
async with Worker(
|
|
91
|
+
client,
|
|
92
|
+
task_queue="orders",
|
|
93
|
+
workflows=[OrderWorkflow],
|
|
94
|
+
activities=[price_order],
|
|
95
|
+
):
|
|
96
|
+
result = await client.execute_workflow(
|
|
97
|
+
OrderWorkflow.run,
|
|
98
|
+
2,
|
|
99
|
+
id=f"order-{uuid.uuid4().hex}",
|
|
100
|
+
task_queue="orders",
|
|
101
|
+
)
|
|
102
|
+
print(result)
|
|
103
|
+
finally:
|
|
104
|
+
# Stop workers first. These methods return False if the time budget expires.
|
|
105
|
+
if not telemetry.shutdown(timeout_millis=3000):
|
|
106
|
+
print("Tracing shutdown timed out; the final batch may be lost")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
asyncio.run(main())
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
python app.py
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
In Future AGI, open **Observe**, select `temporal-orders`, and open the latest `StartWorkflow:OrderWorkflow` trace. It contains `RunWorkflow`, `StartActivity`, `RunActivity`, and `calculate-price`. The workflow ID is the session ID, including on nested tool/model spans and signal handlers.
|
|
117
|
+
|
|
118
|
+
## Add model tracing inside activities
|
|
119
|
+
|
|
120
|
+
Temporal's plugin does not trace model requests. Install the traceAI package for your model SDK and instrument it **once**, using `telemetry.provider`. For example, with `traceAI-openai` installed:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from traceai_openai import OpenAIInstrumentor
|
|
124
|
+
|
|
125
|
+
OpenAIInstrumentor().instrument(tracer_provider=telemetry.provider)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Make model calls only inside activities, not replayed workflow code. Provider spans keep their model, token usage, and span kind; the adapter does not copy token totals onto workflow or activity parents. Do not instrument the same model call through two packages.
|
|
129
|
+
|
|
130
|
+
## Privacy
|
|
131
|
+
|
|
132
|
+
The default is **metadata only**: workflow/run/activity IDs, span names and timing, status, model/tool identifiers, token counts, and explicit session/user IDs. Unknown attributes, content, arbitrary events, status text, and exception messages are removed before this destination exports. Exception types remain. Exception stack attributes are always removed, including with content enabled. Resource and scope attributes are filtered, and link attributes and trace state are removed.
|
|
133
|
+
|
|
134
|
+
Use opaque workflow IDs and user IDs. Span names, instrumentation-scope names, and allowed metadata values are not secret scanners; do not put prompts, emails, paths, or credentials in them.
|
|
135
|
+
|
|
136
|
+
To include supported input/output and message attributes, opt in in both processes as needed:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
telemetry = configure(capture_content=True)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Error text needs a second explicit opt-in, `keep_error_text=True`, together with `capture_content=True`. The core `FI_HIDE_*` settings remain privacy ceilings; `FI_HIDE_ERROR_DETAILS=true` still removes error text. Content values are capped at 16,384 characters by default. The adapter cannot recover content that your instrumentor did not record, and opt-in content can contain sensitive data.
|
|
143
|
+
|
|
144
|
+
The policy applies to this exporter only. It does not redact Temporal history, application logs, or other exporters you attach. It does not propagate user identity across Temporal's process boundary: attach explicit user IDs in activities if needed. Application-supplied `session.id` takes precedence over the workflow ID.
|
|
145
|
+
|
|
146
|
+
## Configuration and lifecycle
|
|
147
|
+
|
|
148
|
+
- `project_name`, `api_key`, `secret_key`, `base_url` override the corresponding `FI_*` environment values. `base_url` is the origin (optionally with a deployment prefix), not the traces URL; the package appends `/tracer/v1/traces`.
|
|
149
|
+
- The destination uses upstream OTLP/HTTP **protobuf** with no compression. Set `compression="gzip"` for Future AGI Cloud or self-hosted v1.56.0 and later. Remote endpoints require HTTPS; plain HTTP is allowed only for loopback collectors.
|
|
150
|
+
- `exporter=` accepts an application-supplied OpenTelemetry `SpanExporter` in place of endpoint/auth settings. It still receives filtered spans and is shut down by the handle.
|
|
151
|
+
- The batch queue holds at most 2,048 spans, with batches of at most 512 and a 1-second schedule. Set `max_queue_size`, `max_export_batch_size`, and `schedule_delay_millis` to tune them. A full queue drops spans rather than blocking an activity.
|
|
152
|
+
- `export_timeout` defaults to 3 seconds per HTTP export. `telemetry.force_flush(timeout_millis=3000)` and `telemetry.shutdown(timeout_millis=3000)` bound the caller's wait and return a boolean. On timeout, an in-flight daemon export can finish later; delivery is not guaranteed. Neither method ends unfinished workflow spans.
|
|
153
|
+
- Normal interpreter exit has a bounded shutdown fallback. Explicitly shut down after stopping the worker. Crashes, forced exits, and container freezes can lose buffered spans. In an async server, use `await asyncio.to_thread(telemetry.shutdown)` to avoid blocking its event loop while waiting.
|
|
154
|
+
- Do not configure again after shutdown: OpenTelemetry does not allow replacing its process-global provider. Construct worker processes after forking, then configure each process.
|
|
155
|
+
|
|
156
|
+
## Troubleshooting
|
|
157
|
+
|
|
158
|
+
**The worker rejects the global tracer provider.** Call this package's `configure()` before `Client.connect()`. Do not use the ordinary `register()` provider with Temporal's replay-safe plugin.
|
|
159
|
+
|
|
160
|
+
**Model spans start separate traces.** Configure the plugin on both clients and pass `telemetry.provider` to the model instrumentor. Keep calls inside activities.
|
|
161
|
+
|
|
162
|
+
**A workflow fails sandbox validation.** Move tracing setup and model imports into the worker/activity module. The workflow module should import only deterministic workflow dependencies and refer to activities by name.
|
|
163
|
+
|
|
164
|
+
**No spans appear, or the trace splits across projects.** Check both key headers, the base URL, and that starter and worker use the same `FI_PROJECT_NAME`. Flush short-lived starters before exit. A running workflow's `RunWorkflow` span is exported only when it ends.
|
|
165
|
+
|
|
166
|
+
## Limits
|
|
167
|
+
|
|
168
|
+
This integration covers the Python native plugin's workflow/activity hierarchy, activity retries, signal sessions, and history replay. It does not configure Temporal metrics/logs, cluster authentication, or model instrumentation. Native Temporal spans remain runtime spans rather than being relabeled as model calls. Each activity attempt is a distinct span; no attempt number is synthesized. Temporal owns deterministic IDs and replay suppression, not exactly-once delivery to Future AGI. Child workflows, continue-as-new, Nexus, and standalone activities are not additional compatibility guarantees of this package.
|