policyengine-observability 0.2.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.
- policyengine_observability/__init__.py +166 -0
- policyengine_observability/adapters/__init__.py +1 -0
- policyengine_observability/adapters/fastapi.py +286 -0
- policyengine_observability/adapters/flask.py +132 -0
- policyengine_observability/config.py +164 -0
- policyengine_observability/context.py +238 -0
- policyengine_observability/integrations/__init__.py +1 -0
- policyengine_observability/integrations/httpx.py +8 -0
- policyengine_observability/logging.py +17 -0
- policyengine_observability/runtime.py +1784 -0
- policyengine_observability/segments.py +35 -0
- policyengine_observability-0.2.0.dist-info/METADATA +52 -0
- policyengine_observability-0.2.0.dist-info/RECORD +14 -0
- policyengine_observability-0.2.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterable
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
UNKNOWN_SEGMENT = "unknown_segment"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def segment_values(
|
|
11
|
+
registry: type[Enum] | Iterable[str] | None,
|
|
12
|
+
) -> frozenset[str]:
|
|
13
|
+
if registry is None:
|
|
14
|
+
return frozenset()
|
|
15
|
+
if isinstance(registry, type) and issubclass(registry, Enum):
|
|
16
|
+
return frozenset(str(member.value) for member in registry)
|
|
17
|
+
return frozenset(str(value) for value in registry)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def coerce_segment_name(
|
|
21
|
+
value: Any,
|
|
22
|
+
*,
|
|
23
|
+
registry: type[Enum] | Iterable[str] | None = None,
|
|
24
|
+
) -> tuple[str, bool]:
|
|
25
|
+
values = segment_values(registry)
|
|
26
|
+
if isinstance(value, Enum):
|
|
27
|
+
segment = str(value.value)
|
|
28
|
+
return segment, not values or segment in values
|
|
29
|
+
if isinstance(value, str):
|
|
30
|
+
return value, not values or value in values
|
|
31
|
+
try:
|
|
32
|
+
segment = str(value)
|
|
33
|
+
except BaseException:
|
|
34
|
+
return UNKNOWN_SEGMENT, False
|
|
35
|
+
return segment, False if values else True
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: policyengine-observability
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Shared PolicyEngine observability runtime for logs, timings, metrics, and OpenTelemetry.
|
|
5
|
+
Author-email: PolicyEngine <hello@policyengine.org>
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
|
+
Provides-Extra: all
|
|
8
|
+
Requires-Dist: fastapi; extra == 'all'
|
|
9
|
+
Requires-Dist: flask>=2.2; extra == 'all'
|
|
10
|
+
Requires-Dist: httpx; extra == 'all'
|
|
11
|
+
Requires-Dist: opentelemetry-api; extra == 'all'
|
|
12
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc; extra == 'all'
|
|
13
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http; extra == 'all'
|
|
14
|
+
Requires-Dist: opentelemetry-instrumentation-fastapi; extra == 'all'
|
|
15
|
+
Requires-Dist: opentelemetry-instrumentation-httpx; extra == 'all'
|
|
16
|
+
Requires-Dist: opentelemetry-sdk; extra == 'all'
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: build; extra == 'dev'
|
|
19
|
+
Requires-Dist: coverage; extra == 'dev'
|
|
20
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
21
|
+
Requires-Dist: ruff>=0.9.0; extra == 'dev'
|
|
22
|
+
Requires-Dist: towncrier>=24.8.0; extra == 'dev'
|
|
23
|
+
Provides-Extra: fastapi
|
|
24
|
+
Requires-Dist: fastapi; extra == 'fastapi'
|
|
25
|
+
Requires-Dist: opentelemetry-instrumentation-fastapi; extra == 'fastapi'
|
|
26
|
+
Provides-Extra: flask
|
|
27
|
+
Requires-Dist: flask>=2.2; extra == 'flask'
|
|
28
|
+
Provides-Extra: httpx
|
|
29
|
+
Requires-Dist: httpx; extra == 'httpx'
|
|
30
|
+
Requires-Dist: opentelemetry-instrumentation-httpx; extra == 'httpx'
|
|
31
|
+
Provides-Extra: otel
|
|
32
|
+
Requires-Dist: opentelemetry-api; extra == 'otel'
|
|
33
|
+
Requires-Dist: opentelemetry-sdk; extra == 'otel'
|
|
34
|
+
Provides-Extra: otlp-grpc
|
|
35
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc; extra == 'otlp-grpc'
|
|
36
|
+
Provides-Extra: otlp-http
|
|
37
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http; extra == 'otlp-http'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# policyengine-observability
|
|
41
|
+
|
|
42
|
+
Shared PolicyEngine observability runtime for fail-open local timings,
|
|
43
|
+
structured logs, OpenTelemetry traces, and OpenTelemetry metrics.
|
|
44
|
+
|
|
45
|
+
The package intentionally keeps framework support in adapters:
|
|
46
|
+
|
|
47
|
+
- `policyengine_observability.adapters.flask`
|
|
48
|
+
- `policyengine_observability.adapters.fastapi`
|
|
49
|
+
- `policyengine_observability.integrations.httpx`
|
|
50
|
+
|
|
51
|
+
OpenTelemetry imports are lazy. Timing and structured logging can run without
|
|
52
|
+
an OTel backend; exporting traces/metrics is opt-in through configuration.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
policyengine_observability/__init__.py,sha256=on7-kJ2b7cmTw1rN8eFRfqdHIP_EfexFGOGgL77D3Vo,3850
|
|
2
|
+
policyengine_observability/config.py,sha256=CmbYkdumKTdK-CIu_dJKigCtLhFFibfHofPbtJlI7OQ,5053
|
|
3
|
+
policyengine_observability/context.py,sha256=ZFPBy7ts8q5qIGUEcoN7iqDHhByqZLFzexGIgK5Vw2c,8155
|
|
4
|
+
policyengine_observability/logging.py,sha256=9PAAYR3b-OfxX62--kKNilN3U__Cx05nL4nywddGZmI,481
|
|
5
|
+
policyengine_observability/runtime.py,sha256=-aw-AJkukplEQ5cKhq3zcwX4bkxA9WBcXHmfVCUGwhI,62060
|
|
6
|
+
policyengine_observability/segments.py,sha256=sUMPCdS_eD1hppJxOPRy3HH97andvpd2ej72aA4tTY0,1008
|
|
7
|
+
policyengine_observability/adapters/__init__.py,sha256=gIdwm4nI4U9m44V5ThtvGv8pzJIHJYMPnPZSYpAgi2I,57
|
|
8
|
+
policyengine_observability/adapters/fastapi.py,sha256=7zgDJXw7hx4Pug8UWhQ_yFyqvPOR3zYGnmwWjHpeg74,9391
|
|
9
|
+
policyengine_observability/adapters/flask.py,sha256=4oMNKLlOvfpY1UvW3o0CU5LGBEIfiyhWEEUgOD8VKDo,4517
|
|
10
|
+
policyengine_observability/integrations/__init__.py,sha256=pUb156i2mSaPEyVD-xf8yjc33WIkc_nNygtpszcNk0U,45
|
|
11
|
+
policyengine_observability/integrations/httpx.py,sha256=Wod4m64ggtmJ-XfGhlczauFvdZHJQ3DBB2yvhB3sma0,259
|
|
12
|
+
policyengine_observability-0.2.0.dist-info/METADATA,sha256=wAGP8ZNogUNwFzjzOflAXXEDb05ZPtL2OU9eZ3nHAtY,2215
|
|
13
|
+
policyengine_observability-0.2.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
14
|
+
policyengine_observability-0.2.0.dist-info/RECORD,,
|