mainwave 0.1.0rc1__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.
- mainwave-0.1.0rc1/.gitignore +10 -0
- mainwave-0.1.0rc1/LICENSE +202 -0
- mainwave-0.1.0rc1/PKG-INFO +147 -0
- mainwave-0.1.0rc1/README.md +78 -0
- mainwave-0.1.0rc1/pyproject.toml +97 -0
- mainwave-0.1.0rc1/src/mainwave/__init__.py +133 -0
- mainwave-0.1.0rc1/src/mainwave/_anthropic_thinking.py +164 -0
- mainwave-0.1.0rc1/src/mainwave/_config.py +302 -0
- mainwave-0.1.0rc1/src/mainwave/_errors.py +15 -0
- mainwave-0.1.0rc1/src/mainwave/_exporter.py +318 -0
- mainwave-0.1.0rc1/src/mainwave/_flush.py +67 -0
- mainwave-0.1.0rc1/src/mainwave/_instrumentors.py +130 -0
- mainwave-0.1.0rc1/src/mainwave/_processors.py +107 -0
- mainwave-0.1.0rc1/src/mainwave/_runtime.py +274 -0
- mainwave-0.1.0rc1/src/mainwave/langchain.py +632 -0
- mainwave-0.1.0rc1/src/mainwave/py.typed +0 -0
- mainwave-0.1.0rc1/src/mainwave/testing.py +70 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mainwave
|
|
3
|
+
Version: 0.1.0rc1
|
|
4
|
+
Summary: Python SDK for the Mainwave AI observability platform
|
|
5
|
+
Project-URL: Homepage, https://mainwave.ai
|
|
6
|
+
Project-URL: Repository, https://github.com/mainwaveai/mainwave
|
|
7
|
+
Project-URL: Issues, https://github.com/mainwaveai/mainwave/issues
|
|
8
|
+
Author: Mainwave AI
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agents,llm,mainwave,observability,openinference,opentelemetry,tracing
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Topic :: System :: Monitoring
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: opentelemetry-api>=1.27
|
|
25
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.27
|
|
26
|
+
Requires-Dist: opentelemetry-sdk>=1.27
|
|
27
|
+
Provides-Extra: all
|
|
28
|
+
Requires-Dist: langchain-core; extra == 'all'
|
|
29
|
+
Requires-Dist: openinference-instrumentation-anthropic; extra == 'all'
|
|
30
|
+
Requires-Dist: openinference-instrumentation-bedrock; extra == 'all'
|
|
31
|
+
Requires-Dist: openinference-instrumentation-crewai; extra == 'all'
|
|
32
|
+
Requires-Dist: openinference-instrumentation-google-genai; extra == 'all'
|
|
33
|
+
Requires-Dist: openinference-instrumentation-groq; extra == 'all'
|
|
34
|
+
Requires-Dist: openinference-instrumentation-langchain; extra == 'all'
|
|
35
|
+
Requires-Dist: openinference-instrumentation-litellm; extra == 'all'
|
|
36
|
+
Requires-Dist: openinference-instrumentation-llama-index; extra == 'all'
|
|
37
|
+
Requires-Dist: openinference-instrumentation-mistralai; extra == 'all'
|
|
38
|
+
Requires-Dist: openinference-instrumentation-openai; extra == 'all'
|
|
39
|
+
Requires-Dist: openinference-instrumentation-vertexai; extra == 'all'
|
|
40
|
+
Provides-Extra: anthropic
|
|
41
|
+
Requires-Dist: openinference-instrumentation-anthropic; extra == 'anthropic'
|
|
42
|
+
Provides-Extra: bedrock
|
|
43
|
+
Requires-Dist: openinference-instrumentation-bedrock; extra == 'bedrock'
|
|
44
|
+
Provides-Extra: crewai
|
|
45
|
+
Requires-Dist: openinference-instrumentation-crewai; extra == 'crewai'
|
|
46
|
+
Provides-Extra: dev
|
|
47
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
48
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
49
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
50
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
51
|
+
Provides-Extra: google-genai
|
|
52
|
+
Requires-Dist: openinference-instrumentation-google-genai; extra == 'google-genai'
|
|
53
|
+
Provides-Extra: groq
|
|
54
|
+
Requires-Dist: openinference-instrumentation-groq; extra == 'groq'
|
|
55
|
+
Provides-Extra: langchain
|
|
56
|
+
Requires-Dist: langchain-core; extra == 'langchain'
|
|
57
|
+
Requires-Dist: openinference-instrumentation-langchain; extra == 'langchain'
|
|
58
|
+
Provides-Extra: litellm
|
|
59
|
+
Requires-Dist: openinference-instrumentation-litellm; extra == 'litellm'
|
|
60
|
+
Provides-Extra: llama-index
|
|
61
|
+
Requires-Dist: openinference-instrumentation-llama-index; extra == 'llama-index'
|
|
62
|
+
Provides-Extra: mistralai
|
|
63
|
+
Requires-Dist: openinference-instrumentation-mistralai; extra == 'mistralai'
|
|
64
|
+
Provides-Extra: openai
|
|
65
|
+
Requires-Dist: openinference-instrumentation-openai; extra == 'openai'
|
|
66
|
+
Provides-Extra: vertexai
|
|
67
|
+
Requires-Dist: openinference-instrumentation-vertexai; extra == 'vertexai'
|
|
68
|
+
Description-Content-Type: text/markdown
|
|
69
|
+
|
|
70
|
+
# mainwave
|
|
71
|
+
|
|
72
|
+
Python SDK for the [Mainwave AI](https://mainwave.ai) observability platform.
|
|
73
|
+
|
|
74
|
+
## Install
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install "mainwave[openai]" # one platform
|
|
78
|
+
pip install "mainwave[langchain]" # LangChain + a callback handler
|
|
79
|
+
pip install "mainwave[all]" # everything (kick-the-tires only)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Per-platform pinning is recommended in production.
|
|
83
|
+
|
|
84
|
+
## Quickstart
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
import mainwave
|
|
88
|
+
|
|
89
|
+
mainwave.init(
|
|
90
|
+
api_key="...", # or MAINWAVE_API_KEY
|
|
91
|
+
use_case_id="00000000-0000-0000-0000-000000000001", # or MAINWAVE_USE_CASE_ID
|
|
92
|
+
collector_url="https://collect.mainwave.ai", # default
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
with mainwave.run("INV-12345", metadata={"customer": "acme"}):
|
|
96
|
+
# ... do work; auto-instrumented LLM calls land under this run
|
|
97
|
+
...
|
|
98
|
+
|
|
99
|
+
mainwave.flush() # before exit
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`init()` auto-wires every supported instrumentor that's already importable, so
|
|
103
|
+
the snippet above needs no `instrument()` call. Reach for `instrument()` only
|
|
104
|
+
to wire a framework imported *after* `init()` ran (lazy import, CLI subcommand,
|
|
105
|
+
FastAPI lifespan) — see [Public API](#public-api).
|
|
106
|
+
|
|
107
|
+
`mainwave.run(...)` is optional — without it, every OTel trace becomes its
|
|
108
|
+
own logical run. Wrap explicitly when one logical operation spans multiple
|
|
109
|
+
traces (loops, fan-out, multiple LLM invocations per request); the integration
|
|
110
|
+
guide wraps every agent execution for exactly this reason.
|
|
111
|
+
|
|
112
|
+
## Not seeing data?
|
|
113
|
+
|
|
114
|
+
The SDK never raises into your app, so a misconfigured endpoint or key fails
|
|
115
|
+
quietly. Turn on its logger to see what's happening:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
import logging
|
|
119
|
+
logging.getLogger("mainwave").setLevel(logging.INFO) # add a handler if you have none
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
At `INFO` it logs the first successful export, which instrumentors wired, and a
|
|
123
|
+
`WARNING` for any framework that didn't. `mainwave.flush()` returns `False` on a
|
|
124
|
+
failed drain — check it before a hard exit. Confirm `collector_url` and the API
|
|
125
|
+
key, and that the framework's extra is installed (`pip install "mainwave[openai]"`).
|
|
126
|
+
|
|
127
|
+
## Public API
|
|
128
|
+
|
|
129
|
+
- `mainwave.init(...)` — set up the SDK once, at process start.
|
|
130
|
+
- `mainwave.instrument(name=None)` — re-wire instrumentors after late imports.
|
|
131
|
+
- `mainwave.run(...)` / `mainwave.arun(...)` / `mainwave.start_run(...)` — open a logical run (sync CM, async CM, imperative).
|
|
132
|
+
- `mainwave.span(name, attrs=...)` — escape hatch for manual spans.
|
|
133
|
+
- `mainwave.flush(timeout=30.0)` / `mainwave.aflush(timeout=30.0)` — drain buffers.
|
|
134
|
+
- `mainwave.langchain.CallbackHandler` — optional explicit LangChain handler.
|
|
135
|
+
- `mainwave.testing` — `reset()` + `install_in_memory_provider()` for tests.
|
|
136
|
+
|
|
137
|
+
## LangChain users
|
|
138
|
+
|
|
139
|
+
Use the native `CallbackHandler` (captures model reasoning + step trajectory) OR
|
|
140
|
+
auto-instrumentation (`instrument(name="langchain")`) — not both, or every call
|
|
141
|
+
is double-counted. You don't have to police it: attaching the handler disables
|
|
142
|
+
the OpenInference LangChain instrumentor automatically, and
|
|
143
|
+
`init(skip_instrumentors=["langchain"])` skips wiring it up front.
|
|
144
|
+
|
|
145
|
+
## See also
|
|
146
|
+
|
|
147
|
+
Spec: `docs/agent_sdk/` in the platform monorepo.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# mainwave
|
|
2
|
+
|
|
3
|
+
Python SDK for the [Mainwave AI](https://mainwave.ai) observability platform.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install "mainwave[openai]" # one platform
|
|
9
|
+
pip install "mainwave[langchain]" # LangChain + a callback handler
|
|
10
|
+
pip install "mainwave[all]" # everything (kick-the-tires only)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Per-platform pinning is recommended in production.
|
|
14
|
+
|
|
15
|
+
## Quickstart
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import mainwave
|
|
19
|
+
|
|
20
|
+
mainwave.init(
|
|
21
|
+
api_key="...", # or MAINWAVE_API_KEY
|
|
22
|
+
use_case_id="00000000-0000-0000-0000-000000000001", # or MAINWAVE_USE_CASE_ID
|
|
23
|
+
collector_url="https://collect.mainwave.ai", # default
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
with mainwave.run("INV-12345", metadata={"customer": "acme"}):
|
|
27
|
+
# ... do work; auto-instrumented LLM calls land under this run
|
|
28
|
+
...
|
|
29
|
+
|
|
30
|
+
mainwave.flush() # before exit
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`init()` auto-wires every supported instrumentor that's already importable, so
|
|
34
|
+
the snippet above needs no `instrument()` call. Reach for `instrument()` only
|
|
35
|
+
to wire a framework imported *after* `init()` ran (lazy import, CLI subcommand,
|
|
36
|
+
FastAPI lifespan) — see [Public API](#public-api).
|
|
37
|
+
|
|
38
|
+
`mainwave.run(...)` is optional — without it, every OTel trace becomes its
|
|
39
|
+
own logical run. Wrap explicitly when one logical operation spans multiple
|
|
40
|
+
traces (loops, fan-out, multiple LLM invocations per request); the integration
|
|
41
|
+
guide wraps every agent execution for exactly this reason.
|
|
42
|
+
|
|
43
|
+
## Not seeing data?
|
|
44
|
+
|
|
45
|
+
The SDK never raises into your app, so a misconfigured endpoint or key fails
|
|
46
|
+
quietly. Turn on its logger to see what's happening:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import logging
|
|
50
|
+
logging.getLogger("mainwave").setLevel(logging.INFO) # add a handler if you have none
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
At `INFO` it logs the first successful export, which instrumentors wired, and a
|
|
54
|
+
`WARNING` for any framework that didn't. `mainwave.flush()` returns `False` on a
|
|
55
|
+
failed drain — check it before a hard exit. Confirm `collector_url` and the API
|
|
56
|
+
key, and that the framework's extra is installed (`pip install "mainwave[openai]"`).
|
|
57
|
+
|
|
58
|
+
## Public API
|
|
59
|
+
|
|
60
|
+
- `mainwave.init(...)` — set up the SDK once, at process start.
|
|
61
|
+
- `mainwave.instrument(name=None)` — re-wire instrumentors after late imports.
|
|
62
|
+
- `mainwave.run(...)` / `mainwave.arun(...)` / `mainwave.start_run(...)` — open a logical run (sync CM, async CM, imperative).
|
|
63
|
+
- `mainwave.span(name, attrs=...)` — escape hatch for manual spans.
|
|
64
|
+
- `mainwave.flush(timeout=30.0)` / `mainwave.aflush(timeout=30.0)` — drain buffers.
|
|
65
|
+
- `mainwave.langchain.CallbackHandler` — optional explicit LangChain handler.
|
|
66
|
+
- `mainwave.testing` — `reset()` + `install_in_memory_provider()` for tests.
|
|
67
|
+
|
|
68
|
+
## LangChain users
|
|
69
|
+
|
|
70
|
+
Use the native `CallbackHandler` (captures model reasoning + step trajectory) OR
|
|
71
|
+
auto-instrumentation (`instrument(name="langchain")`) — not both, or every call
|
|
72
|
+
is double-counted. You don't have to police it: attaching the handler disables
|
|
73
|
+
the OpenInference LangChain instrumentor automatically, and
|
|
74
|
+
`init(skip_instrumentors=["langchain"])` skips wiring it up front.
|
|
75
|
+
|
|
76
|
+
## See also
|
|
77
|
+
|
|
78
|
+
Spec: `docs/agent_sdk/` in the platform monorepo.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mainwave"
|
|
3
|
+
version = "0.1.0rc1"
|
|
4
|
+
description = "Python SDK for the Mainwave AI observability platform"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "Mainwave AI" }]
|
|
10
|
+
keywords = [
|
|
11
|
+
"mainwave",
|
|
12
|
+
"observability",
|
|
13
|
+
"opentelemetry",
|
|
14
|
+
"openinference",
|
|
15
|
+
"llm",
|
|
16
|
+
"tracing",
|
|
17
|
+
"agents",
|
|
18
|
+
]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 4 - Beta",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
29
|
+
"Topic :: System :: Monitoring",
|
|
30
|
+
"Typing :: Typed",
|
|
31
|
+
]
|
|
32
|
+
dependencies = [
|
|
33
|
+
"opentelemetry-api>=1.27",
|
|
34
|
+
"opentelemetry-sdk>=1.27",
|
|
35
|
+
"opentelemetry-exporter-otlp-proto-http>=1.27",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.urls]
|
|
39
|
+
Homepage = "https://mainwave.ai"
|
|
40
|
+
Repository = "https://github.com/mainwaveai/mainwave"
|
|
41
|
+
Issues = "https://github.com/mainwaveai/mainwave/issues"
|
|
42
|
+
|
|
43
|
+
[project.optional-dependencies]
|
|
44
|
+
openai = ["openinference-instrumentation-openai"]
|
|
45
|
+
anthropic = ["openinference-instrumentation-anthropic"]
|
|
46
|
+
mistralai = ["openinference-instrumentation-mistralai"]
|
|
47
|
+
google-genai = ["openinference-instrumentation-google-genai"]
|
|
48
|
+
groq = ["openinference-instrumentation-groq"]
|
|
49
|
+
bedrock = ["openinference-instrumentation-bedrock"]
|
|
50
|
+
vertexai = ["openinference-instrumentation-vertexai"]
|
|
51
|
+
litellm = ["openinference-instrumentation-litellm"]
|
|
52
|
+
langchain = [
|
|
53
|
+
"openinference-instrumentation-langchain",
|
|
54
|
+
"langchain-core",
|
|
55
|
+
]
|
|
56
|
+
crewai = ["openinference-instrumentation-crewai"]
|
|
57
|
+
llama-index = ["openinference-instrumentation-llama-index"]
|
|
58
|
+
all = [
|
|
59
|
+
"mainwave[openai,anthropic,mistralai,google-genai,groq,bedrock,vertexai,litellm,langchain,crewai,llama-index]",
|
|
60
|
+
]
|
|
61
|
+
dev = [
|
|
62
|
+
"pytest>=8",
|
|
63
|
+
"pytest-asyncio>=0.23",
|
|
64
|
+
"ruff>=0.6",
|
|
65
|
+
"mypy>=1.10",
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[build-system]
|
|
69
|
+
requires = ["hatchling>=1.27"]
|
|
70
|
+
build-backend = "hatchling.build"
|
|
71
|
+
|
|
72
|
+
[tool.hatch.build.targets.wheel]
|
|
73
|
+
packages = ["src/mainwave"]
|
|
74
|
+
|
|
75
|
+
# Allowlist, not denylist: the sdist is public on PyPI, so only ship what a
|
|
76
|
+
# consumer needs to build/inspect the package. Anything not listed here
|
|
77
|
+
# (CLAUDE.md, SDK_README.md, Makefile, tests/, .gitignore, CI config) stays
|
|
78
|
+
# out by construction, so a new internal file can't silently leak into a
|
|
79
|
+
# release. pyproject.toml, the README, and LICENSE are always included by
|
|
80
|
+
# hatchling regardless.
|
|
81
|
+
[tool.hatch.build.targets.sdist]
|
|
82
|
+
only-include = ["src/mainwave"]
|
|
83
|
+
|
|
84
|
+
[tool.ruff]
|
|
85
|
+
line-length = 100
|
|
86
|
+
target-version = "py310"
|
|
87
|
+
|
|
88
|
+
[tool.ruff.lint]
|
|
89
|
+
select = ["E", "F", "I", "UP", "B", "SIM"]
|
|
90
|
+
ignore = ["SIM105", "SIM117", "SIM103"]
|
|
91
|
+
|
|
92
|
+
[tool.ruff.lint.per-file-ignores]
|
|
93
|
+
"tests/*" = ["E501"]
|
|
94
|
+
|
|
95
|
+
[tool.pytest.ini_options]
|
|
96
|
+
asyncio_mode = "auto"
|
|
97
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""mainwave — Python SDK for the Mainwave AI observability platform.
|
|
2
|
+
|
|
3
|
+
Public surface (stable):
|
|
4
|
+
init, instrument, register_framework
|
|
5
|
+
run, arun, start_run, span, flush, aflush, Run
|
|
6
|
+
langchain.CallbackHandler (lazy via `from mainwave import langchain`)
|
|
7
|
+
testing (test helpers)
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import logging as _logging
|
|
11
|
+
|
|
12
|
+
from . import _config, _instrumentors
|
|
13
|
+
from . import testing as testing # noqa: F401 (re-export module for users)
|
|
14
|
+
from ._config import init
|
|
15
|
+
from ._errors import MainwaveConfigError, MainwaveError, MainwaveReinitConflict
|
|
16
|
+
from ._flush import aflush, flush
|
|
17
|
+
from ._runtime import Run, arun, run, span, start_run
|
|
18
|
+
|
|
19
|
+
__version__ = _config._SDK_VERSION
|
|
20
|
+
|
|
21
|
+
_log = _logging.getLogger("mainwave")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _active_injector():
|
|
25
|
+
"""The attribute-injector processor that stamps framework names, or None if absent."""
|
|
26
|
+
from ._processors import MainwaveAttrInjector
|
|
27
|
+
|
|
28
|
+
procs = _config._state.mainwave_owned_processors
|
|
29
|
+
if procs and isinstance(procs[0], MainwaveAttrInjector):
|
|
30
|
+
return procs[0]
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _stamp_frameworks(injector, names: list[str]) -> None:
|
|
35
|
+
"""Record framework names (+ detected versions) on the injector, deduped."""
|
|
36
|
+
if injector is None:
|
|
37
|
+
return
|
|
38
|
+
injector.record_frameworks(names)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def register_framework(name: str) -> None:
|
|
42
|
+
"""Stamp a framework name on spans without wiring an OpenInference instrumentor.
|
|
43
|
+
|
|
44
|
+
Use when the instrumentor for a framework is unavailable or broken but you
|
|
45
|
+
still want the framework to appear in telemetry (e.g. crewai>=1.x while
|
|
46
|
+
openinference-instrumentation-crewai is incompatible).
|
|
47
|
+
"""
|
|
48
|
+
if not _config.is_initialized() or _config.is_disabled():
|
|
49
|
+
return
|
|
50
|
+
_stamp_frameworks(_active_injector(), [name])
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def instrument(name: str | list[str] | None = None) -> list[str]:
|
|
54
|
+
"""Wire OpenInference instrumentors after `init()`.
|
|
55
|
+
|
|
56
|
+
Use after a late import (lazy import, Click subcommand, FastAPI lifespan)
|
|
57
|
+
where the target library wasn't loaded at init() time.
|
|
58
|
+
|
|
59
|
+
- `name=None`: re-walk the full registry, instrumenting any newly-importable
|
|
60
|
+
packages. Returns the names that were newly wired this call.
|
|
61
|
+
- `name="openai"`: instrument exactly that platform. Raises KeyError if
|
|
62
|
+
the name isn't registered.
|
|
63
|
+
- `name=["crewai", "openai"]`: instrument each named platform (handy when a
|
|
64
|
+
framework needs more than one, e.g. CrewAI's structure instrumentor plus
|
|
65
|
+
its LLM-provider instrumentor). Raises KeyError before wiring anything if
|
|
66
|
+
any name is unregistered. Returns the subset that actually wired.
|
|
67
|
+
|
|
68
|
+
Returns the names that wired — a name whose package is missing or whose
|
|
69
|
+
installed version conflicts with the instrumentor is silently dropped from
|
|
70
|
+
the result (with a WARN from the wiring layer), not raised.
|
|
71
|
+
|
|
72
|
+
No-op when the SDK is disabled or not yet initialized (logs at WARN
|
|
73
|
+
if not initialized).
|
|
74
|
+
"""
|
|
75
|
+
if not _config.is_initialized():
|
|
76
|
+
_log.warning("mainwave.instrument() called before init(); ignoring")
|
|
77
|
+
return []
|
|
78
|
+
if _config.is_disabled():
|
|
79
|
+
return []
|
|
80
|
+
provider = _config.get_provider()
|
|
81
|
+
if provider is None:
|
|
82
|
+
return []
|
|
83
|
+
|
|
84
|
+
injector = _active_injector()
|
|
85
|
+
|
|
86
|
+
if name is None:
|
|
87
|
+
newly_wired = _instrumentors.wire_instrumentors(provider)
|
|
88
|
+
_stamp_frameworks(injector, newly_wired)
|
|
89
|
+
if newly_wired:
|
|
90
|
+
_log.info("mainwave: instrumented %s", ", ".join(newly_wired))
|
|
91
|
+
return newly_wired
|
|
92
|
+
|
|
93
|
+
raw = [name] if isinstance(name, str) else list(name)
|
|
94
|
+
# Accept hyphen or underscore spellings ("llama-index" == "llama_index"):
|
|
95
|
+
# the install extra is hyphenated, so users naturally type hyphens.
|
|
96
|
+
names = [_instrumentors.normalize_name(n) for n in raw]
|
|
97
|
+
# Validate the whole list up front so a typo in one name doesn't leave the
|
|
98
|
+
# crew half-instrumented (KeyError after some have already wired).
|
|
99
|
+
unknown = [n for n in names if n not in _instrumentors.known_names()]
|
|
100
|
+
if unknown:
|
|
101
|
+
raise KeyError(unknown[0] if len(unknown) == 1 else unknown)
|
|
102
|
+
|
|
103
|
+
wired = [n for n in names if _instrumentors.wire_one(n, provider)]
|
|
104
|
+
_stamp_frameworks(injector, wired)
|
|
105
|
+
if wired:
|
|
106
|
+
_log.info("mainwave: instrumented %s", ", ".join(wired))
|
|
107
|
+
not_wired = [n for n in names if n not in wired]
|
|
108
|
+
if not_wired:
|
|
109
|
+
_log.warning(
|
|
110
|
+
"mainwave: requested instrumentor(s) not wired (package not importable "
|
|
111
|
+
"or version conflict): %s",
|
|
112
|
+
", ".join(not_wired),
|
|
113
|
+
)
|
|
114
|
+
return wired
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
__all__ = [
|
|
118
|
+
"init",
|
|
119
|
+
"instrument",
|
|
120
|
+
"register_framework",
|
|
121
|
+
"run",
|
|
122
|
+
"arun",
|
|
123
|
+
"start_run",
|
|
124
|
+
"span",
|
|
125
|
+
"flush",
|
|
126
|
+
"aflush",
|
|
127
|
+
"Run",
|
|
128
|
+
"testing",
|
|
129
|
+
"MainwaveError",
|
|
130
|
+
"MainwaveConfigError",
|
|
131
|
+
"MainwaveReinitConflict",
|
|
132
|
+
"__version__",
|
|
133
|
+
]
|