Skip to main content

A standardized, file-based telemetry toolkit for LLM Agents.

Project description

๐Ÿค– LLM Telemetry Toolkit

PyPI Version Python Versions License Typing: PEP 561

A standardized, async-first observability system for LLM Agents. Zero-latency logging, beautiful metrics, and deep telemetry for production AI systems.


โœจ Design Goals

  • Zero Latency Impact Logging happens in a background thread via queue.Queue. Your Agent's "Process Loop" is never blocked by file I/O.

  • "Masterpiece" Developer Experience From beautiful Rich-powered CLI dashboards to zero-friction @monitor_interaction decorators, every interaction feels expertly crafted.

  • Smart Parsing Automatically detects reasoning traces (<think> tags) and segregates them from the final response. Handles PII redaction intelligently.

  • Implicit Context Uses contextvars to track sessions across deep function stacks without passing session_id arguments everywhere.


โญ Features

  • Multi-Format Logging: Generate JSON dossiers, human-readable Markdown reports, and CSV datasets simultaneously.
  • Rich CLI Dashboard: Visualize your agent's performance with a beautiful terminal UI (view and stats commands).
  • Smart PII Redaction: "Smart Masking" for Emails (r***@example.com), IPs, Phones, and Credit Cards. (Opt-in)
  • Ollama Native Support: Captures deep metadata (load duration, eval count, quantization) from local Ollama providers.
  • Robust Schema: Built on Pydantic v2 for strict validation and typing.

๐Ÿš€ Installation

pip install llm-telemetry-toolkit
# Ensure you have 'rich' for the CLI experience (installed by default)

๐Ÿงช Quick Start

The toolkit uses "Smart Defaults" so you can start logging with zero configuration.

from llm_telemetry_toolkit import LLMLogger, TelemetryConfig, monitor_interaction

# 1. Zero-Config initialization
# - session_id auto-generated (session_YYYYMMDD_HHMMSS)
# - logs written to ./logs
config = TelemetryConfig() 

logger = LLMLogger(config)

# 2. Decorate your LLM function
@monitor_interaction(logger)
def chat_completion(prompt: str) -> str:
    # Simulate LLM call
    return "The sky is blue because of Rayleigh scattering."

# 3. Run!
print(chat_completion("Why is the sky blue?"))
# -> Logs are automatically written to ./logs/llm_interactions/session_.../

๐Ÿ› ๏ธ Command-Line Interface (CLI)

The toolkit comes with a "sexy" CLI for viewing logs and calculating costs.

View Logs

Displays color-coded panels with syntax highlighting for prompts and responses.

python -m llm_telemetry_toolkit.interface.cli view --session ollama_test_004910

Calculate Stats

Aggregates token counts, latency, and estimated cost.

python -m llm_telemetry_toolkit.interface.cli stats --session ollama_test_004910

Example Output:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Session Statistics: ollama_test_004910 โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Metric               โ”‚ Value                                                โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Total Interactions   โ”‚ 7                                                    โ”‚
โ”‚ Total Latency        โ”‚ 65.57s                                               โ”‚
โ”‚ Avg Latency          โ”‚ 9.37s                                                โ”‚
โ”‚ Total Cost           โ”‚ $0.00000                                             โ”‚
โ”‚ Total Tokens         โ”‚ 3268                                                 โ”‚
โ”‚  - Prompt            โ”‚ 2454                                                 โ”‚
โ”‚  - Response          โ”‚ 814                                                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โš™๏ธ Configuration

The TelemetryConfig object controls all behavior.

Field Type Default Description
session_id str session_Timestamp Unique identifier for the logging session.
base_log_dir Path ./logs Root directory for storing logs.
enable_session_logging bool True Group logs by session ID.
enable_entity_logging bool False Fork logs into entity folders (e.g., 'Company A').
output_formats List[str] ['json'] Supported: 'json', 'md', 'csv'.
mask_pii bool False Enable regex-based PII redaction. (Opt-in)
max_content_length int None Truncate prompts/responses longer than this chars.
json_indent int 2 Indentation for JSON files.

๐Ÿค– Agents & MCP Server Integration

