Kedi OpenTelemetry Instrumentation
opentelemetry-instrumentation-kedi connects Kedi's dependency-free telemetry seam to
OpenTelemetry. Importing Kedi remains a no-op; telemetry starts only after the
instrumentor is enabled.
Installation
From a Kedi source checkout with its submodules initialized:
uv sync --project kedi-otel --locked
This installs the checked-out Kedi runtime and instrumentor into
kedi-otel/.venv. Run the application in that environment. Add --extra httpx
when using HTTPX instrumentation. To install into an existing compatible
environment instead, use python -m pip install -e ./kedi-otel from the Kedi
repository root. Kedi >=0.1.1,<0.2 must already be available in that environment
or from the package index.
Usage
from opentelemetry.instrumentation.kedi import KediInstrumentor
KediInstrumentor().instrument()
Configure the application's tracer and meter providers with
service.name=kedi. Kedi does not replace the application's SDK, sampler,
resource, exporter, or Logfire configuration.
Configuration
All boolean options require actual bool values. Unknown option names and invalid
types raise immediately instead of silently weakening telemetry policy.
KediInstrumentor().instrument(
runtime_detail="lifecycle", # "off", "lifecycle", or "detailed"
agent_enabled=True,
artifacts_enabled=True,
capture_content=False,
capture_binary_content=False,
capture_source_paths=False,
capture_source_snippets=False,
capture_model_request_parameters=False,
capture_tool_definitions=False,
capture_exception_messages=False,
capture_exception_stacktraces=False,
max_metric_instruments=128,
instrument_pydantic_ai=True,
instrument_httpx=False,
tracer_provider=tracer_provider,
meter_provider=meter_provider,
)
agent_enabled controls the complete agent surface, including model and tool
calls, MCP initialization, approvals, subagents, dynamic workflows, and
CodeMode discovery and execution. CodeMode emits payload-free search tools,
get tool schema, and execute code spans in the kedi.agent instrumentation
scope, plus kedi.codemode.operations and kedi.codemode.duration metrics.
Content, binary content, source paths, source snippets, model request parameters,
tool definitions, exception messages, and exception stack traces are separate
privacy classes. All are disabled by default. Exception type remains observable;
message and stack data require their respective explicit opt-ins and are bounded.
Pydantic AI instrumentation is enabled by default. Kedi filters model request
parameters and tool definitions before they reach the configured tracer provider
unless their dedicated capture options are enabled. Pydantic's process-wide
instrumentation setting is restored only while Kedi still owns the exact setting;
a newer application owner is never overwritten.
HTTPX instrumentation requires the httpx extra and explicit
instrument_httpx=True. Enabling it is a one-way, application-owned setup action.
Kedi deliberately does not call global HTTPX uninstrument() because the upstream
instrumentor exposes no owner token and teardown could remove another library's
instrumentation.
Lifecycle
Instrumentation transitions are serialized and idempotent. Teardown attempts every
owned cleanup step even when one fails, restores the Kedi backend with an
owner-aware compare-and-restore operation, and raises
KediInstrumentationCleanupError with all cleanup causes. If setup itself fails,
the setup exception remains primary and any rollback failure is chained beneath it.