omniray 1.0.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.
Files changed (41) hide show
  1. omniray-1.0.0/.gitignore +15 -0
  2. omniray-1.0.0/LICENSE +201 -0
  3. omniray-1.0.0/NOTICE +2 -0
  4. omniray-1.0.0/PKG-INFO +89 -0
  5. omniray-1.0.0/README.md +47 -0
  6. omniray-1.0.0/omniray/__init__.py +29 -0
  7. omniray-1.0.0/omniray/decorators.py +151 -0
  8. omniray-1.0.0/omniray/py.typed +0 -0
  9. omniray-1.0.0/omniray/tracing/__init__.py +1 -0
  10. omniray-1.0.0/omniray/tracing/console.py +21 -0
  11. omniray-1.0.0/omniray/tracing/flags.py +85 -0
  12. omniray-1.0.0/omniray/tracing/io_loggers.py +76 -0
  13. omniray-1.0.0/omniray/tracing/otel.py +81 -0
  14. omniray-1.0.0/omniray/tracing/profilers.py +108 -0
  15. omniray-1.0.0/omniray/tracing/span_name_generator.py +42 -0
  16. omniray-1.0.0/omniray/tracing/tracers.py +262 -0
  17. omniray-1.0.0/omniray/types.py +7 -0
  18. omniray-1.0.0/pyproject.toml +75 -0
  19. omniray-1.0.0/tests/conftest.py +16 -0
  20. omniray-1.0.0/tests/integration/conftest.py +59 -0
  21. omniray-1.0.0/tests/integration/test_otel_override.py +77 -0
  22. omniray-1.0.0/tests/integration/test_skip_if_trace.py +100 -0
  23. omniray-1.0.0/tests/integration/test_skip_if_wrapper.py +127 -0
  24. omniray-1.0.0/tests/unit/__init__.py +0 -0
  25. omniray-1.0.0/tests/unit/test_trace_decorator.py +77 -0
  26. omniray-1.0.0/tests/unit/test_trace_decorator_skip_if.py +133 -0
  27. omniray-1.0.0/tests/unit/test_trace_otel_decorator.py +52 -0
  28. omniray-1.0.0/tests/unit/test_trace_wrapper.py +130 -0
  29. omniray-1.0.0/tests/unit/test_trace_wrapper_flags.py +108 -0
  30. omniray-1.0.0/tests/unit/test_trace_wrapper_skip_if.py +94 -0
  31. omniray-1.0.0/tests/unit/tracing/__init__.py +0 -0
  32. omniray-1.0.0/tests/unit/tracing/test_console.py +40 -0
  33. omniray-1.0.0/tests/unit/tracing/test_flags.py +68 -0
  34. omniray-1.0.0/tests/unit/tracing/test_io_loggers.py +149 -0
  35. omniray-1.0.0/tests/unit/tracing/test_no_otel.py +140 -0
  36. omniray-1.0.0/tests/unit/tracing/test_profilers.py +175 -0
  37. omniray-1.0.0/tests/unit/tracing/test_span_name_generator.py +107 -0
  38. omniray-1.0.0/tests/unit/tracing/test_tracers.py +131 -0
  39. omniray-1.0.0/tests/unit/tracing/test_tracers_flag_resolution.py +139 -0
  40. omniray-1.0.0/tests/unit/tracing/test_tracers_internals.py +229 -0
  41. omniray-1.0.0/tests/unit/tracing/test_tracers_otel_override.py +137 -0