This toolkit is designed to be the "Telemetry Layer" for Agentic frameworks or MCP Servers.

1. Manual Logging (for Traceability)

If you can't use decorators, use the manual API.

from llm_telemetry_toolkit import LLMInteraction

# ... inside your MCP tool execution ...
interaction = LLMInteraction(
    session_id="agent_run_x",
    model_name="deepseek:r1",
    prompt=tool_input,
    response=tool_output,
    response_time_seconds=latency,
    # Capture Deep Metadata from Ollama/Providers
    metadata={
        "ollama_stats": {
            "total_duration_ns": 1500000000,
            "load_duration_ns": 500000000,
            "prompt_eval_count": 45,
            "eval_count": 120
        },
        "tool_name": "web_scraper",
        "url": "example.com"
    }
)

# Non-blocking write
logger.log(interaction)

2. Context Management

Use SessionContext to implicitly pass session IDs through your call stack.

from llm_telemetry_toolkit import SessionContext

def my_deeply_nested_function():
    # Automatically picks up "user_session_abc" from context
    logger.log(interaction) 

with SessionContext("user_session_abc"):
    my_deeply_nested_function()

๐Ÿ”Ž Smart Parsing & PII

reasoning-trace extraction ()

If your model (e.g., DeepSeek R1, Groq) returns <think> blocks, the toolkit automatically extracts them into a separate thought_process field in the JSON log, keeping the response clean.

Smart Masking (PII)

Enable via TelemetryConfig(mask_pii=True). This is Opt-in and disabled by default. When enabled, sensitive data is redacted while preserving debug context:

  • Email: roy@example.com -> r***@example.com
  • IP: 192.168.1.1 -> 192.xxx.xxx.xxx
  • Credit Card: 4111 2222 3333 4444 -> 4111 xxxx xxxx 4444
  • Phone: +1 (555) 123-4567 -> +1 (555) ***-**67

๐Ÿ“ฆ Example Log Output (Ollama)

{
  "interaction_id": "ollama_test_004910_llm_0003",
  "session_id": "ollama_test_004910",
  "timestamp_utc": "2025-12-12T07:49:34.550928+00:00",
  "model_name": "ministral-3:latest",
  "provider": "ollama_local",
  "prompt": "Explain why the sky is blue in one concise sentence.",
  "response": "The sky appears blue because Earth's atmosphere scatters shorter (blue) wavelengths of sunlight more than other colors due to a phenomenon called **Rayleigh scattering**.",
  "response_time_seconds": 7.78,
  "token_count_prompt": 551,
  "token_count_response": 33,
  "metadata": {
    "ollama_details": {
      "format": "gguf",
      "family": "mistral3",
      "parameter_size": "8.9B",
      "quantization_level": "Q4_K_M"
    },
    "ollama_stats": {
      "total_duration_ns": 7757972341,
      "load_duration_ns": 6139982699,
      "eval_count": 33
    }
  }
}

๐Ÿ“ฆ License

MIT. Created by Roy Dawson IV.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_telemetry_toolkit-0.1.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_telemetry_toolkit-0.1.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file llm_telemetry_toolkit-0.1.0.tar.gz.

File metadata

  • Download URL: llm_telemetry_toolkit-0.1.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for llm_telemetry_toolkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3ff0c00ff686e6b847125b4ff400db718a9bdd42a028f6132468df436cacc8c7
MD5 19867f07636bacd351c5139bf502ee67
BLAKE2b-256 de7c5e8d170241c3e6ae0b51d674ff90d2800efac73f55cc77a4d48da114a2c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_telemetry_toolkit-0.1.0.tar.gz:

Publisher: python-publish.yml on ImYourBoyRoy/llm-telemetry-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llm_telemetry_toolkit-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_telemetry_toolkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e7ce9076eacc9eb17cfb9dff843f85ba7d239c1f3a58d5e6f4775ebe588068c
MD5 9366b08762d6ae72119c2efa9bef7802
BLAKE2b-256 df8da5561f86ca696ec619d968b49038de79349c1c425d0481e5b50a48695960

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_telemetry_toolkit-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on ImYourBoyRoy/llm-telemetry-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page