Skip to content

src/dazzle_back/runtime/api_tracker.py

Generated: 2026-03-30T04:38:46.770574+00:00

Commit: 615f1354a103

Language: python

Scope: dazzle_back

Purpose

External API Call Tracker.

Instruments outbound API calls to track: - Latency and response times - Success/error rates - Request/response sizes - Costs (for metered APIs like OpenAI, Stripe)

Usage: # As context manager async with api_tracker.track("stripe", "/v1/charges", "POST") as ctx: ...

Key Exports

  • ApiCostConfig
  • TrackingContext
  • ApiTracker
  • TrackedHttpxClient
  • create_openai_cost_calculator
  • configure_openai_tracking
  • configure_anthropic_tracking
  • set_request_size
  • set_response
  • set_error
  • set_cost
  • add_metadata
  • latency_ms
  • configure_cost
  • track
  • traced
  • request
  • get
  • post
  • put

Dependencies

Imports

  • __future__.annotations
  • functools
  • logging
  • time
  • collections.abc.Callable
  • contextlib.asynccontextmanager
  • dataclasses.dataclass
  • dataclasses.field
  • datetime.UTC
  • datetime.datetime
  • typing.TYPE_CHECKING
  • typing.Any
  • typing.ParamSpec
  • typing.TypeVar
  • uuid.uuid4
  • dazzle_back.runtime.ops_database.ApiCallRecord
  • dazzle_back.runtime.ops_database.OpsDatabase
  • collections.abc.AsyncGenerator
  • collections.abc.Awaitable
  • dazzle_back.events.bus.EventBus

Event Interactions

Emits: ops.api_call

Invariants and Assumptions

No invariants documented.

Tests

  • tests/integration/test_runtime_e2e.py
  • tests/integration/test_runtime_pipeline.py
  • tests/unit/test_runtime_test_routes.py
  • tests/unit/test_runtime_services.py
  • tests/unit/test_runtime_mcp_tools.py

Notes

This page was automatically generated by tools/gen_reference_docs.py.