aid-runtime-python 0.1.149__tar.gz → 0.1.150__tar.gz

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 (117) hide show
  1. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/PKG-INFO +4 -1
  2. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/pyproject.toml +13 -1
  3. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/__init__.py +15 -1
  4. aid_runtime_python-0.1.150/src/aid_runtime/telemetry.py +184 -0
  5. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/tracing.py +5 -3
  6. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime_python.egg-info/PKG-INFO +4 -1
  7. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime_python.egg-info/SOURCES.txt +2 -0
  8. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime_python.egg-info/requires.txt +4 -0
  9. aid_runtime_python-0.1.150/tests/test_telemetry.py +226 -0
  10. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/README.md +0 -0
  11. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/setup.cfg +0 -0
  12. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/agents/__init__.py +0 -0
  13. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/agents/chat_model.py +0 -0
  14. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/agents/deep_agents.py +0 -0
  15. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/agents/engine.py +0 -0
  16. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/agents/guardrails.py +0 -0
  17. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/agents/ir.py +0 -0
  18. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/agents/loop.py +0 -0
  19. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/agents/managed.py +0 -0
  20. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/agents/memory.py +0 -0
  21. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/agents/policy.py +0 -0
  22. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/agents/state.py +0 -0
  23. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/cache.py +0 -0
  24. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/concurrency.py +0 -0
  25. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/control.py +0 -0
  26. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/cost.py +0 -0
  27. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/decisions.py +0 -0
  28. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/errors.py +0 -0
  29. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/evals/__init__.py +0 -0
  30. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/evals/dataset.py +0 -0
  31. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/evals/gate.py +0 -0
  32. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/evals/metrics.py +0 -0
  33. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/evals/predicate.py +0 -0
  34. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/evals/runner.py +0 -0
  35. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/gateway.py +0 -0
  36. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/local_trace.py +0 -0
  37. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/pipeline.py +0 -0
  38. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/prompts.py +0 -0
  39. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/providers/__init__.py +0 -0
  40. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/providers/anthropic.py +0 -0
  41. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/providers/base.py +0 -0
  42. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/providers/bedrock.py +0 -0
  43. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/providers/fake.py +0 -0
  44. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/providers/gemini.py +0 -0
  45. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/providers/gemini_wire.py +0 -0
  46. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/providers/http.py +0 -0
  47. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/providers/vertex.py +0 -0
  48. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/py.typed +0 -0
  49. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/__init__.py +0 -0
  50. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/chunking.py +0 -0
  51. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/citations.py +0 -0
  52. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/connectors.py +0 -0
  53. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/embedding.py +0 -0
  54. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/filters.py +0 -0
  55. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/gate.py +0 -0
  56. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/hybrid.py +0 -0
  57. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/knowledge_base.py +0 -0
  58. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/metrics.py +0 -0
  59. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/pgvector.py +0 -0
  60. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/rerank.py +0 -0
  61. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/retriever.py +0 -0
  62. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/stores.py +0 -0
  63. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/retrieval/types.py +0 -0
  64. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/steps.py +0 -0
  65. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/structured.py +0 -0
  66. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/tools.py +0 -0
  67. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime/types.py +0 -0
  68. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime_python.egg-info/dependency_links.txt +0 -0
  69. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/src/aid_runtime_python.egg-info/top_level.txt +0 -0
  70. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_agents_budget.py +0 -0
  71. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_agents_deep_agents.py +0 -0
  72. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_agents_hitl.py +0 -0
  73. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_agents_loop.py +0 -0
  74. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_agents_memory.py +0 -0
  75. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_anthropic_provider.py +0 -0
  76. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_bedrock_provider.py +0 -0
  77. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_cache.py +0 -0
  78. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_concurrency.py +0 -0
  79. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_control.py +0 -0
  80. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_cost.py +0 -0
  81. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_dataset.py +0 -0
  82. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_decisions.py +0 -0
  83. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_evals.py +0 -0
  84. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_evals_assert_gate.py +0 -0
  85. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_evals_decision.py +0 -0
  86. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_evals_gate.py +0 -0
  87. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_evals_predicate.py +0 -0
  88. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_gateway.py +0 -0
  89. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_gemini_provider.py +0 -0
  90. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_guardrails.py +0 -0
  91. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_guardrails_managed.py +0 -0
  92. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_guardrails_model_armor.py +0 -0
  93. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_http_provider.py +0 -0
  94. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_local_trace.py +0 -0
  95. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_package.py +0 -0
  96. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_pipeline.py +0 -0
  97. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_prompts.py +0 -0
  98. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_retrieval_chunking.py +0 -0
  99. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_retrieval_citations.py +0 -0
  100. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_retrieval_connectors.py +0 -0
  101. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_retrieval_embedding.py +0 -0
  102. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_retrieval_filters.py +0 -0
  103. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_retrieval_gate.py +0 -0
  104. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_retrieval_hybrid.py +0 -0
  105. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_retrieval_knowledge_base.py +0 -0
  106. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_retrieval_metrics.py +0 -0
  107. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_retrieval_rerank.py +0 -0
  108. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_retrieval_stores.py +0 -0
  109. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_retrieval_types.py +0 -0
  110. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_steps.py +0 -0
  111. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_streaming.py +0 -0
  112. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_structured.py +0 -0
  113. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_tool_permissions.py +0 -0
  114. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_tools.py +0 -0
  115. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_tracing.py +0 -0
  116. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_types.py +0 -0
  117. {aid_runtime_python-0.1.149 → aid_runtime_python-0.1.150}/tests/test_vertex_provider.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aid-runtime-python
