Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .venv/lib/python3.11/site-packages/depyf-0.18.0.dist-info/INSTALLER +1 -0
- .venv/lib/python3.11/site-packages/depyf-0.18.0.dist-info/LICENSE +21 -0
- .venv/lib/python3.11/site-packages/depyf-0.18.0.dist-info/METADATA +139 -0
- .venv/lib/python3.11/site-packages/depyf-0.18.0.dist-info/RECORD +37 -0
- .venv/lib/python3.11/site-packages/depyf-0.18.0.dist-info/WHEEL +5 -0
- .venv/lib/python3.11/site-packages/depyf-0.18.0.dist-info/top_level.txt +1 -0
- .venv/lib/python3.11/site-packages/opencensus/common/__init__.py +1 -0
- .venv/lib/python3.11/site-packages/opencensus/common/http_handler/__init__.py +43 -0
- .venv/lib/python3.11/site-packages/opencensus/common/http_handler/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/__pycache__/aws_identity_doc_utils.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/__pycache__/gcp_metadata_config.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/__pycache__/k8s_utils.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/__pycache__/monitored_resource.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/aws_identity_doc_utils.py +95 -0
- .venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/monitored_resource.py +68 -0
- .venv/lib/python3.11/site-packages/opencensus/common/resource/__init__.py +218 -0
- .venv/lib/python3.11/site-packages/opencensus/common/resource/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/runtime_context/__init__.py +177 -0
- .venv/lib/python3.11/site-packages/opencensus/common/runtime_context/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/runtime_context/__pycache__/version.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/runtime_context/version.py +15 -0
- .venv/lib/python3.11/site-packages/opencensus/common/schedule/__init__.py +149 -0
- .venv/lib/python3.11/site-packages/opencensus/common/schedule/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/transports/__init__.py +13 -0
- .venv/lib/python3.11/site-packages/opencensus/common/transports/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/transports/__pycache__/async_.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/transports/__pycache__/base.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/transports/__pycache__/sync.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/common/transports/async_.py +231 -0
- .venv/lib/python3.11/site-packages/opencensus/common/transports/base.py +31 -0
- .venv/lib/python3.11/site-packages/opencensus/common/transports/sync.py +28 -0
- .venv/lib/python3.11/site-packages/opencensus/common/utils/__init__.py +131 -0
- .venv/lib/python3.11/site-packages/opencensus/common/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/metrics/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/metrics/__pycache__/label_key.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/metrics/__pycache__/label_value.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/metrics/__pycache__/transport.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/metrics/export/__pycache__/metric_descriptor.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/metrics/export/__pycache__/metric_producer.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/metrics/export/__pycache__/value.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/attributes_helper.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/blank_span.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/exceptions_status.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/integrations.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/link.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/logging_exporter.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/span.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/stack_trace.cpython-311.pyc +0 -0
.venv/lib/python3.11/site-packages/depyf-0.18.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
.venv/lib/python3.11/site-packages/depyf-0.18.0.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2023 Tsinghua University, Machine Learning Group (THUML)
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
.venv/lib/python3.11/site-packages/depyf-0.18.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: depyf
|
| 3 |
+
Version: 0.18.0
|
| 4 |
+
Summary: Decompile python functions, from bytecode to source code!
|
| 5 |
+
Home-page: https://github.com/thuml/depyf
|
| 6 |
+
Author: Kaichao You
|
| 7 |
+
Author-email: youkaichao@gmail.com
|
| 8 |
+
License: MIT
|
| 9 |
+
Requires-Python: >=3.7
|
| 10 |
+
Description-Content-Type: text/markdown
|
| 11 |
+
License-File: LICENSE
|
| 12 |
+
Requires-Dist: astor
|
| 13 |
+
Requires-Dist: dill
|
| 14 |
+
Provides-Extra: dev
|
| 15 |
+
Requires-Dist: pytest ; extra == 'dev'
|
| 16 |
+
Requires-Dist: flake8 ; extra == 'dev'
|
| 17 |
+
Requires-Dist: autopep8 ; extra == 'dev'
|
| 18 |
+
|
| 19 |
+

