pyrock-core 0.1.0__py3-none-any.whl
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.
- pyrock/__init__.py +141 -0
- pyrock/_bedrock.py +1147 -0
- pyrock/_cloud.py +504 -0
- pyrock/_compat.py +129 -0
- pyrock/_context.py +171 -0
- pyrock/_envdetect.py +412 -0
- pyrock/_httpcore.py +268 -0
- pyrock/_noop.py +98 -0
- pyrock/_operation.py +1360 -0
- pyrock/_push.py +254 -0
- pyrock/_transport.py +77 -0
- pyrock/_types.py +35 -0
- pyrock/_version.py +10 -0
- pyrock/asgi.py +269 -0
- pyrock/attr.py +482 -0
- pyrock/config.py +310 -0
- pyrock/env.py +300 -0
- pyrock/http.py +504 -0
- pyrock/logs.py +669 -0
- pyrock/metric/__init__.py +856 -0
- pyrock/metric/prometheus.py +216 -0
- pyrock/metric/runtime.py +358 -0
- pyrock/privacy.py +582 -0
- pyrock/profile/__init__.py +58 -0
- pyrock/profile/_config.py +164 -0
- pyrock/profile/_export.py +279 -0
- pyrock/profile/_frames.py +91 -0
- pyrock/profile/_heap.py +261 -0
- pyrock/profile/_locks.py +337 -0
- pyrock/profile/_otlp.py +270 -0
- pyrock/profile/_pprof.py +208 -0
- pyrock/profile/_sampler.py +345 -0
- pyrock/profile/_stacks.py +85 -0
- pyrock/profile/debug.py +149 -0
- pyrock/py.typed +0 -0
- pyrock/server.py +824 -0
- pyrock/testing.py +397 -0
- pyrock/trace/__init__.py +704 -0
- pyrock/trace/http.py +155 -0
- pyrock/trace/otlp/__init__.py +21 -0
- pyrock/trace/otlp/_h2.py +1078 -0
- pyrock/trace/otlp/_pb.py +308 -0
- pyrock/trace/otlp/batch.py +272 -0
- pyrock/trace/otlp/grpc.py +398 -0
- pyrock/trace/otlp/http.py +228 -0
- pyrock/trace/propagator.py +50 -0
- pyrock/trace/sampler.py +156 -0
- pyrock/trace/w3c.py +147 -0
- pyrock/wsgi.py +247 -0
- pyrock_core-0.1.0.dist-info/METADATA +858 -0
- pyrock_core-0.1.0.dist-info/RECORD +54 -0
- pyrock_core-0.1.0.dist-info/WHEEL +4 -0
- pyrock_core-0.1.0.dist-info/entry_points.txt +2 -0
- pyrock_core-0.1.0.dist-info/licenses/LICENSE +21 -0
pyrock/__init__.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""pyrock: opinionated, zero-dependency observability built around operations.
|
|
2
|
+
|
|
3
|
+
.. code-block:: python
|
|
4
|
+
|
|
5
|
+
import pyrock
|
|
6
|
+
|
|
7
|
+
with pyrock.init(service="users-api"):
|
|
8
|
+
with pyrock.operation("process_user", attrs={"user_id": "123"},
|
|
9
|
+
metric_labels=["status"]) as op:
|
|
10
|
+
op.register(status="active")
|
|
11
|
+
|
|
12
|
+
Importing ``pyrock`` is cheap: profiling, cloud, gRPC, the server, the HTTP
|
|
13
|
+
client and the WSGI/ASGI middleware load on first use.
|
|
14
|
+
|
|
15
|
+
Logging integration classes (``BedrockHandler``, ``CorrelationFilter``, ...)
|
|
16
|
+
live in :mod:`pyrock.logs`; ``pyrock.log(level, msg, ...)`` is the helper.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import importlib
|
|
22
|
+
from typing import TYPE_CHECKING, Any
|
|
23
|
+
|
|
24
|
+
from pyrock._bedrock import (
|
|
25
|
+
Bedrock,
|
|
26
|
+
counter,
|
|
27
|
+
current,
|
|
28
|
+
current_operation,
|
|
29
|
+
current_span,
|
|
30
|
+
current_span_context,
|
|
31
|
+
debug,
|
|
32
|
+
error,
|
|
33
|
+
gauge,
|
|
34
|
+
histogram,
|
|
35
|
+
info,
|
|
36
|
+
init,
|
|
37
|
+
inject_headers,
|
|
38
|
+
log,
|
|
39
|
+
register,
|
|
40
|
+
track_loop,
|
|
41
|
+
warn,
|
|
42
|
+
warning,
|
|
43
|
+
)
|
|
44
|
+
from pyrock._context import Thread, bind
|
|
45
|
+
from pyrock._operation import (
|
|
46
|
+
Activation as Activation, # re-exported outside the __all__ contract
|
|
47
|
+
)
|
|
48
|
+
from pyrock._operation import (
|
|
49
|
+
Operation,
|
|
50
|
+
OperationScope,
|
|
51
|
+
Source,
|
|
52
|
+
SourceScope,
|
|
53
|
+
Step,
|
|
54
|
+
StepScope,
|
|
55
|
+
operation,
|
|
56
|
+
source,
|
|
57
|
+
start_operation,
|
|
58
|
+
step,
|
|
59
|
+
)
|
|
60
|
+
from pyrock._version import __version__ as __version__
|
|
61
|
+
from pyrock.attr import AttrValue, Event
|
|
62
|
+
from pyrock.config import Config, ConfigError
|
|
63
|
+
from pyrock.metric import MetricConflictError as MetricConflictError
|
|
64
|
+
from pyrock.metric import MetricLimitError as MetricLimitError
|
|
65
|
+
from pyrock.trace import SpanContext, SpanKind
|
|
66
|
+
|
|
67
|
+
if TYPE_CHECKING:
|
|
68
|
+
# Lazily loaded on first attribute access (see __getattr__ below).
|
|
69
|
+
from pyrock._cloud import CloudConfig, cloud
|
|
70
|
+
from pyrock._context import ContextThreadPoolExecutor
|
|
71
|
+
|
|
72
|
+
__all__ = [
|
|
73
|
+
"AttrValue",
|
|
74
|
+
"Bedrock",
|
|
75
|
+
"CloudConfig",
|
|
76
|
+
"Config",
|
|
77
|
+
"ConfigError",
|
|
78
|
+
"ContextThreadPoolExecutor",
|
|
79
|
+
"Event",
|
|
80
|
+
"Operation",
|
|
81
|
+
"OperationScope",
|
|
82
|
+
"Source",
|
|
83
|
+
"SourceScope",
|
|
84
|
+
"SpanContext",
|
|
85
|
+
"SpanKind",
|
|
86
|
+
"Step",
|
|
87
|
+
"StepScope",
|
|
88
|
+
"Thread",
|
|
89
|
+
"bind",
|
|
90
|
+
"cloud",
|
|
91
|
+
"counter",
|
|
92
|
+
"current",
|
|
93
|
+
"current_operation",
|
|
94
|
+
"current_span",
|
|
95
|
+
"current_span_context",
|
|
96
|
+
"debug",
|
|
97
|
+
"error",
|
|
98
|
+
"gauge",
|
|
99
|
+
"histogram",
|
|
100
|
+
"info",
|
|
101
|
+
"init",
|
|
102
|
+
"inject_headers",
|
|
103
|
+
"log",
|
|
104
|
+
"operation",
|
|
105
|
+
"register",
|
|
106
|
+
"source",
|
|
107
|
+
"start_operation",
|
|
108
|
+
"step",
|
|
109
|
+
"track_loop",
|
|
110
|
+
"warn",
|
|
111
|
+
"warning",
|
|
112
|
+
]
|
|
113
|
+
|
|
114
|
+
# name -> (module, attribute or None for the module itself). ``env`` and ``logs``
|
|
115
|
+
# need no entry: the core imports them, which binds them as attributes.
|
|
116
|
+
_LAZY: dict[str, tuple[str, str | None]] = {
|
|
117
|
+
"CloudConfig": ("pyrock._cloud", "CloudConfig"),
|
|
118
|
+
"ContextThreadPoolExecutor": ("pyrock._context", "ContextThreadPoolExecutor"),
|
|
119
|
+
"cloud": ("pyrock._cloud", "cloud"),
|
|
120
|
+
"asgi": ("pyrock.asgi", None),
|
|
121
|
+
"http": ("pyrock.http", None),
|
|
122
|
+
"profile": ("pyrock.profile", None),
|
|
123
|
+
"server": ("pyrock.server", None),
|
|
124
|
+
"testing": ("pyrock.testing", None),
|
|
125
|
+
"wsgi": ("pyrock.wsgi", None),
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def __getattr__(name: str) -> Any:
|
|
130
|
+
try:
|
|
131
|
+
module_name, attr_name = _LAZY[name]
|
|
132
|
+
except KeyError:
|
|
133
|
+
raise AttributeError(f"module 'pyrock' has no attribute {name!r}") from None
|
|
134
|
+
module = importlib.import_module(module_name)
|
|
135
|
+
value = module if attr_name is None else getattr(module, attr_name)
|
|
136
|
+
globals()[name] = value
|
|
137
|
+
return value
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def __dir__() -> list[str]:
|
|
141
|
+
return sorted({*globals(), *_LAZY})
|