aid-runtime-python 0.1.149__py3-none-any.whl → 0.1.150__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.
- aid_runtime/__init__.py +15 -1
- aid_runtime/telemetry.py +184 -0
- aid_runtime/tracing.py +5 -3
- {aid_runtime_python-0.1.149.dist-info → aid_runtime_python-0.1.150.dist-info}/METADATA +4 -1
- {aid_runtime_python-0.1.149.dist-info → aid_runtime_python-0.1.150.dist-info}/RECORD +7 -6
- {aid_runtime_python-0.1.149.dist-info → aid_runtime_python-0.1.150.dist-info}/WHEEL +0 -0
- {aid_runtime_python-0.1.149.dist-info → aid_runtime_python-0.1.150.dist-info}/top_level.txt +0 -0
aid_runtime/__init__.py
CHANGED
|
@@ -280,6 +280,14 @@ from aid_runtime.structured import (
|
|
|
280
280
|
repair_prompt,
|
|
281
281
|
run_structured,
|
|
282
282
|
)
|
|
283
|
+
from aid_runtime.telemetry import (
|
|
284
|
+
DEFAULT_ENDPOINT_ENV,
|
|
285
|
+
EXPORT_KINDS,
|
|
286
|
+
OTLP_EXTRA,
|
|
287
|
+
ExportReason,
|
|
288
|
+
ExportStatus,
|
|
289
|
+
configure_export,
|
|
290
|
+
)
|
|
283
291
|
from aid_runtime.tools import Tool, ToolExecutor
|
|
284
292
|
from aid_runtime.tracing import (
|
|
285
293
|
ATTRIBUTES,
|
|
@@ -315,7 +323,7 @@ from aid_runtime.types import (
|
|
|
315
323
|
)
|
|
316
324
|
|
|
317
325
|
#: Kept in sync with ``pyproject.toml`` by a test, so the two cannot drift.
|
|
318
|
-
__version__ = "0.1.
|
|
326
|
+
__version__ = "0.1.150"
|
|
319
327
|
|
|
320
328
|
__all__ = [
|
|
321
329
|
"ANTHROPIC_VERSION",
|
|
@@ -324,12 +332,14 @@ __all__ = [
|
|
|
324
332
|
"DEFAULT_ANTHROPIC_BASE_URL",
|
|
325
333
|
"DEFAULT_BASE_URL",
|
|
326
334
|
"DEFAULT_CANDIDATE_FACTOR",
|
|
335
|
+
"DEFAULT_ENDPOINT_ENV",
|
|
327
336
|
"DEFAULT_GEMINI_BASE_URL",
|
|
328
337
|
"DEFAULT_SYNC_TIMEOUT_SECONDS",
|
|
329
338
|
"DEFAULT_TYPESAFE_BASE_URL",
|
|
330
339
|
"DEFAULT_VERTEX_LOCATION",
|
|
331
340
|
"DEPTH_KEY",
|
|
332
341
|
"EMITTED_KEY",
|
|
342
|
+
"EXPORT_KINDS",
|
|
333
343
|
"GEMINI_API_KEY_ENV",
|
|
334
344
|
"GEN_AI_OPERATION_CHAT",
|
|
335
345
|
"INDEX_KEY",
|
|
@@ -339,6 +349,7 @@ __all__ = [
|
|
|
339
349
|
"LIMITER_KEY",
|
|
340
350
|
"MAX_STEP_DEPTH",
|
|
341
351
|
"METADATA_TOKEN_URL",
|
|
352
|
+
"OTLP_EXTRA",
|
|
342
353
|
"PRINCIPAL_KEY",
|
|
343
354
|
"REDUCED_KEY",
|
|
344
355
|
"RESERVED_KEYS",
|
|
@@ -398,6 +409,8 @@ __all__ = [
|
|
|
398
409
|
"EvalRun",
|
|
399
410
|
"ExactMatch",
|
|
400
411
|
"Example",
|
|
412
|
+
"ExportReason",
|
|
413
|
+
"ExportStatus",
|
|
401
414
|
"FakeDeterministicEmbedder",
|
|
402
415
|
"FakeProvider",
|
|
403
416
|
"FeatureDeferredError",
|
|
@@ -535,6 +548,7 @@ __all__ = [
|
|
|
535
548
|
"chunk_id_for",
|
|
536
549
|
"chunker_for",
|
|
537
550
|
"cite",
|
|
551
|
+
"configure_export",
|
|
538
552
|
"create_store",
|
|
539
553
|
"decision_cost_usd",
|
|
540
554
|
"decision_key",
|
aid_runtime/telemetry.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"""Installing the span exporter a document declared.
|
|
2
|
+
|
|
3
|
+
``observability.export`` states where spans should go, and ``observability.endpointEnv``
|
|
4
|
+
names -- never holds -- the variable carrying the collector address. Those two facts were
|
|
5
|
+
declarable from spec 0.27 and unenforced until this module: :mod:`aid_runtime.tracing`
|
|
6
|
+
writes every span through the OpenTelemetry *API*, so with no provider installed the spans
|
|
7
|
+
were recorded and dropped.
|
|
8
|
+
|
|
9
|
+
This is the one place the runtime installs a provider, and it is deliberately a function
|
|
10
|
+
the application calls rather than an import side effect. A library that configured global
|
|
11
|
+
telemetry on import would decide its host's export destination, and the entrypoint that
|
|
12
|
+
runs it belongs to the application, not to this package.
|
|
13
|
+
|
|
14
|
+
Nothing here raises. A missing endpoint or a missing exporter is reported as an
|
|
15
|
+
:class:`ExportStatus` the caller can log, because telemetry that cannot start must not stop
|
|
16
|
+
a service from serving -- the honest alternative to a silent drop is a status that names
|
|
17
|
+
what was missing.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import os
|
|
23
|
+
from dataclasses import dataclass
|
|
24
|
+
from typing import Final, Literal
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"DEFAULT_ENDPOINT_ENV",
|
|
28
|
+
"EXPORT_KINDS",
|
|
29
|
+
"OTLP_EXTRA",
|
|
30
|
+
"ExportReason",
|
|
31
|
+
"ExportStatus",
|
|
32
|
+
"configure_export",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
#: The variable an OTLP/HTTP collector address conventionally lives in, and the value a
|
|
36
|
+
#: document's ``endpointEnv`` names on every walkthrough.
|
|
37
|
+
DEFAULT_ENDPOINT_ENV: Final = "OTEL_EXPORTER_OTLP_ENDPOINT"
|
|
38
|
+
|
|
39
|
+
#: The transport this module installs. OTLP over HTTP with protobuf bodies: it needs no
|
|
40
|
+
#: gRPC runtime, and every collector that speaks OTLP speaks this half of it.
|
|
41
|
+
EXPORT_KINDS: Final[tuple[str, ...]] = ("otlp",)
|
|
42
|
+
|
|
43
|
+
#: The extra that carries the exporter, quoted back when the import fails. The SDK itself
|
|
44
|
+
#: is not enough -- the OTLP exporter is a separate distribution, which is exactly the
|
|
45
|
+
#: mistake this message exists to stop.
|
|
46
|
+
OTLP_EXTRA: Final = "aid-runtime-python[otlp]"
|
|
47
|
+
|
|
48
|
+
ExportReason = Literal[
|
|
49
|
+
"configured",
|
|
50
|
+
"already-configured",
|
|
51
|
+
"not-declared",
|
|
52
|
+
"endpoint-env-unset",
|
|
53
|
+
"exporter-not-installed",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True, slots=True)
|
|
58
|
+
class ExportStatus:
|
|
59
|
+
"""What :func:`configure_export` did, in terms a caller can log or assert on.
|
|
60
|
+
|
|
61
|
+
``configured`` is the answer to "will spans leave this process", and it is never
|
|
62
|
+
inferred from the document alone: an endpoint variable that is unset means the same
|
|
63
|
+
dropped spans as no declaration, so it reports ``False`` with a reason rather than
|
|
64
|
+
echoing the declaration back as if it had been honoured.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
configured: bool
|
|
68
|
+
reason: ExportReason
|
|
69
|
+
endpoint_env: str
|
|
70
|
+
detail: str
|
|
71
|
+
|
|
72
|
+
def as_dict(self) -> dict[str, object]:
|
|
73
|
+
"""A JSON-safe view, for a health endpoint or a startup log line."""
|
|
74
|
+
return {
|
|
75
|
+
"configured": self.configured,
|
|
76
|
+
"reason": self.reason,
|
|
77
|
+
"endpointEnv": self.endpoint_env,
|
|
78
|
+
"detail": self.detail,
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _status(
|
|
83
|
+
*,
|
|
84
|
+
configured: bool,
|
|
85
|
+
reason: ExportReason,
|
|
86
|
+
endpoint_env: str,
|
|
87
|
+
detail: str,
|
|
88
|
+
) -> ExportStatus:
|
|
89
|
+
return ExportStatus(
|
|
90
|
+
configured=configured,
|
|
91
|
+
reason=reason,
|
|
92
|
+
endpoint_env=endpoint_env,
|
|
93
|
+
detail=detail,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def configure_export(
|
|
98
|
+
*,
|
|
99
|
+
service_name: str,
|
|
100
|
+
declared: Literal["otlp", "none"] = "otlp",
|
|
101
|
+
endpoint_env: str = DEFAULT_ENDPOINT_ENV,
|
|
102
|
+
) -> ExportStatus:
|
|
103
|
+
"""Install an OTLP span exporter when the document declared one and the endpoint is set.
|
|
104
|
+
|
|
105
|
+
Call it once, at startup, before serving:
|
|
106
|
+
|
|
107
|
+
.. code-block:: python
|
|
108
|
+
|
|
109
|
+
from aid_runtime.telemetry import configure_export
|
|
110
|
+
|
|
111
|
+
status = configure_export(service_name="support-copilot")
|
|
112
|
+
if not status.configured:
|
|
113
|
+
logger.warning("tracing export inactive: %s", status.detail)
|
|
114
|
+
|
|
115
|
+
``declared`` is the document's ``observability.export`` as generated, so a document
|
|
116
|
+
that never asked for export reports ``not-declared`` instead of guessing from the
|
|
117
|
+
environment. ``endpoint_env`` is the *name* of the variable to read at call time,
|
|
118
|
+
which is what lets one image run in several environments.
|
|
119
|
+
|
|
120
|
+
Re-calling after a successful install returns ``already-configured`` and installs
|
|
121
|
+
nothing: the OpenTelemetry API forbids replacing a global provider, and quietly trying
|
|
122
|
+
would produce the warning every second call currently produces.
|
|
123
|
+
"""
|
|
124
|
+
if declared != "otlp":
|
|
125
|
+
return _status(
|
|
126
|
+
configured=False,
|
|
127
|
+
reason="not-declared",
|
|
128
|
+
endpoint_env=endpoint_env,
|
|
129
|
+
detail=(
|
|
130
|
+
"observability.export is not otlp, so no exporter is installed and spans "
|
|
131
|
+
"stay in-process"
|
|
132
|
+
),
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
endpoint = os.environ.get(endpoint_env, "").strip()
|
|
136
|
+
if not endpoint:
|
|
137
|
+
return _status(
|
|
138
|
+
configured=False,
|
|
139
|
+
reason="endpoint-env-unset",
|
|
140
|
+
endpoint_env=endpoint_env,
|
|
141
|
+
detail=(
|
|
142
|
+
f"{endpoint_env} is unset or empty, so the OTLP exporter has no collector "
|
|
143
|
+
"to send to and spans stay in-process"
|
|
144
|
+
),
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
try:
|
|
148
|
+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
|
|
149
|
+
OTLPSpanExporter,
|
|
150
|
+
)
|
|
151
|
+
from opentelemetry.sdk.resources import Resource
|
|
152
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
153
|
+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
|
154
|
+
except ImportError:
|
|
155
|
+
return _status(
|
|
156
|
+
configured=False,
|
|
157
|
+
reason="exporter-not-installed",
|
|
158
|
+
endpoint_env=endpoint_env,
|
|
159
|
+
detail=(
|
|
160
|
+
"the OpenTelemetry SDK and OTLP exporter are not installed; install "
|
|
161
|
+
f"{OTLP_EXTRA} to honour observability.export"
|
|
162
|
+
),
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
from opentelemetry import trace
|
|
166
|
+
|
|
167
|
+
existing = trace.get_tracer_provider()
|
|
168
|
+
if isinstance(existing, TracerProvider):
|
|
169
|
+
return _status(
|
|
170
|
+
configured=True,
|
|
171
|
+
reason="already-configured",
|
|
172
|
+
endpoint_env=endpoint_env,
|
|
173
|
+
detail="a tracer provider is already installed; this call installed nothing",
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
provider = TracerProvider(resource=Resource.create({"service.name": service_name}))
|
|
177
|
+
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter(endpoint=endpoint)))
|
|
178
|
+
trace.set_tracer_provider(provider)
|
|
179
|
+
return _status(
|
|
180
|
+
configured=True,
|
|
181
|
+
reason="configured",
|
|
182
|
+
endpoint_env=endpoint_env,
|
|
183
|
+
detail=f"spans export to {endpoint} over OTLP/HTTP as service {service_name}",
|
|
184
|
+
)
|
aid_runtime/tracing.py
CHANGED
|
@@ -6,9 +6,11 @@ the conventions do not cover -- which pinned alias produced the call, and what i
|
|
|
6
6
|
cost -- are namespaced under ``aid.*`` rather than smuggled into a ``gen_ai.*``
|
|
7
7
|
key with the wrong meaning.
|
|
8
8
|
|
|
9
|
-
Only the OpenTelemetry *API* is a runtime dependency
|
|
10
|
-
installed
|
|
11
|
-
|
|
9
|
+
Only the OpenTelemetry *API* is a runtime dependency, so every call here is a no-op in a
|
|
10
|
+
process that installed no provider. That is deliberate: a library must not decide a host
|
|
11
|
+
application's telemetry destination. Installing an exporter is the application's decision
|
|
12
|
+
and happens through :func:`aid_runtime.telemetry.configure_export`, which is what makes the
|
|
13
|
+
spans written here leave the process.
|
|
12
14
|
"""
|
|
13
15
|
|
|
14
16
|
from __future__ import annotations
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aid-runtime-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.150
|
|
4
4
|
Summary: The AID Framework Python runtime: model gateway with pinning and cost budgets, prompt registry, tool executor, OTel GenAI tracing, plain-async pipeline, and an eval harness that gates on statistical regression against a stored baseline.
|
|
5
5
|
Author: The AID Framework authors
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -25,8 +25,11 @@ Provides-Extra: pgvector
|
|
|
25
25
|
Requires-Dist: psycopg[binary]<4,>=3.1; extra == "pgvector"
|
|
26
26
|
Provides-Extra: deepagents
|
|
27
27
|
Requires-Dist: deepagents==0.7.32; extra == "deepagents"
|
|
28
|
+
Provides-Extra: otlp
|
|
29
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http<2,>=1.24; extra == "otlp"
|
|
28
30
|
Provides-Extra: dev
|
|
29
31
|
Requires-Dist: mypy<3,>=1.11; extra == "dev"
|
|
32
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http<2,>=1.24; extra == "dev"
|
|
30
33
|
Requires-Dist: opentelemetry-sdk<2,>=1.24; extra == "dev"
|
|
31
34
|
Requires-Dist: pytest<10,>=8; extra == "dev"
|
|
32
35
|
Requires-Dist: pytest-asyncio<2,>=0.24; extra == "dev"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
aid_runtime/__init__.py,sha256=
|
|
1
|
+
aid_runtime/__init__.py,sha256=86bjw0qQXGb_g6Tmv6hM5AFXfM45cwtMZjwrBXqM-RA,13766
|
|
2
2
|
aid_runtime/cache.py,sha256=jhw_EBd9dfWEUzYeibOvIkVBqqiLUjqF5WKEPz9GkhE,6836
|
|
3
3
|
aid_runtime/concurrency.py,sha256=z0tFQHw35ttFLKfazGBjCMPOLQOnUotE_OPpvR1piH4,2829
|
|
4
4
|
aid_runtime/control.py,sha256=y6wPn0fqYJv0nVSsjzpzfiaq1Y7zBoMxCpdrEuqkfvg,17529
|
|
@@ -12,8 +12,9 @@ aid_runtime/prompts.py,sha256=eN3p_Yc-J6pyKaL2w4I-EmwvcPKErnXBvvI_Syq13ZM,7083
|
|
|
12
12
|
aid_runtime/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
aid_runtime/steps.py,sha256=44v8-ebN77VGZePmfhBYi0KORFBrH2GWFSzlfczaJhs,12047
|
|
14
14
|
aid_runtime/structured.py,sha256=Uga-VoGJN56lUtr-M3nmUjAKGF32cAAk-p7WceUgPzg,5061
|
|
15
|
+
aid_runtime/telemetry.py,sha256=KFcOILI2QFdcmNbcRaXTCL6Im0E9r0St3uFGzszvGNM,6602
|
|
15
16
|
aid_runtime/tools.py,sha256=7LeaPI5aJioNe3vexUv94tvIRpOwxj1Ujt723qvO3UI,9906
|
|
16
|
-
aid_runtime/tracing.py,sha256=
|
|
17
|
+
aid_runtime/tracing.py,sha256=jZMl5btxcUSQQDeWGMT0lQB-YSdRW7cxl5QsJVeWE7Q,9795
|
|
17
18
|
aid_runtime/types.py,sha256=cVYgmacDIhStQT5dX_X67-q57sPBBaWC5nybtGVqVsw,10389
|
|
18
19
|
aid_runtime/agents/__init__.py,sha256=H_WKu9u0fvF56W7ccTByEv1RdayzwUfRzEKsXXDRr2A,3113
|
|
19
20
|
aid_runtime/agents/chat_model.py,sha256=fZdCmSpoECuBVGZE1s8NmT2erT33RhDuLh3yJM6kAJE,14808
|
|
@@ -56,7 +57,7 @@ aid_runtime/retrieval/rerank.py,sha256=L4ICBi9YHDzhnKVtImKh5Wzre1HDzS8at-AKDkXBJ
|
|
|
56
57
|
aid_runtime/retrieval/retriever.py,sha256=0Cx-_6Qcf2TRolFy4ktMseyyyr-WLphMYYHane0t9lA,24412
|
|
57
58
|
aid_runtime/retrieval/stores.py,sha256=mG261rUHZIzB7niiTj_DuUzcNMOd4QYENk5ArgI1iBo,6840
|
|
58
59
|
aid_runtime/retrieval/types.py,sha256=hJ5IRSD-PTfrc1xhuK6CBdX0Yr-S6L_JeSMPity8ecM,20447
|
|
59
|
-
aid_runtime_python-0.1.
|
|
60
|
-
aid_runtime_python-0.1.
|
|
61
|
-
aid_runtime_python-0.1.
|
|
62
|
-
aid_runtime_python-0.1.
|
|
60
|
+
aid_runtime_python-0.1.150.dist-info/METADATA,sha256=V_PyFw8MH7dvLHXPe6DGqt6HC43fcotGLuksuY-wd80,17163
|
|
61
|
+
aid_runtime_python-0.1.150.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
62
|
+
aid_runtime_python-0.1.150.dist-info/top_level.txt,sha256=QvODgNVRDDMmLcTnoIQ4jYnhqf-N4b9sHWEmaUUxp44,12
|
|
63
|
+
aid_runtime_python-0.1.150.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|