|
| 20 |
+
|
| 21 |
+
[](https://depyf.readthedocs.io/en/latest/)    [](https://codecov.io/github/thuml/depyf) 
|
| 22 |
+
|
| 23 |
+
> `depyf` is proud to be a [PyTorch ecosystem project](https://pytorch.org/ecosystem/). Check out the announcement blog [https://pytorch.org/blog/introducing-depyf/](https://pytorch.org/blog/introducing-depyf/) for more details.
|
| 24 |
+
|
| 25 |
+
Have you ever felt overwhelmed by the complexities of `torch.compile`? Diving into its workings can feel like black magic, with bytecode and Python internal details that many users fail to understand, hindering them from understanding and adapting to `torch.compile`.
|
| 26 |
+
|
| 27 |
+
If you also face the problem, then you might be interested in `depyf`. As the logo suggests, `depyf` is a software tool to leverage advanced Python features (the Python snake symbol) to open up internal details (the internal gears symbol) of PyTorch's compiler `torch.compile` (the PyTorch logo), so that users can understand it, adapt to it, and tune their code (the debugger symbol) to get maximum performance benefit out of it.
|
| 28 |
+
|
| 29 |
+
:warning: This project is developed under close collaborations with the PyTorch team. Therefore, it requires very new features from PyTorch to support better understanding of `torch.compile`. **Please use this project along with PyTorch>=2.2.0 (PyTorch nightly is recommended)**. Visit the [PyTorch website](https://pytorch.org/) for how to install different versions of PyTorch.
|
| 30 |
+
|
| 31 |
+
:warning: During development, we seek suggestions from the community quite a lot. You may find some early usage examples from some discussion forums or social media platforms. **Please follow the latest documentation for how to use this tool.**
|
| 32 |
+
|
| 33 |
+
# Why `depyf`?
|
| 34 |
+
|
| 35 |
+
If you want to understand bytecode generated by `torch.compile`, then `depyf` might be the only choice for you. Below we tested several existing decompilers, they struggle to decompile simple Python bytecode across versions, and have poor support for PyTorch.
|
| 36 |
+
|
| 37 |
+
| Decompiler | Python 3.8 | Python 3.9 | Python 3.10 | Python 3.11 | PyTorch |
|
| 38 |
+
|-------------|--------------|------------|-------------|-------------|---------|
|
| 39 |
+
| [decompyle3](https://github.com/rocky/python-decompile3) | 90.6% (77/85) | × | × | × | × |
|
| 40 |
+
| [uncompyle6](https://github.com/rocky/python-uncompyle6) | 91.8% (78/85)| × | × | × | × |
|
| 41 |
+
| [pycdc](https://github.com/zrax/pycdc) | 74.1% (63/85) | 74.1% (63/85)| 74.1% (63/85) | 67.1% (57/85) | 19.3% (27/140)|
|
| 42 |
+
| [depyf](https://github.com/thuml/depyf) | 100% (85/85) | 100% (85/85)| 100% (85/85)| 100% (85/85)| 100% (140/140)|
|
| 43 |
+
|
| 44 |
+
# Installation
|
| 45 |
+
|
| 46 |
+
Stable release: `pip install depyf`
|
| 47 |
+
|
| 48 |
+
Nightly version (recommended): `pip install git+https://github.com/thuml/depyf.git`
|
| 49 |
+
|
| 50 |
+
# Usage
|
| 51 |
+
|
| 52 |
+
The main usage is quite simple: just wrap your code within a context manager:
|
| 53 |
+
|
| 54 |
+
```python
|
| 55 |
+
import torch
|
| 56 |
+
from torch import _dynamo as torchdynamo
|
| 57 |
+
from typing import List
|
| 58 |
+
|
| 59 |
+
@torch.compile
|
| 60 |
+
def toy_example(a, b):
|
| 61 |
+
x = a / (torch.abs(a) + 1)
|
| 62 |
+
if b.sum() < 0:
|
| 63 |
+
b = b * -1
|
| 64 |
+
return x * b
|
| 65 |
+
|
| 66 |
+
def main():
|
| 67 |
+
for _ in range(100):
|
| 68 |
+
toy_example(torch.randn(10), torch.randn(10))
|
| 69 |
+
|
| 70 |
+
if __name__ == "__main__":
|
| 71 |
+
# main()
|
| 72 |
+
# surround the code you want to run inside `with depyf.prepare_debug`
|
| 73 |
+
import depyf
|
| 74 |
+
with depyf.prepare_debug("./dump_src_dir"):
|
| 75 |
+
main()
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
Then you can see all the details of `torch.compile` inside the directory `./dump_src_dir`. The details are organized into the following:
|
| 79 |
+
|
| 80 |
+
- `full_code_for_xxx.py` for each function using `torch.compile`
|
| 81 |
+
- `__transformed_code_for_xxx.py` for Python code associated with each graph.
|
| 82 |
+
- `__transformed_code_for_xxx.py.xxx_bytecode` for Python bytecode, dumped code object, can be loaded via `dill.load(open("/path/to/file", "wb"))`. Note that the `load` function might import some modules like `transformers`. Make sure you have these modules installed.
|
| 83 |
+
- `__compiled_fn_xxx.py` for each computation graph and its optimization:
|
| 84 |
+
- `Captured Graph`: a plain forward computation graph
|
| 85 |
+
- `Joint Graph`: joint forward-backward graph from `AOTAutograd`
|
| 86 |
+
- `Forward Graph`: forward graph from `AOTAutograd`
|
| 87 |
+
- `Backward Graph`: backward graph from `AOTAutograd`
|
| 88 |
+
- `kernel xxx`: compiled CPU/GPU kernel wrapper from Inductor.
|
| 89 |
+
|
| 90 |
+
We collect [all the compilation artifacts](https://github.com/thuml/learn_torch.compile) when testing over 100 deep learning models. You can take a look to learn how the PyTorch compiler works.
|
| 91 |
+
|
| 92 |
+
If you want to use debugger to step through the above code, just add another context manager (and launch the script through debuggers):
|
| 93 |
+
|
| 94 |
+
```python
|
| 95 |
+
import torch
|
| 96 |
+
from torch import _dynamo as torchdynamo
|
| 97 |
+
from typing import List
|
| 98 |
+
|
| 99 |
+
@torch.compile
|
| 100 |
+
def toy_example(a, b):
|
| 101 |
+
x = a / (torch.abs(a) + 1)
|
| 102 |
+
if b.sum() < 0:
|
| 103 |
+
b = b * -1
|
| 104 |
+
return x * b
|
| 105 |
+
|
| 106 |
+
def main():
|
| 107 |
+
for _ in range(100):
|
| 108 |
+
toy_example(torch.randn(10), torch.randn(10))
|
| 109 |
+
|
| 110 |
+
if __name__ == "__main__":
|
| 111 |
+
import depyf
|
| 112 |
+
with depyf.prepare_debug("./dump_src_dir"):
|
| 113 |
+
main()
|
| 114 |
+
# surround the code you want to debug inside `with depyf.debug()`
|
| 115 |
+
with depyf.debug():
|
| 116 |
+
main()
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
Calling `depyf.debug()` will pause the program for you to set breakpoints, and then you can use debuggers to hit breakpoints in these files under the `./dump_src_dir` directory you specified above.
|
| 120 |
+
|
| 121 |
+
# Contact
|
| 122 |
+
|
| 123 |
+
If you have any question about `depyf`, feel free to open issues to reach out! Any discussion/issue report/PR is welcome. Or contact youkaichao@gmail.com if you have any other questions.
|
| 124 |
+
|
| 125 |
+
# Citing `depyf`
|
| 126 |
+
|
| 127 |
+
If you find `depyf` useful, please cite it in your publications.
|
| 128 |
+
|
| 129 |
+
```latex
|
| 130 |
+
@article{you2024depyf,
|
| 131 |
+
title={depyf: Open the Opaque Box of PyTorch Compiler for Machine Learning Researchers},
|
| 132 |
+
author={Kaichao You and Runsheng Bai and Meng Cao and Jianmin Wang and Ion Stoica and Mingsheng Long},
|
| 133 |
+
year={2024},
|
| 134 |
+
eprint={2403.13839},
|
| 135 |
+
journal={arXiv},
|
| 136 |
+
primaryClass={cs.LG},
|
| 137 |
+
url={https://github.com/thuml/depyf}
|
| 138 |
+
}
|
| 139 |
+
```
|
.venv/lib/python3.11/site-packages/depyf-0.18.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
depyf-0.18.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
depyf-0.18.0.dist-info/LICENSE,sha256=lzua0q7KCQHlSWzC19FuMW0BAF6WZZ3CV7R9A_3scmY,1108
|
| 3 |
+
depyf-0.18.0.dist-info/METADATA,sha256=BeQoG-ccxNdRfp6WoHhRCC9h2C71nsGLMKlPoGM1qw0,7102
|
| 4 |
+
depyf-0.18.0.dist-info/RECORD,,
|
| 5 |
+
depyf-0.18.0.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
| 6 |
+
depyf-0.18.0.dist-info/top_level.txt,sha256=Q8OIJwiCISz0EGVEbMqj3ybR3yHWYbLNxR0ocsccRoo,6
|
| 7 |
+
depyf/VERSION.txt,sha256=QsG7ukni09uOW2RMD0kLOlCvEaKkRnPYnJ03IRLMrX8,6
|
| 8 |
+
depyf/__init__.py,sha256=LbOU08fulsuNrWJrbh-RP3aotFRDBOhPbPRJcriNiNk,841
|
| 9 |
+
depyf/__pycache__/__init__.cpython-311.pyc,,
|
| 10 |
+
depyf/__pycache__/code_transform.cpython-311.pyc,,
|
| 11 |
+
depyf/__pycache__/decompiler.cpython-311.pyc,,
|
| 12 |
+
depyf/__pycache__/optimization.cpython-311.pyc,,
|
| 13 |
+
depyf/__pycache__/utils.cpython-311.pyc,,
|
| 14 |
+
depyf/code_transform.py,sha256=yLFkRxyXCfE_B4FOik4a89IAJJg5cFrl9TB7m15hDXs,17855
|
| 15 |
+
depyf/decompiler.py,sha256=SP9nbIhpMqygnHTCYnoe538ZPSygP9dFV3jtl7fYPUw,53998
|
| 16 |
+
depyf/explain/__init__.py,sha256=pXasvun6VLMr5YqXkaEenMZqrLLtL5jkEi-H86LI15k,620
|
| 17 |
+
depyf/explain/__pycache__/__init__.cpython-311.pyc,,
|
| 18 |
+
depyf/explain/__pycache__/enable_debugging.cpython-311.pyc,,
|
| 19 |
+
depyf/explain/__pycache__/enhance_logging.cpython-311.pyc,,
|
| 20 |
+
depyf/explain/__pycache__/global_variables.cpython-311.pyc,,
|
| 21 |
+
depyf/explain/__pycache__/patched___call__.cpython-311.pyc,,
|
| 22 |
+
depyf/explain/__pycache__/patched__exec_with_source.cpython-311.pyc,,
|
| 23 |
+
depyf/explain/__pycache__/patched_boxed_run.cpython-311.pyc,,
|
| 24 |
+
depyf/explain/__pycache__/patched_lazy_format_graph_code.cpython-311.pyc,,
|
| 25 |
+
depyf/explain/__pycache__/patched_load_by_key_path.cpython-311.pyc,,
|
| 26 |
+
depyf/explain/__pycache__/utils.cpython-311.pyc,,
|
| 27 |
+
depyf/explain/enable_debugging.py,sha256=cOTGwTJlYFAwVW_kgFvBhFITCO7lj9eOhh5zXnvF-0M,12602
|
| 28 |
+
depyf/explain/enhance_logging.py,sha256=x-9Y3rxlIW30-cYIUfqv_Ha3h_0AwFnZ7_7tisDso2k,2745
|
| 29 |
+
depyf/explain/global_variables.py,sha256=cdE2qMzfK4LvP-VJXP36ZQMG1m896mN7hJsQmbPWRkQ,451
|
| 30 |
+
depyf/explain/patched___call__.py,sha256=kEg09Pt08gDeICr5D_SryS2TJ2k5lDqbv_m5VViD43Q,352
|
| 31 |
+
depyf/explain/patched__exec_with_source.py,sha256=yEAB3k9KOrQ75275fY0ghdjs3qMXESYKV0VH6C947wk,750
|
| 32 |
+
depyf/explain/patched_boxed_run.py,sha256=Uq70zcEcY-F3cupORR10_OdRU9TOzfOVqRW4Dpw8w30,83
|
| 33 |
+
depyf/explain/patched_lazy_format_graph_code.py,sha256=3YOke3DCeISdS_-X-ucalkDeXAsWRsu4PwE5oJ4at9g,3200
|
| 34 |
+
depyf/explain/patched_load_by_key_path.py,sha256=1NmSDdET0qqm0NsHg1a4q-H5T0JljEXPqVSrYInmIuY,774
|
| 35 |
+
depyf/explain/utils.py,sha256=i2MarlLUnqQAOCc0SXHUrHI5eW0LliF1vD8Wk0LfLlY,13682
|
| 36 |
+
depyf/optimization.py,sha256=0sPpOC76tzmUlHrNpI2gUZ4_qEcsUVWdkNxEu3DeeCg,2969
|
| 37 |
+
depyf/utils.py,sha256=-0AjE-vrFV-Gkgg62S83L0TO45nlbNlyuaxrLDksfrQ,3239
|
.venv/lib/python3.11/site-packages/depyf-0.18.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.41.2)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
.venv/lib/python3.11/site-packages/depyf-0.18.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
depyf
|
.venv/lib/python3.11/site-packages/opencensus/common/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
|
.venv/lib/python3.11/site-packages/opencensus/common/http_handler/__init__.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2018, OpenCensus Authors
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
try:
|
| 16 |
+
# For Python 3.0 and later
|
| 17 |
+
from urllib.request import urlopen, Request
|
| 18 |
+
from urllib.error import HTTPError, URLError
|
| 19 |
+
except ImportError:
|
| 20 |
+
# Fall back to Python 2's urllib2
|
| 21 |
+
from urllib2 import urlopen, Request
|
| 22 |
+
from urllib2 import HTTPError, URLError
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
import socket
|
| 26 |
+
|
| 27 |
+
_REQUEST_TIMEOUT = 2 # in secs
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def get_request(request_url, request_headers=dict()):
|
| 31 |
+
"""Execute http get request on given request_url with optional headers
|
| 32 |
+
"""
|
| 33 |
+
request = Request(request_url)
|
| 34 |
+
for key, val in request_headers.items():
|
| 35 |
+
request.add_header(key, val)
|
| 36 |
+
|
| 37 |
+
try:
|
| 38 |
+
response = urlopen(request, timeout=_REQUEST_TIMEOUT)
|
| 39 |
+
response_content = response.read()
|
| 40 |
+
except (HTTPError, URLError, socket.timeout):
|
| 41 |
+
response_content = None
|
| 42 |
+
|
| 43 |
+
return response_content
|
.venv/lib/python3.11/site-packages/opencensus/common/http_handler/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (1.47 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (209 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/__pycache__/aws_identity_doc_utils.cpython-311.pyc
ADDED
|
Binary file (2.9 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/__pycache__/gcp_metadata_config.cpython-311.pyc
ADDED
|
Binary file (3.97 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/__pycache__/k8s_utils.cpython-311.pyc
ADDED
|
Binary file (1.69 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/__pycache__/monitored_resource.cpython-311.pyc
ADDED
|
Binary file (2.83 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/aws_identity_doc_utils.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2018, OpenCensus Authors
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import json
|
| 16 |
+
|
| 17 |
+
from opencensus.common.http_handler import get_request
|
| 18 |
+
|
| 19 |
+
REGION_KEY = 'region'
|
| 20 |
+
ACCOUNT_ID_KEY = 'aws_account'
|
| 21 |
+
INSTANCE_ID_KEY = 'instance_id'
|
| 22 |
+
|
| 23 |
+
# AWS provides Instance Metadata via below url
|
| 24 |
+
_AWS_INSTANCE_IDENTITY_DOCUMENT_URI = \
|
| 25 |
+
"http://169.254.169.254/latest/dynamic/instance-identity/document"
|
| 26 |
+
|
| 27 |
+
_AWS_ATTRIBUTES = {
|
| 28 |
+
# Region is the AWS region for the VM. The format of this field is
|
| 29 |
+
# "aws:{region}", where supported values for {region} are listed at
|
| 30 |
+
# http://docs.aws.amazon.com/general/latest/gr/rande.html.
|
| 31 |
+
'region': REGION_KEY,
|
| 32 |
+
|
| 33 |
+
# accountId is the AWS account number for the VM.
|
| 34 |
+
'accountId': ACCOUNT_ID_KEY,
|
| 35 |
+
|
| 36 |
+
# instanceId is the instance id of the instance.
|
| 37 |
+
'instanceId': INSTANCE_ID_KEY
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
# inited is used to make sure AWS initialize executes only once.
|
| 41 |
+
inited = False
|
| 42 |
+
|
| 43 |
+
# Detects if the application is running on EC2 by making a connection to AWS
|
| 44 |
+
# instance identity document URI.If connection is successful, application
|
| 45 |
+
# should be on an EC2 instance.
|
| 46 |
+
is_running_on_aws = False
|
| 47 |
+
|
| 48 |
+
aws_metadata_map = {}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class AwsIdentityDocumentUtils(object):
|
| 52 |
+
"""Util methods for getting and parsing AWS instance identity document."""
|
| 53 |
+
|
| 54 |
+
inited = False
|
| 55 |
+
is_running = False
|
| 56 |
+
|
| 57 |
+
@classmethod
|
| 58 |
+
def _initialize_aws_identity_document(cls):
|
| 59 |
+
"""This method, tries to establish an HTTP connection to AWS instance
|
| 60 |
+
identity document url. If the application is running on an EC2
|
| 61 |
+
instance, we should be able to get back a valid JSON document. Make a
|
| 62 |
+
http get request call and store data in local map.
|
| 63 |
+
This method should only be called once.
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
+
if cls.inited:
|
| 67 |
+
return
|
| 68 |
+
|
| 69 |
+
content = get_request(_AWS_INSTANCE_IDENTITY_DOCUMENT_URI)
|
| 70 |
+
if content is not None:
|
| 71 |
+
content = json.loads(content)
|
| 72 |
+
for env_var, attribute_key in _AWS_ATTRIBUTES.items():
|
| 73 |
+
attribute_value = content.get(env_var)
|
| 74 |
+
if attribute_value is not None:
|
| 75 |
+
aws_metadata_map[attribute_key] = attribute_value
|
| 76 |
+
|
| 77 |
+
cls.is_running = True
|
| 78 |
+
|
| 79 |
+
cls.inited = True
|
| 80 |
+
|
| 81 |
+
@classmethod
|
| 82 |
+
def is_running_on_aws(cls):
|
| 83 |
+
cls._initialize_aws_identity_document()
|
| 84 |
+
return cls.is_running
|
| 85 |
+
|
| 86 |
+
def get_aws_metadata(self):
|
| 87 |
+
"""AWS Instance Identity Document is a JSON file.
|
| 88 |
+
See docs.aws.amazon.com/AWSEC2/latest/UserGuide/
|
| 89 |
+
instance-identity-documents.html.
|
| 90 |
+
:return:
|
| 91 |
+
"""
|
| 92 |
+
if self.is_running_on_aws():
|
| 93 |
+
return aws_metadata_map
|
| 94 |
+
|
| 95 |
+
return dict()
|
.venv/lib/python3.11/site-packages/opencensus/common/monitored_resource/monitored_resource.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2018, OpenCensus Authors
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from opencensus.common import resource
|
| 16 |
+
from opencensus.common.monitored_resource import (
|
| 17 |
+
aws_identity_doc_utils,
|
| 18 |
+
gcp_metadata_config,
|
| 19 |
+
k8s_utils,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Supported environments (resource types)
|
| 23 |
+
_GCE_INSTANCE = "gce_instance"
|
| 24 |
+
_K8S_CONTAINER = "k8s_container"
|
| 25 |
+
_AWS_EC2_INSTANCE = "aws_ec2_instance"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def is_gce_environment():
|
| 29 |
+
"""Whether the environment is a virtual machine on GCE."""
|
| 30 |
+
return gcp_metadata_config.GcpMetadataConfig.is_running_on_gcp()
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def is_aws_environment():
|
| 34 |
+
"""Whether the environment is a virtual machine instance on EC2."""
|
| 35 |
+
return aws_identity_doc_utils.AwsIdentityDocumentUtils.is_running_on_aws()
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def get_instance():
|
| 39 |
+
"""Get a resource based on the application environment.
|
| 40 |
+
|
| 41 |
+
Returns a `Resource` configured for the current environment, or None if the
|
| 42 |
+
environment is unknown or unsupported.
|
| 43 |
+
|
| 44 |
+
:rtype: :class:`opencensus.common.resource.Resource` or None
|
| 45 |
+
:return: A `Resource` configured for the current environment.
|
| 46 |
+
"""
|
| 47 |
+
resources = []
|
| 48 |
+
env_resource = resource.get_from_env()
|
| 49 |
+
if env_resource is not None:
|
| 50 |
+
resources.append(env_resource)
|
| 51 |
+
|
| 52 |
+
if k8s_utils.is_k8s_environment():
|
| 53 |
+
resources.append(resource.Resource(
|
| 54 |
+
_K8S_CONTAINER, k8s_utils.get_k8s_metadata()))
|
| 55 |
+
|
| 56 |
+
if is_gce_environment():
|
| 57 |
+
resources.append(resource.Resource(
|
| 58 |
+
_GCE_INSTANCE,
|
| 59 |
+
gcp_metadata_config.GcpMetadataConfig().get_gce_metadata()))
|
| 60 |
+
elif is_aws_environment():
|
| 61 |
+
resources.append(resource.Resource(
|
| 62 |
+
_AWS_EC2_INSTANCE,
|
| 63 |
+
(aws_identity_doc_utils.AwsIdentityDocumentUtils()
|
| 64 |
+
.get_aws_metadata())))
|
| 65 |
+
|
| 66 |
+
if not resources:
|
| 67 |
+
return None
|
| 68 |
+
return resource.merge_resources(resources)
|
.venv/lib/python3.11/site-packages/opencensus/common/resource/__init__.py
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019, OpenCensus Authors
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
import logging
|
| 17 |
+
import os
|
| 18 |
+
import re
|
| 19 |
+
from copy import copy
|
| 20 |
+
|
| 21 |
+
logger = logging.getLogger(__name__)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
OC_RESOURCE_TYPE = 'OC_RESOURCE_TYPE'
|
| 25 |
+
OC_RESOURCE_LABELS = 'OC_RESOURCE_LABELS'
|
| 26 |
+
|
| 27 |
+
# Matches anything outside ASCII 32-126 inclusive
|
| 28 |
+
_NON_PRINTABLE_ASCII = re.compile(
|
| 29 |
+
r'[^ !"#$%&\'()*+,\-./:;<=>?@\[\\\]^_`{|}~0-9a-zA-Z]')
|
| 30 |
+
|
| 31 |
+
# Label key/value tokens, may be quoted
|
| 32 |
+
_WORD_RES = r'(\'[^\']*\'|"[^"]*"|[^\s,=]+)'
|
| 33 |
+
|
| 34 |
+
_KV_RE = re.compile(r"""
|
| 35 |
+
\s* # ignore leading spaces
|
| 36 |
+
(?P<key>{word_re}) # capture the key word
|
| 37 |
+
\s*=\s*
|
| 38 |
+
(?P<val>{word_re}) # capture the value word
|
| 39 |
+
\s* # ignore trailing spaces
|
| 40 |
+
""".format(word_re=_WORD_RES), re.VERBOSE)
|
| 41 |
+
|
| 42 |
+
_LABELS_RE = re.compile(r"""
|
| 43 |
+
^\s*{word_re}\s*=\s*{word_re}\s* # _KV_RE without the named groups
|
| 44 |
+
(,\s*{word_re}\s*=\s*{word_re}\s*)* # more KV pairs, comma delimited
|
| 45 |
+
$
|
| 46 |
+
""".format(word_re=_WORD_RES), re.VERBOSE)
|
| 47 |
+
|
| 48 |
+
_UNQUOTE_RE = re.compile(r'^([\'"]?)([^\1]*)(\1)$')
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def merge_resources(resource_list):
|
| 52 |
+
"""Merge multiple resources to get a new resource.
|
| 53 |
+
|
| 54 |
+
Resources earlier in the list take precedence: if multiple resources share
|
| 55 |
+
a label key, use the value from the first resource in the list with that
|
| 56 |
+
key. The combined resource's type will be the first non-null type in the
|
| 57 |
+
list.
|
| 58 |
+
|
| 59 |
+
:type resource_list: list(:class:`Resource`)
|
| 60 |
+
:param resource_list: The list of resources to combine.
|
| 61 |
+
|
| 62 |
+
:rtype: :class:`Resource`
|
| 63 |
+
:return: The new combined resource.
|
| 64 |
+
"""
|
| 65 |
+
if not resource_list:
|
| 66 |
+
raise ValueError
|
| 67 |
+
rtype = None
|
| 68 |
+
for rr in resource_list:
|
| 69 |
+
if rr.type:
|
| 70 |
+
rtype = rr.type
|
| 71 |
+
break
|
| 72 |
+
labels = {}
|
| 73 |
+
for rr in reversed(resource_list):
|
| 74 |
+
labels.update(rr.labels)
|
| 75 |
+
return Resource(rtype, labels)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def check_ascii_256(string):
|
| 79 |
+
"""Check that `string` is printable ASCII and at most 256 chars.
|
| 80 |
+
|
| 81 |
+
Raise a `ValueError` if this check fails. Note that `string` itself doesn't
|
| 82 |
+
have to be ASCII-encoded.
|
| 83 |
+
|
| 84 |
+
:type string: str
|
| 85 |
+
:param string: The string to check.
|
| 86 |
+
"""
|
| 87 |
+
if string is None:
|
| 88 |
+
return
|
| 89 |
+
if len(string) > 256:
|
| 90 |
+
raise ValueError("Value is longer than 256 characters")
|
| 91 |
+
bad_char = _NON_PRINTABLE_ASCII.search(string)
|
| 92 |
+
if bad_char:
|
| 93 |
+
raise ValueError(u'Character "{}" at position {} is not printable '
|
| 94 |
+
'ASCII'
|
| 95 |
+
.format(
|
| 96 |
+
string[bad_char.start():bad_char.end()],
|
| 97 |
+
bad_char.start()))
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class Resource(object):
|
| 101 |
+
"""A description of the entity for which signals are reported.
|
| 102 |
+
|
| 103 |
+
`type_` and `labels`' keys and values should contain only printable ASCII
|
| 104 |
+
and should be at most 256 characters.
|
| 105 |
+
|
| 106 |
+
See:
|
| 107 |
+
https://github.com/census-instrumentation/opencensus-specs/blob/master/resource/Resource.md
|
| 108 |
+
|
| 109 |
+
:type type_: str
|
| 110 |
+
:param type_: The resource type identifier.
|
| 111 |
+
|
| 112 |
+
:type labels: dict
|
| 113 |
+
:param labels: Key-value pairs that describe the entity.
|
| 114 |
+
""" # noqa
|
| 115 |
+
|
| 116 |
+
def __init__(self, type_=None, labels=None):
|
| 117 |
+
if type_ is not None and not type_:
|
| 118 |
+
raise ValueError("Resource type must not be empty")
|
| 119 |
+
check_ascii_256(type_)
|
| 120 |
+
if labels is None:
|
| 121 |
+
labels = {}
|
| 122 |
+
for key, value in labels.items():
|
| 123 |
+
if not key:
|
| 124 |
+
raise ValueError("Resource key must not be null or empty")
|
| 125 |
+
if value is None:
|
| 126 |
+
raise ValueError("Resource value must not be null")
|
| 127 |
+
check_ascii_256(key)
|
| 128 |
+
check_ascii_256(value)
|
| 129 |
+
|
| 130 |
+
self.type = type_
|
| 131 |
+
self.labels = copy(labels)
|
| 132 |
+
|
| 133 |
+
def get_type(self):
|
| 134 |
+
"""Get this resource's type.
|
| 135 |
+
|
| 136 |
+
:rtype: str
|
| 137 |
+
:return: The resource's type.
|
| 138 |
+
"""
|
| 139 |
+
return self.type
|
| 140 |
+
|
| 141 |
+
def get_labels(self):
|
| 142 |
+
"""Get this resource's labels.
|
| 143 |
+
|
| 144 |
+
:rtype: dict
|
| 145 |
+
:return: The resource's label dict.
|
| 146 |
+
"""
|
| 147 |
+
return copy(self.labels)
|
| 148 |
+
|
| 149 |
+
def merge(self, other):
|
| 150 |
+
"""Get a copy of this resource combined with another resource.
|
| 151 |
+
|
| 152 |
+
The combined resource will have the union of both resources' labels,
|
| 153 |
+
keeping this resource's label values if they conflict.
|
| 154 |
+
|
| 155 |
+
:type other: :class:`Resource`
|
| 156 |
+
:param other: The other resource to merge.
|
| 157 |
+
|
| 158 |
+
:rtype: :class:`Resource`
|
| 159 |
+
:return: The new combined resource.
|
| 160 |
+
"""
|
| 161 |
+
return merge_resources([self, other])
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def unquote(string):
|
| 165 |
+
"""Strip quotes surrounding `string` if they exist.
|
| 166 |
+
|
| 167 |
+
>>> unquote('abc')
|
| 168 |
+
'abc'
|
| 169 |
+
>>> unquote('"abc"')
|
| 170 |
+
'abc'
|
| 171 |
+
>>> unquote("'abc'")
|
| 172 |
+
'abc'
|
| 173 |
+
>>> unquote('"a\\'b\\'c"')
|
| 174 |
+
"a'b'c"
|
| 175 |
+
"""
|
| 176 |
+
return _UNQUOTE_RE.sub(r'\2', string)
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def parse_labels(labels_str):
|
| 180 |
+
"""Parse label keys and values following the Resource spec.
|
| 181 |
+
|
| 182 |
+
>>> parse_labels("k=v")
|
| 183 |
+
{'k': 'v'}
|
| 184 |
+
>>> parse_labels("k1=v1, k2=v2")
|
| 185 |
+
{'k1': 'v1', 'k2': 'v2'}
|
| 186 |
+
>>> parse_labels("k1='v1,=z1'")
|
| 187 |
+
{'k1': 'v1,=z1'}
|
| 188 |
+
"""
|
| 189 |
+
if not _LABELS_RE.match(labels_str):
|
| 190 |
+
return None
|
| 191 |
+
labels = {}
|
| 192 |
+
for kv in _KV_RE.finditer(labels_str):
|
| 193 |
+
gd = kv.groupdict()
|
| 194 |
+
key = unquote(gd['key'])
|
| 195 |
+
if key in labels:
|
| 196 |
+
logger.warning('Duplicate label key "%s"', key)
|
| 197 |
+
labels[key] = unquote(gd['val'])
|
| 198 |
+
return labels
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def get_from_env():
|
| 202 |
+
"""Get a Resource from environment variables.
|
| 203 |
+
|
| 204 |
+
:rtype: :class:`Resource`
|
| 205 |
+
:return: A resource with type and labels from the environment.
|
| 206 |
+
"""
|
| 207 |
+
type_env = os.getenv(OC_RESOURCE_TYPE)
|
| 208 |
+
if type_env is None:
|
| 209 |
+
return None
|
| 210 |
+
type_env = type_env.strip()
|
| 211 |
+
|
| 212 |
+
labels_env = os.getenv(OC_RESOURCE_LABELS)
|
| 213 |
+
if labels_env is None:
|
| 214 |
+
return Resource(type_env)
|
| 215 |
+
|
| 216 |
+
labels = parse_labels(labels_env)
|
| 217 |
+
|
| 218 |
+
return Resource(type_env, labels)
|
.venv/lib/python3.11/site-packages/opencensus/common/resource/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (8.03 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/runtime_context/__init__.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019, OpenCensus Authors
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
import contextvars
|
| 18 |
+
except ImportError:
|
| 19 |
+
contextvars = None
|
| 20 |
+
|
| 21 |
+
import threading
|
| 22 |
+
|
| 23 |
+
__all__ = ['RuntimeContext']
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class _RuntimeContext(object):
|
| 27 |
+
@classmethod
|
| 28 |
+
def clear(cls):
|
| 29 |
+
"""Clear all slots to their default value."""
|
| 30 |
+
|
| 31 |
+
raise NotImplementedError # pragma: NO COVER
|
| 32 |
+
|
| 33 |
+
@classmethod
|
| 34 |
+
def register_slot(cls, name, default=None):
|
| 35 |
+
"""Register a context slot with an optional default value.
|
| 36 |
+
|
| 37 |
+
:type name: str
|
| 38 |
+
:param name: The name of the context slot.
|
| 39 |
+
|
| 40 |
+
:type default: object
|
| 41 |
+
:param name: The default value of the slot, can be a value or lambda.
|
| 42 |
+
|
| 43 |
+
:returns: The registered slot.
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
raise NotImplementedError # pragma: NO COVER
|
| 47 |
+
|
| 48 |
+
def apply(self, snapshot):
|
| 49 |
+
"""Set the current context from a given snapshot dictionary"""
|
| 50 |
+
|
| 51 |
+
for name in snapshot:
|
| 52 |
+
setattr(self, name, snapshot[name])
|
| 53 |
+
|
| 54 |
+
def snapshot(self):
|
| 55 |
+
"""Return a dictionary of current slots by reference."""
|
| 56 |
+
|
| 57 |
+
return dict((n, self._slots[n].get()) for n in self._slots.keys())
|
| 58 |
+
|
| 59 |
+
def __repr__(self):
|
| 60 |
+
return ('{}({})'.format(type(self).__name__, self.snapshot()))
|
| 61 |
+
|
| 62 |
+
def __getattr__(self, name):
|
| 63 |
+
if name not in self._slots:
|
| 64 |
+
raise AttributeError('{} is not a registered context slot'
|
| 65 |
+
.format(name))
|
| 66 |
+
slot = self._slots[name]
|
| 67 |
+
return slot.get()
|
| 68 |
+
|
| 69 |
+
def __setattr__(self, name, value):
|
| 70 |
+
if name not in self._slots:
|
| 71 |
+
raise AttributeError('{} is not a registered context slot'
|
| 72 |
+
.format(name))
|
| 73 |
+
slot = self._slots[name]
|
| 74 |
+
slot.set(value)
|
| 75 |
+
|
| 76 |
+
def with_current_context(self, func):
|
| 77 |
+
"""Capture the current context and apply it to the provided func"""
|
| 78 |
+
|
| 79 |
+
caller_context = self.snapshot()
|
| 80 |
+
|
| 81 |
+
def call_with_current_context(*args, **kwargs):
|
| 82 |
+
try:
|
| 83 |
+
backup_context = self.snapshot()
|
| 84 |
+
self.apply(caller_context)
|
| 85 |
+
return func(*args, **kwargs)
|
| 86 |
+
finally:
|
| 87 |
+
self.apply(backup_context)
|
| 88 |
+
|
| 89 |
+
return call_with_current_context
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
class _ThreadLocalRuntimeContext(_RuntimeContext):
|
| 93 |
+
_lock = threading.Lock()
|
| 94 |
+
_slots = {}
|
| 95 |
+
|
| 96 |
+
class Slot(object):
|
| 97 |
+
_thread_local = threading.local()
|
| 98 |
+
|
| 99 |
+
def __init__(self, name, default):
|
| 100 |
+
self.name = name
|
| 101 |
+
self.default = default if callable(default) else (lambda: default)
|
| 102 |
+
|
| 103 |
+
def clear(self):
|
| 104 |
+
setattr(self._thread_local, self.name, self.default())
|
| 105 |
+
|
| 106 |
+
def get(self):
|
| 107 |
+
try:
|
| 108 |
+
return getattr(self._thread_local, self.name)
|
| 109 |
+
except AttributeError:
|
| 110 |
+
value = self.default()
|
| 111 |
+
self.set(value)
|
| 112 |
+
return value
|
| 113 |
+
|
| 114 |
+
def set(self, value):
|
| 115 |
+
setattr(self._thread_local, self.name, value)
|
| 116 |
+
|
| 117 |
+
@classmethod
|
| 118 |
+
def clear(cls):
|
| 119 |
+
with cls._lock:
|
| 120 |
+
for name in cls._slots:
|
| 121 |
+
slot = cls._slots[name]
|
| 122 |
+
slot.clear()
|
| 123 |
+
|
| 124 |
+
@classmethod
|
| 125 |
+
def register_slot(cls, name, default=None):
|
| 126 |
+
with cls._lock:
|
| 127 |
+
if name in cls._slots:
|
| 128 |
+
raise ValueError('slot {} already registered'.format(name))
|
| 129 |
+
slot = cls.Slot(name, default)
|
| 130 |
+
cls._slots[name] = slot
|
| 131 |
+
return slot
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
class _AsyncRuntimeContext(_RuntimeContext):
|
| 135 |
+
_lock = threading.Lock()
|
| 136 |
+
_slots = {}
|
| 137 |
+
|
| 138 |
+
class Slot(object):
|
| 139 |
+
def __init__(self, name, default):
|
| 140 |
+
self.name = name
|
| 141 |
+
self.contextvar = contextvars.ContextVar(name)
|
| 142 |
+
self.default = default if callable(default) else (lambda: default)
|
| 143 |
+
|
| 144 |
+
def clear(self):
|
| 145 |
+
self.contextvar.set(self.default())
|
| 146 |
+
|
| 147 |
+
def get(self):
|
| 148 |
+
try:
|
| 149 |
+
return self.contextvar.get()
|
| 150 |
+
except LookupError:
|
| 151 |
+
value = self.default()
|
| 152 |
+
self.set(value)
|
| 153 |
+
return value
|
| 154 |
+
|
| 155 |
+
def set(self, value):
|
| 156 |
+
self.contextvar.set(value)
|
| 157 |
+
|
| 158 |
+
@classmethod
|
| 159 |
+
def clear(cls):
|
| 160 |
+
with cls._lock:
|
| 161 |
+
for name in cls._slots:
|
| 162 |
+
slot = cls._slots[name]
|
| 163 |
+
slot.clear()
|
| 164 |
+
|
| 165 |
+
@classmethod
|
| 166 |
+
def register_slot(cls, name, default=None):
|
| 167 |
+
with cls._lock:
|
| 168 |
+
if name in cls._slots:
|
| 169 |
+
raise ValueError('slot {} already registered'.format(name))
|
| 170 |
+
slot = cls.Slot(name, default)
|
| 171 |
+
cls._slots[name] = slot
|
| 172 |
+
return slot
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
RuntimeContext = _ThreadLocalRuntimeContext()
|
| 176 |
+
if contextvars:
|
| 177 |
+
RuntimeContext = _AsyncRuntimeContext()
|
.venv/lib/python3.11/site-packages/opencensus/common/runtime_context/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (10.4 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/runtime_context/__pycache__/version.cpython-311.pyc
ADDED
|
Binary file (227 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/runtime_context/version.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019, OpenCensus Authors
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
__version__ = '0.1.3'
|
.venv/lib/python3.11/site-packages/opencensus/common/schedule/__init__.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019, OpenCensus Authors
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from six.moves import queue
|
| 16 |
+
|
| 17 |
+
import logging
|
| 18 |
+
import threading
|
| 19 |
+
import time
|
| 20 |
+
|
| 21 |
+
logger = logging.getLogger(__name__)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class PeriodicTask(threading.Thread):
|
| 25 |
+
"""Thread that periodically calls a given function.
|
| 26 |
+
|
| 27 |
+
:type interval: int or float
|
| 28 |
+
:param interval: Seconds between calls to the function.
|
| 29 |
+
|
| 30 |
+
:type function: function
|
| 31 |
+
:param function: The function to call.
|
| 32 |
+
|
| 33 |
+
:type args: list
|
| 34 |
+
:param args: The args passed in while calling `function`.
|
| 35 |
+
|
| 36 |
+
:type kwargs: dict
|
| 37 |
+
:param kwargs: The kwargs passed in while calling `function`.
|
| 38 |
+
|
| 39 |
+
:type name: str
|
| 40 |
+
:param name: The source of the worker. Used for naming.
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
def __init__(self, interval, function, args=None, kwargs=None, name=None):
|
| 44 |
+
super(PeriodicTask, self).__init__(name=name)
|
| 45 |
+
self.interval = interval
|
| 46 |
+
self.function = function
|
| 47 |
+
self.args = args or []
|
| 48 |
+
self.kwargs = kwargs or {}
|
| 49 |
+
self.finished = threading.Event()
|
| 50 |
+
|
| 51 |
+
def run(self):
|
| 52 |
+
wait_time = self.interval
|
| 53 |
+
while not self.finished.wait(wait_time):
|
| 54 |
+
start_time = time.time()
|
| 55 |
+
self.function(*self.args, **self.kwargs)
|
| 56 |
+
elapsed_time = time.time() - start_time
|
| 57 |
+
wait_time = max(self.interval - elapsed_time, 0)
|
| 58 |
+
|
| 59 |
+
def cancel(self):
|
| 60 |
+
self.finished.set()
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
class QueueEvent(object):
|
| 64 |
+
def __init__(self, name):
|
| 65 |
+
self.name = name
|
| 66 |
+
self.event = threading.Event()
|
| 67 |
+
|
| 68 |
+
def __repr__(self):
|
| 69 |
+
return ('{}({})'.format(type(self).__name__, self.name))
|
| 70 |
+
|
| 71 |
+
def set(self):
|
| 72 |
+
return self.event.set()
|
| 73 |
+
|
| 74 |
+
def wait(self, timeout=None):
|
| 75 |
+
return self.event.wait(timeout)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class QueueExitEvent(QueueEvent):
|
| 79 |
+
pass
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class Queue(object):
|
| 83 |
+
def __init__(self, capacity):
|
| 84 |
+
self.EXIT_EVENT = QueueExitEvent('EXIT')
|
| 85 |
+
self._queue = queue.Queue(maxsize=capacity)
|
| 86 |
+
|
| 87 |
+
def _gets(self, count, timeout):
|
| 88 |
+
start_time = time.time()
|
| 89 |
+
elapsed_time = 0
|
| 90 |
+
cnt = 0
|
| 91 |
+
while cnt < count:
|
| 92 |
+
try:
|
| 93 |
+
item = self._queue.get(block=False)
|
| 94 |
+
yield item
|
| 95 |
+
if isinstance(item, QueueEvent):
|
| 96 |
+
return
|
| 97 |
+
except queue.Empty:
|
| 98 |
+
break
|
| 99 |
+
cnt += 1
|
| 100 |
+
while cnt < count:
|
| 101 |
+
wait_time = max(timeout - elapsed_time, 0)
|
| 102 |
+
try:
|
| 103 |
+
item = self._queue.get(block=True, timeout=wait_time)
|
| 104 |
+
yield item
|
| 105 |
+
if isinstance(item, QueueEvent):
|
| 106 |
+
return
|
| 107 |
+
except queue.Empty:
|
| 108 |
+
break
|
| 109 |
+
cnt += 1
|
| 110 |
+
elapsed_time = time.time() - start_time
|
| 111 |
+
|
| 112 |
+
def gets(self, count, timeout):
|
| 113 |
+
return tuple(self._gets(count, timeout))
|
| 114 |
+
|
| 115 |
+
def is_empty(self):
|
| 116 |
+
return not self._queue.qsize()
|
| 117 |
+
|
| 118 |
+
def flush(self, timeout=None):
|
| 119 |
+
if self._queue.qsize() == 0:
|
| 120 |
+
return 0
|
| 121 |
+
start_time = time.time()
|
| 122 |
+
wait_time = timeout
|
| 123 |
+
event = QueueEvent('SYNC(timeout={})'.format(wait_time))
|
| 124 |
+
try:
|
| 125 |
+
self._queue.put(event, block=True, timeout=wait_time)
|
| 126 |
+
except queue.Full:
|
| 127 |
+
return
|
| 128 |
+
elapsed_time = time.time() - start_time
|
| 129 |
+
wait_time = timeout and max(timeout - elapsed_time, 0)
|
| 130 |
+
if event.wait(wait_time):
|
| 131 |
+
return time.time() - start_time # time taken to flush
|
| 132 |
+
|
| 133 |
+
def put(self, item, block=True, timeout=None):
|
| 134 |
+
try:
|
| 135 |
+
self._queue.put(item, block, timeout)
|
| 136 |
+
except queue.Full:
|
| 137 |
+
logger.warning('Queue is full. Dropping telemetry.')
|
| 138 |
+
|
| 139 |
+
def puts(self, items, block=True, timeout=None):
|
| 140 |
+
if block and timeout is not None:
|
| 141 |
+
start_time = time.time()
|
| 142 |
+
elapsed_time = 0
|
| 143 |
+
for item in items:
|
| 144 |
+
wait_time = max(timeout - elapsed_time, 0)
|
| 145 |
+
self.put(item, block=True, timeout=wait_time)
|
| 146 |
+
elapsed_time = time.time() - start_time
|
| 147 |
+
else:
|
| 148 |
+
for item in items:
|
| 149 |
+
self.put(item, block, timeout)
|
.venv/lib/python3.11/site-packages/opencensus/common/schedule/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (8.12 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/transports/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2018, OpenCensus Authors
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
.venv/lib/python3.11/site-packages/opencensus/common/transports/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (201 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/transports/__pycache__/async_.cpython-311.pyc
ADDED
|
Binary file (10 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/transports/__pycache__/base.cpython-311.pyc
ADDED
|
Binary file (1.02 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/transports/__pycache__/sync.cpython-311.pyc
ADDED
|
Binary file (1.14 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/common/transports/async_.py
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2018, OpenCensus Authors
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from six.moves import queue, range
|
| 16 |
+
|
| 17 |
+
import atexit
|
| 18 |
+
import logging
|
| 19 |
+
import threading
|
| 20 |
+
|
| 21 |
+
from opencensus.common.transports import base
|
| 22 |
+
from opencensus.trace import execution_context
|
| 23 |
+
|
| 24 |
+
_DEFAULT_GRACE_PERIOD = 5.0 # Seconds
|
| 25 |
+
_DEFAULT_MAX_BATCH_SIZE = 600
|
| 26 |
+
_DEFAULT_WAIT_PERIOD = 60.0 # Seconds
|
| 27 |
+
_WORKER_THREAD_NAME = 'opencensus.common.Worker'
|
| 28 |
+
_WORKER_TERMINATOR = object()
|
| 29 |
+
|
| 30 |
+
logger = logging.getLogger(__name__)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class _Worker(object):
|
| 34 |
+
"""A background thread that exports batches of data.
|
| 35 |
+
|
| 36 |
+
:type exporter: :class:`~opencensus.trace.base_exporter.Exporter` or
|
| 37 |
+
:class:`~opencensus.stats.base_exporter.StatsExporter`
|
| 38 |
+
:param exporter: Instance of Exporter object.
|
| 39 |
+
|
| 40 |
+
:type grace_period: float
|
| 41 |
+
:param grace_period: The amount of time to wait for pending data to
|
| 42 |
+
be submitted when the process is shutting down.
|
| 43 |
+
|
| 44 |
+
:type max_batch_size: int
|
| 45 |
+
:param max_batch_size: The maximum number of items to send at a time
|
| 46 |
+
in the background thread.
|
| 47 |
+
|
| 48 |
+
:type wait_period: int
|
| 49 |
+
:param wait_period: The amount of time to wait before sending the next
|
| 50 |
+
batch of data.
|
| 51 |
+
"""
|
| 52 |
+
def __init__(self, exporter,
|
| 53 |
+
grace_period=_DEFAULT_GRACE_PERIOD,
|
| 54 |
+
max_batch_size=_DEFAULT_MAX_BATCH_SIZE,
|
| 55 |
+
wait_period=_DEFAULT_WAIT_PERIOD):
|
| 56 |
+
self.exporter = exporter
|
| 57 |
+
self._grace_period = grace_period
|
| 58 |
+
self._max_batch_size = max_batch_size
|
| 59 |
+
self._wait_period = wait_period
|
| 60 |
+
self._queue = queue.Queue(0)
|
| 61 |
+
self._lock = threading.Lock()
|
| 62 |
+
self._event = threading.Event()
|
| 63 |
+
self._thread = None
|
| 64 |
+
|
| 65 |
+
@property
|
| 66 |
+
def is_alive(self):
|
| 67 |
+
"""Returns True is the background thread is running."""
|
| 68 |
+
return self._thread is not None and self._thread.is_alive()
|
| 69 |
+
|
| 70 |
+
def _get_items(self):
|
| 71 |
+
"""Get multiple items from a Queue.
|
| 72 |
+
|
| 73 |
+
Gets at least one (blocking) and at most ``max_batch_size`` items
|
| 74 |
+
(non-blocking) from a given Queue. Does not mark the items as done.
|
| 75 |
+
|
| 76 |
+
:rtype: Sequence
|
| 77 |
+
:returns: A sequence of items retrieved from the queue.
|
| 78 |
+
"""
|
| 79 |
+
items = [self._queue.get()]
|
| 80 |
+
|
| 81 |
+
while len(items) < self._max_batch_size:
|
| 82 |
+
try:
|
| 83 |
+
items.append(self._queue.get_nowait())
|
| 84 |
+
except queue.Empty:
|
| 85 |
+
break
|
| 86 |
+
|
| 87 |
+
return items
|
| 88 |
+
|
| 89 |
+
def _thread_main(self):
|
| 90 |
+
"""The entry point for the worker thread.
|
| 91 |
+
|
| 92 |
+
Pulls pending data off the queue and writes them in
|
| 93 |
+
batches to the specified tracing backend using the exporter.
|
| 94 |
+
"""
|
| 95 |
+
# Indicate that this thread is an exporter thread.
|
| 96 |
+
# Used to suppress tracking of requests in this thread
|
| 97 |
+
execution_context.set_is_exporter(True)
|
| 98 |
+
quit_ = False
|
| 99 |
+
|
| 100 |
+
while True:
|
| 101 |
+
items = self._get_items()
|
| 102 |
+
data = []
|
| 103 |
+
|
| 104 |
+
for item in items:
|
| 105 |
+
if item is _WORKER_TERMINATOR:
|
| 106 |
+
quit_ = True
|
| 107 |
+
# Continue processing items, don't break, try to process
|
| 108 |
+
# all items we got back before quitting.
|
| 109 |
+
else:
|
| 110 |
+
data.extend(item)
|
| 111 |
+
|
| 112 |
+
if data:
|
| 113 |
+
try:
|
| 114 |
+
self.exporter.emit(data)
|
| 115 |
+
except Exception:
|
| 116 |
+
logger.exception(
|
| 117 |
+
'%s failed to emit data.'
|
| 118 |
+
'Dropping %s objects from queue.',
|
| 119 |
+
self.exporter.__class__.__name__,
|
| 120 |
+
len(data))
|
| 121 |
+
pass
|
| 122 |
+
|
| 123 |
+
for _ in range(len(items)):
|
| 124 |
+
self._queue.task_done()
|
| 125 |
+
|
| 126 |
+
# self._event is set at exit, at which point we start draining the
|
| 127 |
+
# queue immediately. If self._event is unset, block for
|
| 128 |
+
# self.wait_period between each batch of exports.
|
| 129 |
+
self._event.wait(self._wait_period)
|
| 130 |
+
|
| 131 |
+
if quit_:
|
| 132 |
+
break
|
| 133 |
+
|
| 134 |
+
def start(self):
|
| 135 |
+
"""Starts the background thread.
|
| 136 |
+
|
| 137 |
+
Additionally, this registers a handler for process exit to attempt
|
| 138 |
+
to send any pending data before shutdown.
|
| 139 |
+
"""
|
| 140 |
+
with self._lock:
|
| 141 |
+
if self.is_alive:
|
| 142 |
+
return
|
| 143 |
+
|
| 144 |
+
self._thread = threading.Thread(
|
| 145 |
+
target=self._thread_main, name=_WORKER_THREAD_NAME)
|
| 146 |
+
self._thread.daemon = True
|
| 147 |
+
self._thread.start()
|
| 148 |
+
atexit.register(self._export_pending_data)
|
| 149 |
+
|
| 150 |
+
def stop(self):
|
| 151 |
+
"""Signals the background thread to stop.
|
| 152 |
+
|
| 153 |
+
This does not terminate the background thread. It simply queues the
|
| 154 |
+
stop signal. If the main process exits before the background thread
|
| 155 |
+
processes the stop signal, it will be terminated without finishing
|
| 156 |
+
work. The ``grace_period`` parameter will give the background
|
| 157 |
+
thread some time to finish processing before this function returns.
|
| 158 |
+
|
| 159 |
+
:rtype: bool
|
| 160 |
+
:returns: True if the thread terminated. False if the thread is still
|
| 161 |
+
running.
|
| 162 |
+
"""
|
| 163 |
+
if not self.is_alive:
|
| 164 |
+
return True
|
| 165 |
+
|
| 166 |
+
with self._lock:
|
| 167 |
+
self._queue.put_nowait(_WORKER_TERMINATOR)
|
| 168 |
+
self._thread.join(timeout=self._grace_period)
|
| 169 |
+
|
| 170 |
+
success = not self.is_alive
|
| 171 |
+
self._thread = None
|
| 172 |
+
|
| 173 |
+
return success
|
| 174 |
+
|
| 175 |
+
def _export_pending_data(self):
|
| 176 |
+
"""Callback that attempts to send pending data before termination."""
|
| 177 |
+
if not self.is_alive:
|
| 178 |
+
return
|
| 179 |
+
# Stop blocking between export batches
|
| 180 |
+
self._event.set()
|
| 181 |
+
self.stop()
|
| 182 |
+
|
| 183 |
+
def enqueue(self, data):
|
| 184 |
+
"""Queues data to be written by the background thread."""
|
| 185 |
+
self._queue.put_nowait(data)
|
| 186 |
+
|
| 187 |
+
def flush(self):
|
| 188 |
+
"""Submit any pending data."""
|
| 189 |
+
self._queue.join()
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
class AsyncTransport(base.Transport):
|
| 193 |
+
"""Asynchronous transport that uses a background thread.
|
| 194 |
+
|
| 195 |
+
:type exporter: :class:`~opencensus.trace.base_exporter.Exporter` or
|
| 196 |
+
:class:`~opencensus.stats.base_exporter.StatsExporter`
|
| 197 |
+
:param exporter: Instance of Exporter object.
|
| 198 |
+
|
| 199 |
+
:type grace_period: float
|
| 200 |
+
:param grace_period: The amount of time to wait for pending data to
|
| 201 |
+
be submitted when the process is shutting down.
|
| 202 |
+
|
| 203 |
+
:type max_batch_size: int
|
| 204 |
+
:param max_batch_size: The maximum number of items to send at a time
|
| 205 |
+
in the background thread.
|
| 206 |
+
|
| 207 |
+
:type wait_period: int
|
| 208 |
+
:param wait_period: The amount of time to wait before sending the next
|
| 209 |
+
batch of data.
|
| 210 |
+
"""
|
| 211 |
+
|
| 212 |
+
def __init__(self, exporter,
|
| 213 |
+
grace_period=_DEFAULT_GRACE_PERIOD,
|
| 214 |
+
max_batch_size=_DEFAULT_MAX_BATCH_SIZE,
|
| 215 |
+
wait_period=_DEFAULT_WAIT_PERIOD):
|
| 216 |
+
self.exporter = exporter
|
| 217 |
+
self.worker = _Worker(
|
| 218 |
+
exporter,
|
| 219 |
+
grace_period,
|
| 220 |
+
max_batch_size,
|
| 221 |
+
wait_period,
|
| 222 |
+
)
|
| 223 |
+
self.worker.start()
|
| 224 |
+
|
| 225 |
+
def export(self, data):
|
| 226 |
+
"""Put the trace/stats to be exported into queue."""
|
| 227 |
+
self.worker.enqueue(data)
|
| 228 |
+
|
| 229 |
+
def flush(self):
|
| 230 |
+
"""Submit any pending traces/stats."""
|
| 231 |
+
self.worker.flush()
|
.venv/lib/python3.11/site-packages/opencensus/common/transports/base.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2018, OpenCensus Authors
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Module containing base class for transport."""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class Transport(object):
|
| 19 |
+
"""Base class for transport.
|
| 20 |
+
|
| 21 |
+
Subclasses of :class:`Transport` must override :meth:`export`.
|
| 22 |
+
"""
|
| 23 |
+
def export(self, datas):
|
| 24 |
+
"""Export the data."""
|
| 25 |
+
raise NotImplementedError
|
| 26 |
+
|
| 27 |
+
def flush(self):
|
| 28 |
+
"""Submit any pending data.
|
| 29 |
+
|
| 30 |
+
For blocking/sync transports, this is a no-op.
|
| 31 |
+
"""
|
.venv/lib/python3.11/site-packages/opencensus/common/transports/sync.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2018, OpenCensus Authors
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from opencensus.common.transports import base
|
| 16 |
+
from opencensus.trace import execution_context
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class SyncTransport(base.Transport):
|
| 20 |
+
def __init__(self, exporter):
|
| 21 |
+
self.exporter = exporter
|
| 22 |
+
|
| 23 |
+
def export(self, datas):
|
| 24 |
+
# Used to suppress tracking of requests in export
|
| 25 |
+
execution_context.set_is_exporter(True)
|
| 26 |
+
self.exporter.emit(datas)
|
| 27 |
+
# Reset the context
|
| 28 |
+
execution_context.set_is_exporter(False)
|
.venv/lib/python3.11/site-packages/opencensus/common/utils/__init__.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2018, OpenCensus Authors
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
try:
|
| 16 |
+
from weakref import WeakMethod
|
| 17 |
+
except ImportError:
|
| 18 |
+
from opencensus.common.backports import WeakMethod
|
| 19 |
+
|
| 20 |
+
import calendar
|
| 21 |
+
import datetime
|
| 22 |
+
import weakref
|
| 23 |
+
|
| 24 |
+
UTF8 = 'utf-8'
|
| 25 |
+
|
| 26 |
+
# Max length is 128 bytes for a truncatable string.
|
| 27 |
+
MAX_LENGTH = 128
|
| 28 |
+
|
| 29 |
+
ISO_DATETIME_REGEX = '%Y-%m-%dT%H:%M:%S.%fZ'
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def get_truncatable_str(str_to_convert):
|
| 33 |
+
"""Truncate a string if exceed limit and record the truncated bytes
|
| 34 |
+
count.
|
| 35 |
+
"""
|
| 36 |
+
truncated, truncated_byte_count = check_str_length(
|
| 37 |
+
str_to_convert, MAX_LENGTH)
|
| 38 |
+
|
| 39 |
+
result = {
|
| 40 |
+
'value': truncated,
|
| 41 |
+
'truncated_byte_count': truncated_byte_count,
|
| 42 |
+
}
|
| 43 |
+
return result
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def check_str_length(str_to_check, limit=MAX_LENGTH):
|
| 47 |
+
"""Check the length of a string. If exceeds limit, then truncate it.
|
| 48 |
+
|
| 49 |
+
:type str_to_check: str
|
| 50 |
+
:param str_to_check: String to check.
|
| 51 |
+
|
| 52 |
+
:type limit: int
|
| 53 |
+
:param limit: The upper limit of the length.
|
| 54 |
+
|
| 55 |
+
:rtype: tuple
|
| 56 |
+
:returns: The string it self if not exceeded length, or truncated string
|
| 57 |
+
if exceeded and the truncated byte count.
|
| 58 |
+
"""
|
| 59 |
+
str_bytes = str_to_check.encode(UTF8)
|
| 60 |
+
str_len = len(str_bytes)
|
| 61 |
+
truncated_byte_count = 0
|
| 62 |
+
|
| 63 |
+
if str_len > limit:
|
| 64 |
+
truncated_byte_count = str_len - limit
|
| 65 |
+
str_bytes = str_bytes[:limit]
|
| 66 |
+
|
| 67 |
+
result = str(str_bytes.decode(UTF8, errors='ignore'))
|
| 68 |
+
|
| 69 |
+
return (result, truncated_byte_count)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def to_iso_str(ts=None):
|
| 73 |
+
"""Get an ISO 8601 string for a UTC datetime."""
|
| 74 |
+
if ts is None:
|
| 75 |
+
ts = datetime.datetime.utcnow()
|
| 76 |
+
return ts.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def timestamp_to_microseconds(timestamp):
|
| 80 |
+
"""Convert a timestamp string into a microseconds value
|
| 81 |
+
:param timestamp
|
| 82 |
+
:return time in microseconds
|
| 83 |
+
"""
|
| 84 |
+
timestamp_str = datetime.datetime.strptime(timestamp, ISO_DATETIME_REGEX)
|
| 85 |
+
epoch_time_secs = calendar.timegm(timestamp_str.timetuple())
|
| 86 |
+
epoch_time_mus = epoch_time_secs * 1e6 + timestamp_str.microsecond
|
| 87 |
+
return epoch_time_mus
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def iuniq(ible):
|
| 91 |
+
"""Get an iterator over unique items of `ible`."""
|
| 92 |
+
items = set()
|
| 93 |
+
for item in ible:
|
| 94 |
+
if item not in items:
|
| 95 |
+
items.add(item)
|
| 96 |
+
yield item
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def uniq(ible):
|
| 100 |
+
"""Get a list of unique items of `ible`."""
|
| 101 |
+
return list(iuniq(ible))
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def window(ible, length):
|
| 105 |
+
"""Split `ible` into multiple lists of length `length`.
|
| 106 |
+
|
| 107 |
+
>>> list(window(range(5), 2))
|
| 108 |
+
[[0, 1], [2, 3], [4]]
|
| 109 |
+
"""
|
| 110 |
+
if length <= 0: # pragma: NO COVER
|
| 111 |
+
raise ValueError
|
| 112 |
+
ible = iter(ible)
|
| 113 |
+
while True:
|
| 114 |
+
elts = [xx for ii, xx in zip(range(length), ible)]
|
| 115 |
+
if elts:
|
| 116 |
+
yield elts
|
| 117 |
+
else:
|
| 118 |
+
break
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def get_weakref(func):
|
| 122 |
+
"""Get a weak reference to bound or unbound `func`.
|
| 123 |
+
|
| 124 |
+
If `func` is unbound (i.e. has no __self__ attr) get a weakref.ref,
|
| 125 |
+
otherwise get a wrapper that simulates weakref.ref.
|
| 126 |
+
"""
|
| 127 |
+
if func is None:
|
| 128 |
+
raise ValueError
|
| 129 |
+
if not hasattr(func, '__self__'):
|
| 130 |
+
return weakref.ref(func)
|
| 131 |
+
return WeakMethod(func)
|
.venv/lib/python3.11/site-packages/opencensus/common/utils/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (4.68 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/metrics/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (191 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/metrics/__pycache__/label_key.cpython-311.pyc
ADDED
|
Binary file (1.79 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/metrics/__pycache__/label_value.cpython-311.pyc
ADDED
|
Binary file (1.7 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/metrics/__pycache__/transport.cpython-311.pyc
ADDED
|
Binary file (6.38 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/metrics/export/__pycache__/metric_descriptor.cpython-311.pyc
ADDED
|
Binary file (6.42 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/metrics/export/__pycache__/metric_producer.cpython-311.pyc
ADDED
|
Binary file (3.79 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/metrics/export/__pycache__/value.cpython-311.pyc
ADDED
|
Binary file (12.7 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (280 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/attributes_helper.cpython-311.pyc
ADDED
|
Binary file (1.29 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/blank_span.cpython-311.pyc
ADDED
|
Binary file (6.29 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/exceptions_status.cpython-311.pyc
ADDED
|
Binary file (804 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/integrations.cpython-311.pyc
ADDED
|
Binary file (1.74 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/link.cpython-311.pyc
ADDED
|
Binary file (2.7 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/logging_exporter.cpython-311.pyc
ADDED
|
Binary file (3.56 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/span.cpython-311.pyc
ADDED
|
Binary file (21.5 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/opencensus/trace/__pycache__/stack_trace.cpython-311.pyc
ADDED
|
Binary file (7.38 kB). View file
|
|
|