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.
Files changed (54) hide show
  1. pyrock/__init__.py +141 -0
  2. pyrock/_bedrock.py +1147 -0
  3. pyrock/_cloud.py +504 -0
  4. pyrock/_compat.py +129 -0
  5. pyrock/_context.py +171 -0
  6. pyrock/_envdetect.py +412 -0
  7. pyrock/_httpcore.py +268 -0
  8. pyrock/_noop.py +98 -0
  9. pyrock/_operation.py +1360 -0
  10. pyrock/_push.py +254 -0
  11. pyrock/_transport.py +77 -0
  12. pyrock/_types.py +35 -0
  13. pyrock/_version.py +10 -0
  14. pyrock/asgi.py +269 -0
  15. pyrock/attr.py +482 -0
  16. pyrock/config.py +310 -0
  17. pyrock/env.py +300 -0
  18. pyrock/http.py +504 -0
  19. pyrock/logs.py +669 -0
  20. pyrock/metric/__init__.py +856 -0
  21. pyrock/metric/prometheus.py +216 -0
  22. pyrock/metric/runtime.py +358 -0
  23. pyrock/privacy.py +582 -0
  24. pyrock/profile/__init__.py +58 -0
  25. pyrock/profile/_config.py +164 -0
  26. pyrock/profile/_export.py +279 -0
  27. pyrock/profile/_frames.py +91 -0
  28. pyrock/profile/_heap.py +261 -0
  29. pyrock/profile/_locks.py +337 -0
  30. pyrock/profile/_otlp.py +270 -0
  31. pyrock/profile/_pprof.py +208 -0
  32. pyrock/profile/_sampler.py +345 -0
  33. pyrock/profile/_stacks.py +85 -0
  34. pyrock/profile/debug.py +149 -0
  35. pyrock/py.typed +0 -0
  36. pyrock/server.py +824 -0
  37. pyrock/testing.py +397 -0
  38. pyrock/trace/__init__.py +704 -0
  39. pyrock/trace/http.py +155 -0
  40. pyrock/trace/otlp/__init__.py +21 -0
  41. pyrock/trace/otlp/_h2.py +1078 -0
  42. pyrock/trace/otlp/_pb.py +308 -0
  43. pyrock/trace/otlp/batch.py +272 -0
  44. pyrock/trace/otlp/grpc.py +398 -0
  45. pyrock/trace/otlp/http.py +228 -0
  46. pyrock/trace/propagator.py +50 -0
  47. pyrock/trace/sampler.py +156 -0
  48. pyrock/trace/w3c.py +147 -0
  49. pyrock/wsgi.py +247 -0
  50. pyrock_core-0.1.0.dist-info/METADATA +858 -0
  51. pyrock_core-0.1.0.dist-info/RECORD +54 -0
  52. pyrock_core-0.1.0.dist-info/WHEEL +4 -0
  53. pyrock_core-0.1.0.dist-info/entry_points.txt +2 -0
  54. 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})