litellm/tests/unit/proxy/telemetry/fake_database.py
devin-ai-integration[bot] 083d48f62f
feat(telemetry): keep reports in a local table with a persistent instance id and an admin export route (#45490)
* feat(telemetry): keep reports in a local table with a persistent instance id and an admin export route

* feat(telemetry): key deployment hashes from a random secret stored in the proxy DB

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(telemetry): retry a locally stored window under the same id so it is never counted twice

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* docs(telemetry): state the overlap and dedupe contract for paging stored reports

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* chore(ui): regenerate dashboard API types for the telemetry reports paging note

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* feat(telemetry): require an explicit LITELLM_TELEMETRY_DESTINATION or saved destination before recording

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* chore(ui): regenerate dashboard API types for the explicit telemetry destination

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(telemetry): register the attempt logger and create its hash secret only once a sink is built

A proxy with a database that never opts in now carries no telemetry callback
and writes no deployment hash secret to LiteLLM_Config.

---------

Co-authored-by: nate <nate@berri.ai>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-13 18:58:46 -07:00

30 lines
1.1 KiB
Python

import json
from dataclasses import dataclass
from typing import Final
from typing_extensions import LiteralString
@dataclass
class SettingsDatabase:
"""In-memory ``LiteLLM_Config`` holding the telemetry instance id, hash secret and stored groups"""
stored_groups: str | None = None
fail_reads: bool = False
instance_id: str = "persisted-install"
hash_secret: str = "persisted-secret"
inserted: tuple[str, ...] = ()
async def query_raw(self, query: LiteralString, *args: object) -> object:
if self.fail_reads:
raise OSError("db down")
if "AS value" in query:
return ({"value": self.instance_id if args[0] == "telemetry_instance_id" else self.hash_secret},)
stored: Final = self.stored_groups
return () if stored is None else ({"param_value": json.loads(stored)},)
async def execute_raw(self, query: LiteralString, *args: object) -> int:
self.inserted = (*self.inserted, str(args[0]) if args else "")
if args and args[0] == "telemetry_settings":
self.stored_groups = str(args[1])
return 1