3
- Version: 0.1.149
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"
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "aid-runtime-python"
7
- version = "0.1.149"
7
+ version = "0.1.150"
8
8
  description = "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."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -43,8 +43,20 @@ pgvector = ["psycopg[binary]>=3.1,<4"]
43
43
  # copies must move together, which is why the version is a single literal here and a
44
44
  # single literal there rather than a constraint that could silently widen.
45
45
  deepagents = ["deepagents==0.7.32"]
46
+ # The OTLP/HTTP span exporter. Deliberately an extra and not a core dependency:
47
+ # `opentelemetry-api` alone is enough to *write* spans, and a service that has
48
+ # not asked for an export destination should not pay for protobuf or a network
49
+ # client at import time. `aid_runtime.telemetry.configure_export` names this
50
+ # extra in the status it returns when the exporter is absent, so the fix is in
51
+ # the message rather than in a traceback.
52
+ otlp = ["opentelemetry-exporter-otlp-proto-http>=1.24,<2"]
46
53
  dev = [
47
54
  "mypy>=1.11,<3",
55
+ # Both the SDK and the OTLP exporter, so the `configured` path is covered by a
56
+ # real install rather than a stubbed import -- the exporter is a separate
57
+ # distribution from the SDK and shipping without it is the failure mode this
58
+ # extra exists to prevent.
59
+ "opentelemetry-exporter-otlp-proto-http>=1.24,<2",
48
60
  "opentelemetry-sdk>=1.24,<2",
49
61
  "pytest>=8,<10",
50
62
  "pytest-asyncio>=0.24,<2",
@@ -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.149"
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",
@@ -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
+ )
@@ -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. With no tracer provider
10
- installed every call here is a no-op, which is the correct behaviour for a library
11
- that must not decide a host application's telemetry setup for it.
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.149
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"
@@ -14,6 +14,7 @@ src/aid_runtime/prompts.py
14
14
  src/aid_runtime/py.typed
15
15
  src/aid_runtime/steps.py
16
16
  src/aid_runtime/structured.py
17
+ src/aid_runtime/telemetry.py
17
18
  src/aid_runtime/tools.py
18
19
  src/aid_runtime/tracing.py
19
20
  src/aid_runtime/types.py
@@ -106,6 +107,7 @@ tests/test_retrieval_types.py
106
107
  tests/test_steps.py
107
108
  tests/test_streaming.py
108
109
  tests/test_structured.py
110
+ tests/test_telemetry.py
109
111
  tests/test_tool_permissions.py
110
112
  tests/test_tools.py
111
113
  tests/test_tracing.py
@@ -8,10 +8,14 @@ deepagents==0.7.32
8
8
 
9
9
  [dev]
10
10
  mypy<3,>=1.11
11
+ opentelemetry-exporter-otlp-proto-http<2,>=1.24
11
12
  opentelemetry-sdk<2,>=1.24
12
13
  pytest<10,>=8
13
14
  pytest-asyncio<2,>=0.24
14
15
  ruff<1,>=0.6
15
16
 
17
+ [otlp]
18
+ opentelemetry-exporter-otlp-proto-http<2,>=1.24
19
+
16
20
  [pgvector]
17
21
  psycopg[binary]<4,>=3.1