@@ -0,0 +1,15 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .ruff_cache/
8
+ .mypy_cache/
9
+ .pytest_cache/
10
+ .coverage
11
+ *.egg
12
+ coverage.xml
13
+ .idea/
14
+ .venv/
15
+ venv/
omniray-1.0.0/LICENSE ADDED
@@ -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 reasonable and customary use in describing the
141
+ origin of the Work and 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 choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or 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 [yyyy] [name of copyright owner]
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.
omniray-1.0.0/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Omniray & Omniwrap
2
+ Copyright 2026-present OMNIVISER SP. Z O.O.
omniray-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.4
2
+ Name: omniray
3
+ Version: 1.0.0
4
+ Summary: Function tracing and observability with console output and optional OpenTelemetry.
5
+ Project-URL: Homepage, https://github.com/omniviser/omniray
6
+ Project-URL: Repository, https://github.com/omniviser/omniray
7
+ Project-URL: Issues, https://github.com/omniviser/omniray/issues
8
+ Project-URL: Changelog, https://github.com/omniviser/omniray/blob/main/CHANGELOG.md
9
+ Author-email: Bartlomiej Flis <Bartekdawidflis@gmail.com>, "OMNIVISER SP. Z O.O." <info@omniviser.ai>
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Keywords: console,debugging,instrumentation,monitoring,observability,omniray,opentelemetry,otel,performance,profiling,real-time,tracing
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: System Administrators
17
+ Classifier: License :: OSI Approved :: Apache Software License
18
+ Classifier: Natural Language :: English
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Software Development :: Debuggers
24
+ Classifier: Topic :: Software Development :: Libraries
25
+ Classifier: Topic :: System :: Monitoring
26
+ Classifier: Typing :: Typed
27
+ Requires-Python: >=3.12
28
+ Requires-Dist: colorama>=0.4
29
+ Requires-Dist: omniwrap>=1.0.0
30
+ Requires-Dist: pydantic<3,>=2.7
31
+ Provides-Extra: dev
32
+ Requires-Dist: opentelemetry-api>=1.16; extra == 'dev'
33
+ Requires-Dist: opentelemetry-sdk>=1.16; extra == 'dev'
34
+ Requires-Dist: pytest-asyncio>=0.25; extra == 'dev'
35
+ Requires-Dist: pytest-cov>=6.0; extra == 'dev'
36
+ Requires-Dist: pytest-mock>=3.14; extra == 'dev'
37
+ Requires-Dist: pytest>=8.0; extra == 'dev'
38
+ Provides-Extra: otel
39
+ Requires-Dist: opentelemetry-api>=1.16; extra == 'otel'
40
+ Requires-Dist: opentelemetry-sdk>=1.16; extra == 'otel'
41
+ Description-Content-Type: text/markdown
42
+
43
+ # omniray
44
+
45
+ A live tracing tool for Python -- console profiling with optional OpenTelemetry tracing for [omniwrap](https://github.com/omniviser/omniray).
46
+
47
+ See the [main README](../../README.md) for full documentation.
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install omniray
53
+ ```
54
+
55
+ ## Quick Start
56
+
57
+ ```python
58
+ from omniwrap import wrap_all
59
+ from omniray import create_trace_wrapper, trace
60
+
61
+ # Auto-instrument with console profiling (OTel spans off by default)
62
+ wrap_all(create_trace_wrapper())
63
+
64
+ # Selectively enable OTel on high-value functions
65
+ @trace(otel=True)
66
+ def process_payment(order_id: str) -> bool: ...
67
+
68
+ @trace(otel=True)
69
+ async def execute_sql(query: str) -> list[dict]: ...
70
+
71
+ # Regular functions get profiling only — no OTel cost
72
+ @trace()
73
+ def validate_input(data: dict) -> bool: ...
74
+ ```
75
+
76
+ ## Environment Variables
77
+
78
+ | Variable | Default | Description |
79
+ |----------|---------|-------------|
80
+ | `OMNIRAY_OTEL` | `false` | Generate OpenTelemetry spans globally (use `@trace(otel=True)` for selective opt-in) |
81
+ | `OMNIRAY_LOG` | `false` | Enable colored console tree output |
82
+ | `OMNIRAY_LOG_INPUT` | `false` | Log function arguments |
83
+ | `OMNIRAY_LOG_OUTPUT` | `false` | Log function return values |
84
+ | `OMNIRAY_LOG_COLOR` | `true` | Enable ANSI colors in console output |
85
+ | `OMNIRAY_LOG_STYLE` | `auto` | Box-drawing style: `unicode`, `ascii`, or `auto` (detect from terminal) |
86
+
87
+ ## License
88
+
89
+ Apache 2.0
@@ -0,0 +1,47 @@
1
+ # omniray
2
+
3
+ A live tracing tool for Python -- console profiling with optional OpenTelemetry tracing for [omniwrap](https://github.com/omniviser/omniray).
4
+
5
+ See the [main README](../../README.md) for full documentation.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install omniray
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```python
16
+ from omniwrap import wrap_all
17
+ from omniray import create_trace_wrapper, trace
18
+
19
+ # Auto-instrument with console profiling (OTel spans off by default)
20
+ wrap_all(create_trace_wrapper())
21
+
22
+ # Selectively enable OTel on high-value functions
23
+ @trace(otel=True)
24
+ def process_payment(order_id: str) -> bool: ...
25
+
26
+ @trace(otel=True)
27
+ async def execute_sql(query: str) -> list[dict]: ...
28
+
29
+ # Regular functions get profiling only — no OTel cost
30
+ @trace()
31
+ def validate_input(data: dict) -> bool: ...
32
+ ```
33
+
34
+ ## Environment Variables
35
+
36
+ | Variable | Default | Description |
37
+ |----------|---------|-------------|
38
+ | `OMNIRAY_OTEL` | `false` | Generate OpenTelemetry spans globally (use `@trace(otel=True)` for selective opt-in) |
39
+ | `OMNIRAY_LOG` | `false` | Enable colored console tree output |
40
+ | `OMNIRAY_LOG_INPUT` | `false` | Log function arguments |
41
+ | `OMNIRAY_LOG_OUTPUT` | `false` | Log function return values |
42
+ | `OMNIRAY_LOG_COLOR` | `true` | Enable ANSI colors in console output |
43
+ | `OMNIRAY_LOG_STYLE` | `auto` | Box-drawing style: `unicode`, `ascii`, or `auto` (detect from terminal) |
44
+
45
+ ## License
46
+
47
+ Apache 2.0
@@ -0,0 +1,29 @@
1
+ """omniray - Function tracing and observability with console output and optional OpenTelemetry.
2
+
3
+ Provides automatic function/method tracing via OpenTelemetry spans.
4
+
5
+ Example usage::
6
+
7
+ from omniwrap import wrap_all
8
+ from omniray import create_trace_wrapper
9
+
10
+ # Create sync and async wrappers
11
+ wrappers = create_trace_wrapper()
12
+
13
+ # Wrap everything with tracing
14
+ wrap_all(wrappers)
15
+
16
+ # With I/O logging enabled
17
+ wrap_all(create_trace_wrapper(log_input=True, log_output=True))
18
+ """
19
+
20
+ import logging
21
+
22
+ from omniray.decorators import create_trace_wrapper, trace
23
+
24
+ logging.getLogger("omniray").addHandler(logging.NullHandler())
25
+
26
+ __all__ = [
27
+ "create_trace_wrapper",
28
+ "trace",
29
+ ]
@@ -0,0 +1,151 @@
1
+ """Decorators and wrappers for tracing function execution.
2
+
3
+ This module provides:
4
+ - trace() decorator for manual instrumentation
5
+ - create_trace_wrapper() factory for automatic instrumentation with omniwrap
6
+ """
7
+
8
+ import asyncio
9
+ from collections.abc import Callable
10
+ from functools import wraps
11
+
12
+ from omniray.tracing.tracers import (
13
+ AsyncTracer,
14
+ Tracer,
15
+ )
16
+ from omniray.types import CallResult, WraptInstance
17
+
18
+
19
+ def _exclude_from_omniwrap[**P, T](func: Callable[P, T]) -> Callable[P, T]:
20
+ """Mark function as already traced so omniwrap won't double-wrap it.
21
+
22
+ Sets ``_omniwrap_skip`` — the same attribute that ``@skip_wrap`` uses.
23
+ type: ignore because plain functions don't declare this attribute in their type.
24
+ """
25
+ func._omniwrap_skip = True # type: ignore[attr-defined] # noqa: SLF001
26
+ return func
27
+
28
+
29
+ def trace[**P, T](
30
+ *,
31
+ log: bool | None = None,
32
+ log_input: bool | None = None,
33
+ log_output: bool | None = None,
34
+ skip_if: Callable[..., bool] | None = None,
35
+ otel: bool | None = None,
36
+ ) -> Callable[[Callable[P, T]], Callable[P, T]]:
37
+ """Decorator to trace any function/method (sync/async) execution.
38
+
39
+ Use this for manual instrumentation of specific functions.
40
+ For automatic instrumentation of your entire codebase, use
41
+ ``create_trace_wrapper()`` with ``omniwrap.wrap_all()``.
42
+
43
+ Args:
44
+ log: Override global OMNIRAY_LOG setting per-function.
45
+ log_input: Override global OMNIRAY_LOG_INPUT setting.
46
+ log_output: Override global OMNIRAY_LOG_OUTPUT setting.
47
+ skip_if: Predicate receiving the decorated function's arguments.
48
+ When it returns ``True``, tracing is bypassed entirely and the
49
+ function is called directly.
50
+ otel: Whether to create otel spans from the callable.
51
+ """
52
+
53
+ def decorator(func: Callable[P, T]) -> Callable[P, T]:
54
+ if asyncio.iscoroutinefunction(func):
55
+
56
+ @wraps(func)
57
+ async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> CallResult:
58
+ if skip_if is not None and skip_if(*args, **kwargs):
59
+ return await func(*args, **kwargs)
60
+ return await AsyncTracer.trace(
61
+ func,
62
+ args,
63
+ kwargs,
64
+ log=log,
65
+ log_input=log_input,
66
+ log_output=log_output,
67
+ otel=otel,
68
+ )
69
+
70
+ # mypy can't prove async_wrapper satisfies Callable[P, T] because the
71
+ # inner return type is CallResult (Any), not T. @wraps preserves the
72
+ # original signature at runtime; ParamSpec preserves it for callers.
73
+ return _exclude_from_omniwrap(async_wrapper) # type: ignore[return-value, arg-type]
74
+
75
+ @wraps(func)
76
+ def sync_wrapper(*args: P.args, **kwargs: P.kwargs) -> CallResult:
77
+ if skip_if is not None and skip_if(*args, **kwargs):
78
+ return func(*args, **kwargs)
79
+ return Tracer.trace(
80
+ func,
81
+ args,
82
+ kwargs,
83
+ log=log,
84
+ log_input=log_input,
85
+ log_output=log_output,
86
+ otel=otel,
87
+ )
88
+
89
+ return _exclude_from_omniwrap(sync_wrapper) # type: ignore[return-value]
90
+
91
+ return decorator
92
+
93
+
94
+ def create_trace_wrapper(
95
+ *,
96
+ log: bool | None = None,
97
+ log_input: bool | None = None,
98
+ log_output: bool | None = None,
99
+ skip_if: Callable[..., bool] | None = None,
100
+ otel: bool | None = None,
101
+ ) -> tuple[Callable, Callable]:
102
+ """Create sync and async wrappers for tracing with wrapt.
103
+
104
+ Args:
105
+ log: Override global OMNIRAY_LOG setting.
106
+ log_input: Override global OMNIRAY_LOG_INPUT setting.
107
+ log_output: Override global OMNIRAY_LOG_OUTPUT setting.
108
+ skip_if: Predicate receiving the wrapped function's arguments.
109
+ When it returns ``True``, tracing is bypassed entirely and the
110
+ function is called directly. Note: wrapt separates ``self``/``cls``
111
+ into a dedicated ``instance`` parameter, so the predicate receives
112
+ only the explicit arguments (without ``self``).
113
+ otel: Override global OMNIRAY_OTEL setting.
114
+
115
+ Returns:
116
+ Tuple of (sync_wrapper, async_wrapper) for use with omniwrap.
117
+ """
118
+
119
+ def sync_wrapper(
120
+ wrapped: Callable, instance: WraptInstance, args: tuple, kwargs: dict
121
+ ) -> CallResult:
122
+ if skip_if is not None and skip_if(*args, **kwargs):
123
+ return wrapped(*args, **kwargs)
124
+ return Tracer.trace(
125
+ wrapped,
126
+ args,
127
+ kwargs,
128
+ instance=instance,
129
+ log=log,
130
+ log_input=log_input,
131
+ log_output=log_output,
132
+ otel=otel,
133
+ )
134
+
135
+ async def async_wrapper(
136
+ wrapped: Callable, instance: WraptInstance, args: tuple, kwargs: dict
137
+ ) -> CallResult:
138
+ if skip_if is not None and skip_if(*args, **kwargs):
139
+ return await wrapped(*args, **kwargs)
140
+ return await AsyncTracer.trace(
141
+ wrapped,
142
+ args,
143
+ kwargs,
144
+ instance=instance,
145
+ log=log,
146
+ log_input=log_input,
147
+ log_output=log_output,
148
+ otel=otel,
149
+ )
150
+
151
+ return sync_wrapper, async_wrapper
File without changes
@@ -0,0 +1 @@
1
+ """Tracing utilities for OpenTelemetry instrumentation."""
@@ -0,0 +1,21 @@
1
+ """Console logger setup for tree output."""
2
+
3
+ import logging
4
+
5
+ logger = logging.getLogger("omniray.tracing")
6
+
7
+
8
+ def setup_console_handler() -> None:
9
+ """Add console handler if not already present.
10
+
11
+ Omniray owns its handler (like pytest/tqdm) — colored tree output would be
12
+ garbled by app-level formatters. ``propagate=False`` prevents double output.
13
+ To silence at runtime: ``logging.getLogger("omniray.tracing").setLevel(CRITICAL)``
14
+ """
15
+ if not logger.handlers:
16
+ handler = logging.StreamHandler()
17
+ formatter = logging.Formatter("%(asctime)s %(levelname)s: %(message)s", datefmt="%H:%M")
18
+ handler.setFormatter(formatter)
19
+ logger.addHandler(handler)
20
+ logger.setLevel(logging.INFO)
21
+ logger.propagate = False
@@ -0,0 +1,85 @@
1
+ """Flag parsing and resolution for configuration.
2
+
3
+ Provides env var reading and global/local flag merging with kill-switch semantics.
4
+ """
5
+
6
+ import os
7
+ from dataclasses import dataclass
8
+
9
+
10
+ def _env_flag(var: str) -> bool | None:
11
+ """Read env var as bool, or None if unset."""
12
+ raw = os.getenv(var)
13
+ return raw.lower() in ("true", "1", "yes") if raw is not None else None
14
+
15
+
16
+ def resolve_flag(*, global_flag: bool | None, local_flag: bool | None) -> bool:
17
+ """Resolve global (env var) and local (decorator) flag into a single bool."""
18
+ if global_flag is False:
19
+ return False
20
+ if local_flag is not None:
21
+ return local_flag
22
+ return global_flag is True
23
+
24
+
25
+ CONSOLE_LOG_FLAG = _env_flag("OMNIRAY_LOG")
26
+ LOG_INPUT_FLAG = _env_flag("OMNIRAY_LOG_INPUT")
27
+ LOG_OUTPUT_FLAG = _env_flag("OMNIRAY_LOG_OUTPUT")
28
+
29
+
30
+ @dataclass(frozen=True)
31
+ class TraceFlags:
32
+ """Resolved trace flags — all ``bool``, no more ``None``."""
33
+
34
+ log: bool
35
+ log_input: bool
36
+ log_output: bool
37
+ otel: bool
38
+
39
+
40
+ _default_flags_cache: dict[bool | None, TraceFlags] = {}
41
+
42
+
43
+ def resolve_trace_flags(
44
+ *,
45
+ log: bool | None,
46
+ log_input: bool | None,
47
+ log_output: bool | None,
48
+ otel: bool | None,
49
+ otel_flag: bool | None,
50
+ ) -> TraceFlags:
51
+ """Resolve all flags into concrete bools for a single trace call.
52
+
53
+ When all local overrides are None (the common case with ``wrap_all``),
54
+ returns a cached singleton — avoids repeated flag resolution and dataclass
55
+ allocation on every call.
56
+ """
57
+ if log is None and log_input is None and log_output is None and otel is None:
58
+ cached = _default_flags_cache.get(otel_flag)
59
+ if cached is not None:
60
+ return cached
61
+ flags = _resolve_all(
62
+ log=None, log_input=None, log_output=None, otel=None, otel_flag=otel_flag
63
+ )
64
+ _default_flags_cache[otel_flag] = flags
65
+ return flags
66
+ return _resolve_all(
67
+ log=log, log_input=log_input, log_output=log_output, otel=otel, otel_flag=otel_flag
68
+ )
69
+
70
+
71
+ def _resolve_all(
72
+ *,
73
+ log: bool | None,
74
+ log_input: bool | None,
75
+ log_output: bool | None,
76
+ otel: bool | None,
77
+ otel_flag: bool | None,
78
+ ) -> TraceFlags:
79
+ should_log = resolve_flag(global_flag=CONSOLE_LOG_FLAG, local_flag=log)
80
+ return TraceFlags(
81
+ log=should_log,
82
+ log_input=resolve_flag(global_flag=LOG_INPUT_FLAG, local_flag=log_input) and should_log,
83
+ log_output=resolve_flag(global_flag=LOG_OUTPUT_FLAG, local_flag=log_output) and should_log,
84
+ otel=resolve_flag(global_flag=otel_flag, local_flag=otel),
85
+ )