@@ -0,0 +1,226 @@
1
+ """Installing the exporter a document declared.
2
+
3
+ ``configure_export`` writes process-global OpenTelemetry state that cannot be undone once
4
+ set, so almost every case here captures the provider it *would* install rather than
5
+ installing one: a second call in the same interpreter would report ``already-configured``
6
+ and the assertion would stop meaning anything. The one case that needs a real install runs
7
+ in a fresh interpreter, because a status reading ``configured`` is only worth trusting if a
8
+ provider that can actually export came out the other side.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import importlib.util
14
+ import json
15
+ import os
16
+ import subprocess
17
+ import sys
18
+ from typing import Any
19
+
20
+ import pytest
21
+ from opentelemetry.sdk.trace import TracerProvider
22
+ from opentelemetry.sdk.trace.export import BatchSpanProcessor
23
+ from opentelemetry.trace import ProxyTracerProvider
24
+
25
+ from aid_runtime import (
26
+ DEFAULT_ENDPOINT_ENV,
27
+ EXPORT_KINDS,
28
+ OTLP_EXTRA,
29
+ ExportStatus,
30
+ configure_export,
31
+ )
32
+ from aid_runtime.telemetry import ExportReason
33
+
34
+ ENDPOINT = "http://localhost:4318/v1/traces"
35
+ EXPORTER_MODULE = "opentelemetry.exporter.otlp.proto.http.trace_exporter"
36
+
37
+ EXPORTER_INSTALLED = importlib.util.find_spec(EXPORTER_MODULE) is not None
38
+
39
+
40
+ class Captured:
41
+ """The provider ``configure_export`` handed to the API, if it handed one over."""
42
+
43
+ provider: TracerProvider | None = None
44
+
45
+
46
+ @pytest.fixture
47
+ def captured(monkeypatch: pytest.MonkeyPatch) -> Captured:
48
+ """Intercept the global provider install so the process stays unchanged.
49
+
50
+ The unset state is simulated with the proxy the API itself returns before any
51
+ provider is set, so the "is one already installed" check is exercised for real.
52
+ """
53
+ monkeypatch.setenv(DEFAULT_ENDPOINT_ENV, ENDPOINT)
54
+ monkeypatch.setattr("opentelemetry.trace.get_tracer_provider", ProxyTracerProvider)
55
+ held = Captured()
56
+ monkeypatch.setattr(
57
+ "opentelemetry.trace.set_tracer_provider",
58
+ lambda provider: setattr(held, "provider", provider),
59
+ )
60
+ return held
61
+
62
+
63
+ def _only_processor(provider: TracerProvider) -> Any:
64
+ processors = provider._active_span_processor._span_processors
65
+ assert len(processors) == 1, "a provider with no processor exports nothing"
66
+ return processors[0]
67
+
68
+
69
+ def test_the_default_endpoint_variable_is_the_otel_standard() -> None:
70
+ assert DEFAULT_ENDPOINT_ENV == "OTEL_EXPORTER_OTLP_ENDPOINT"
71
+
72
+
73
+ def test_the_only_transport_installed_is_otlp() -> None:
74
+ assert EXPORT_KINDS == ("otlp",)
75
+
76
+
77
+ def test_a_document_that_declared_no_export_installs_nothing(
78
+ monkeypatch: pytest.MonkeyPatch,
79
+ ) -> None:
80
+ monkeypatch.setenv(DEFAULT_ENDPOINT_ENV, ENDPOINT)
81
+
82
+ status = configure_export(service_name="copilot", declared="none")
83
+
84
+ assert status.configured is False
85
+ assert status.reason == "not-declared"
86
+ assert "observability.export" in status.detail
87
+
88
+
89
+ def test_an_unset_endpoint_is_not_treated_as_a_configured_export(
90
+ monkeypatch: pytest.MonkeyPatch,
91
+ ) -> None:
92
+ monkeypatch.delenv(DEFAULT_ENDPOINT_ENV, raising=False)
93
+
94
+ status = configure_export(service_name="copilot")
95
+
96
+ assert status.configured is False
97
+ assert status.reason == "endpoint-env-unset"
98
+ assert DEFAULT_ENDPOINT_ENV in status.detail
99
+
100
+
101
+ def test_a_blank_endpoint_is_not_an_endpoint(monkeypatch: pytest.MonkeyPatch) -> None:
102
+ monkeypatch.setenv(DEFAULT_ENDPOINT_ENV, " ")
103
+
104
+ assert configure_export(service_name="copilot").reason == "endpoint-env-unset"
105
+
106
+
107
+ def test_the_variable_named_by_the_document_is_the_one_read(
108
+ monkeypatch: pytest.MonkeyPatch,
109
+ ) -> None:
110
+ monkeypatch.delenv("COLLECTOR_ADDR", raising=False)
111
+
112
+ status = configure_export(service_name="copilot", endpoint_env="COLLECTOR_ADDR")
113
+
114
+ assert status.reason == "endpoint-env-unset"
115
+ assert status.endpoint_env == "COLLECTOR_ADDR"
116
+ assert "COLLECTOR_ADDR" in status.detail
117
+
118
+
119
+ def test_a_missing_exporter_names_the_extra_that_supplies_it(
120
+ monkeypatch: pytest.MonkeyPatch,
121
+ ) -> None:
122
+ monkeypatch.setenv(DEFAULT_ENDPOINT_ENV, ENDPOINT)
123
+ # `None` in `sys.modules` makes the import raise `ImportError`, which is what an
124
+ # install without the `otlp` extra does at this exact line.
125
+ monkeypatch.setitem(sys.modules, EXPORTER_MODULE, None)
126
+
127
+ status = configure_export(service_name="copilot")
128
+
129
+ assert status.configured is False
130
+ assert status.reason == "exporter-not-installed"
131
+ assert OTLP_EXTRA in status.detail
132
+
133
+
134
+ def test_installing_the_exporter_reports_what_it_installed(captured: Captured) -> None:
135
+ status = configure_export(service_name="support-copilot")
136
+
137
+ assert status.configured is True
138
+ assert status.reason == "configured"
139
+ assert captured.provider is not None
140
+ assert captured.provider.resource.attributes["service.name"] == "support-copilot"
141
+
142
+ processor = _only_processor(captured.provider)
143
+ assert isinstance(processor, BatchSpanProcessor)
144
+ assert type(processor.span_exporter).__name__ == "OTLPSpanExporter"
145
+ assert processor.span_exporter._endpoint == ENDPOINT
146
+
147
+
148
+ def test_an_existing_provider_is_never_replaced(monkeypatch: pytest.MonkeyPatch) -> None:
149
+ monkeypatch.setenv(DEFAULT_ENDPOINT_ENV, ENDPOINT)
150
+ installed = TracerProvider()
151
+ monkeypatch.setattr("opentelemetry.trace.get_tracer_provider", lambda: installed)
152
+
153
+ def refuse(provider: object) -> None:
154
+ raise AssertionError(f"configure_export replaced a live provider: {provider!r}")
155
+
156
+ monkeypatch.setattr("opentelemetry.trace.set_tracer_provider", refuse)
157
+
158
+ status = configure_export(service_name="copilot")
159
+
160
+ assert status.configured is True
161
+ assert status.reason == "already-configured"
162
+ assert installed._active_span_processor._span_processors == ()
163
+
164
+
165
+ @pytest.mark.parametrize(
166
+ "reason",
167
+ [
168
+ "configured",
169
+ "already-configured",
170
+ "not-declared",
171
+ "endpoint-env-unset",
172
+ "exporter-not-installed",
173
+ ],
174
+ )
175
+ def test_every_reason_is_one_of_the_declared_literals(reason: ExportReason) -> None:
176
+ status = ExportStatus(
177
+ configured=reason in {"configured", "already-configured"},
178
+ reason=reason,
179
+ endpoint_env=DEFAULT_ENDPOINT_ENV,
180
+ detail="detail",
181
+ )
182
+
183
+ assert json.loads(json.dumps(status.as_dict())) == {
184
+ "configured": status.configured,
185
+ "reason": reason,
186
+ "endpointEnv": DEFAULT_ENDPOINT_ENV,
187
+ "detail": "detail",
188
+ }
189
+
190
+
191
+ def test_the_status_is_frozen() -> None:
192
+ status = configure_export(service_name="copilot", declared="none")
193
+
194
+ with pytest.raises(AttributeError):
195
+ status.reason = "configured" # type: ignore[misc]
196
+
197
+
198
+ @pytest.mark.skipif(not EXPORTER_INSTALLED, reason=f"{EXPORTER_MODULE} is not installed")
199
+ def test_a_real_interpreter_ends_up_with_an_exporting_provider() -> None:
200
+ script = (
201
+ "import json;"
202
+ "from opentelemetry import trace;"
203
+ "from opentelemetry.sdk.trace import TracerProvider;"
204
+ "from aid_runtime import configure_export;"
205
+ "status = configure_export(service_name='e2e');"
206
+ "print(json.dumps({"
207
+ "'status': status.as_dict(),"
208
+ "'installed': isinstance(trace.get_tracer_provider(), TracerProvider)"
209
+ "}))"
210
+ )
211
+ env = {**os.environ, DEFAULT_ENDPOINT_ENV: ENDPOINT}
212
+
213
+ completed = subprocess.run( # noqa: S603 - fixed argv, no shell, no user input
214
+ [sys.executable, "-c", script],
215
+ capture_output=True,
216
+ text=True,
217
+ env=env,
218
+ check=False,
219
+ timeout=120,
220
+ )
221
+
222
+ assert completed.returncode == 0, completed.stderr
223
+ reported = json.loads(completed.stdout)
224
+ assert reported["status"]["configured"] is True
225
+ assert reported["status"]["reason"] == "configured"
226
+ assert reported["installed"] is True