Skip to main content

Pyvider Telemetry: An opinionated, developer-friendly telemetry wrapper for Python.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

๐Ÿ๐Ÿ“ก pyvider.telemetry

Beautiful, performant, structured logging for Python.

Modern structured logging built on structlog with emoji-enhanced visual parsing and semantic Domain-Action-Status patterns.

Awesome: uv PyPI Version Python Versions Downloads

CI Coverage Type Checked Code style: ruff

Powered by Structlog Built with attrs Performance

License: Apache 2.0


Make your logs beautiful and meaningful! pyvider.telemetry transforms your application logging with visual emoji prefixes, semantic Domain-Action-Status patterns, and high-performance structured output. Perfect for development debugging, production monitoring, and everything in between.

๐Ÿค” Why pyvider.telemetry?

  • ๐ŸŽจ Visual Log Parsing: Emoji prefixes based on logger names and semantic context make logs instantly scannable
  • ๐Ÿ“Š Semantic Structure: (New!) Extensible Semantic Layers for domains like LLMs, HTTP, and Databases, with a fallback to the classic Domain-Action-Status (DAS) pattern.
  • โšก High Performance: Benchmarked >14,000 msg/sec (see details below)
  • ๐Ÿ”ง Zero Configuration: Works beautifully out of the box, configurable via environment variables or code
  • ๐ŸŽฏ Developer Experience: Thread-safe, async-ready, with comprehensive type hints for Python 3.13+

โœจ Features

  • ๐ŸŽจ Emoji-Enhanced Logging:

    • Logger Name Prefixes: ๐Ÿ”‘ User authentication successful (auth module)
    • (New!) Semantic Layer Prefixes: [๐Ÿค–][โœ๏ธ][๐Ÿ‘] LLM response generated (llm-generation-success)
    • Custom TRACE Level: Ultra-verbose debugging with ๐Ÿ‘ฃ visual markers
  • ๐Ÿ“ˆ Production Ready:

    • High Performance: >14,000 messages/second throughput (average ~40,000 msg/sec)
    • Thread Safe: Concurrent logging from multiple threads
    • Async Support: Native async/await compatibility
    • Memory Efficient: Optimized emoji caching and processor chains
  • โš™๏ธ Flexible Configuration:

    • Multiple Formats: JSON for production, key-value for development
    • Module-Level Filtering: Different log levels per component
    • Environment Variables: Zero-code configuration options
    • Service Identification: Automatic service name injection
  • ๐Ÿ—๏ธ Modern Python:

    • Python 3.13+ Exclusive: Latest language features and typing
    • Built with attrs: Immutable, validated configuration objects
    • Structlog Foundation: Industry-standard structured logging

๐Ÿš€ Installation

Requires Python 3.13 or later.

pip install pyvider-telemetry

๐Ÿ’ก Quick Start

Basic Usage

from pyvider.telemetry import setup_telemetry, logger

# Initialize with sensible defaults
setup_telemetry()

# Start logging immediately
logger.info("Application started", version="1.0.0")
logger.debug("Debug information", component="auth")
logger.error("Something went wrong", error_code="E123")

# Create component-specific loggers
auth_logger = logger.get_logger("auth.service")
auth_logger.info("User login attempt", user_id=12345)
# Output: ๐Ÿ”‘ User login attempt user_id=12345

๐Ÿ—๏ธ Semantic Logging with Layers

Go beyond the basic DAS pattern with extensible, schema-driven logging. Semantic Layers allow you to define structured logging conventions for specific domains (like LLMs, HTTP, or Databases) and automatically get rich, contextual emoji prefixes.

Example: Using the built-in llm layer

First, enable the layer in your configuration:

from pyvider.telemetry import setup_telemetry, TelemetryConfig, LoggingConfig

# Enable the 'llm' semantic layer
config = TelemetryConfig(
    logging=LoggingConfig(enabled_semantic_layers=["llm"])
)
setup_telemetry(config)

Now, log events using the layer's defined keys (like llm.provider, llm.task, llm.outcome):

from pyvider.telemetry import logger

# Log a successful LLM generation task
logger.info(
    "LLM response generated",
    **{
        "llm.provider": "openai",
        "llm.task": "generation",
        "llm.outcome": "success",
        "llm.model": "gpt-4o",
        "duration_ms": 1230,
        "llm.output.tokens": 250,
    }
)
# Output: [๐Ÿค–][โœ๏ธ][๐Ÿ‘] LLM response generated duration_ms=1230 llm.output.tokens=250

# Log a rate-limiting event from another provider
logger.warning(
    "LLM call failed",
    **{
        "llm.provider": "anthropic",
        "llm.task": "chat",
        "llm.outcome": "rate_limit",
        "llm.model": "claude-3-opus",
    }
)
# Output: [๐Ÿ“š][๐Ÿ’ฌ][โณ] LLM call failed
  • How it works: The llm layer maps the llm.provider key to provider emojis (๐Ÿค– for openai, ๐Ÿ“š for anthropic), llm.task to task emojis (โœ๏ธ for generation), and llm.outcome to outcome emojis (๐Ÿ‘ for success).
  • Extensible: You can define your own custom layers and emoji sets for your application's specific domains!
  • Legacy DAS: The original domain, action, status keys still work as a fallback if no semantic layers are active.

Custom Configuration

from pyvider.telemetry import setup_telemetry, TelemetryConfig, LoggingConfig

config = TelemetryConfig(
    service_name="my-microservice",
    logging=LoggingConfig(
        default_level="INFO",
        console_formatter="json",           # JSON for production
        # Enable built-in layers for HTTP and Database logging
        enabled_semantic_layers=["http", "database"],
        module_levels={
            "auth": "DEBUG",                # Verbose auth logging
            "database": "ERROR",            # Only DB errors
            "external.api": "WARNING",      # Minimal third-party noise
        }
    )
)

setup_telemetry(config)

Environment Variable Configuration

export PYVIDER_SERVICE_NAME="my-service"
export PYVIDER_LOG_LEVEL="INFO"
export PYVIDER_LOG_CONSOLE_FORMATTER="json"
export PYVIDER_LOG_MODULE_LEVELS="auth:DEBUG,db:ERROR"
# New: Enable semantic layers via environment
export PYVIDER_LOG_ENABLED_SEMANTIC_LAYERS="llm,http"
from pyvider.telemetry import setup_telemetry, TelemetryConfig

# Automatically loads from environment
setup_telemetry(TelemetryConfig.from_env())

Exception Logging

try:
    risky_operation()
except Exception:
    logger.exception("Operation failed",
                    operation="user_registration",
                    user_id=123)
    # Automatically includes full traceback

Ultra-Verbose TRACE Logging

from pyvider.telemetry import setup_telemetry, logger, TelemetryConfig, LoggingConfig

# Enable TRACE level for deep debugging
config = TelemetryConfig(
    logging=LoggingConfig(default_level="TRACE")
)
setup_telemetry(config)

logger.trace("Entering function", function="authenticate_user")
logger.trace("Token validation details",
            token_type="bearer", expires_in=3600)

๐Ÿ“Š Performance

pyvider.telemetry is designed for high-throughput production environments:

Scenario Performance Notes
Basic Logging ~40,000 msg/sec Key-value format with emojis
JSON Output ~38,900 msg/sec Structured production format
Multithreaded ~39,800 msg/sec Concurrent logging
Level Filtering ~68,100 msg/sec Efficiently filters by level
Large Payloads ~14,200 msg/sec Logging with larger event data
Async Logging ~43,400 msg/sec Logging from async code

Overall Average Throughput: ~40,800 msg/sec Peak Throughput: ~68,100 msg/sec

Run benchmarks yourself:

python scripts/benchmark_performance.py

python scripts/extreme_performance.py

๐ŸŽจ Emoji Reference

The emoji system is now driven by Semantic Layers. The active layers determine which log keys produce emoji prefixes.

Viewing the Active Emoji Contract

To see the complete emoji mappings for your current configuration (including any custom layers), run the following command. This is the best way to see which emojis are active.

# This will print the full emoji matrix for your active configuration
export PYVIDER_SHOW_EMOJI_MATRIX=true
python -c "from pyvider.telemetry.logger.emoji_matrix import show_emoji_matrix; show_emoji_matrix()"

Built-in Layer Emojis (Examples)

  • llm Layer:

    • Provider: llm.provider -> ๐Ÿค– (openai), ๐Ÿ“š (anthropic), ๐Ÿฆ™ (meta)
    • Task: llm.task -> โœ๏ธ (generation), ๐Ÿ’ฌ (chat), ๐Ÿ› ๏ธ (tool_use)
    • Outcome: llm.outcome -> ๐Ÿ‘ (success), ๐Ÿ”ฅ (error), โณ (rate_limit)
  • http Layer:

    • Method: http.method -> ๐Ÿ“ฅ (get), ๐Ÿ“ค (post), ๐Ÿ—‘๏ธ (delete)
    • Status Class: http.status_class -> โœ… (2xx), โš ๏ธCLIENT (4xx), ๐Ÿ”ฅSERVER (5xx)

Legacy DAS Emojis (Fallback)

These emojis are used when no semantic layers are active and you use the domain, action, and status keys.

  • Domain Emojis (Primary): ๐Ÿ”‘ auth, ๐Ÿ—„๏ธ database, ๐ŸŒ network, โš™๏ธ system
  • Action Emojis (Secondary): โžก๏ธ login, ๐Ÿ”— connect, ๐Ÿ“ค send, ๐Ÿ” query
  • Status Emojis (Tertiary): โœ… success, ๐Ÿ”ฅ error, โš ๏ธ warning, โณ attempt

๐Ÿ”ง Advanced Usage

Async Applications

import asyncio
from pyvider.telemetry import setup_telemetry, logger, shutdown_pyvider_telemetry

async def main():
    setup_telemetry()

    # Your async application code
    logger.info("Async app started")

    # Graceful shutdown
    await shutdown_pyvider_telemetry()

asyncio.run(main())

Timing Code Blocks

Easily log the duration and outcome of any code block using the timed_block context manager. It automatically handles success and failure cases.

import time
from pyvider.telemetry import logger, timed_block

# Successful operation
with timed_block(logger, "Data processing task", task_id="abc-123"):
    time.sleep(0.05)  # Simulate work
# Output: Data processing task task_id=abc-123 outcome=success duration_ms=50

# Failing operation
try:
    with timed_block(logger, "Database query", table="users"):
        raise ValueError("Connection refused")
except ValueError:
    pass # Exception is re-raised and caught here
# Output: Database query table=users outcome=error error.message='Connection refused' error.type=ValueError duration_ms=...

Production Configuration

production_config = TelemetryConfig(
    service_name="production-service",
    logging=LoggingConfig(
        default_level="INFO",               # Don't spam with DEBUG
        console_formatter="json",           # Machine-readable
        enabled_semantic_layers=["http"],   # Enable HTTP layer for request logging
        module_levels={
            "security": "DEBUG",            # Always verbose for security
            "performance": "WARNING",       # Only perf issues
            "third_party": "ERROR",         # Minimal external noise
        }
    )
)

๐Ÿ“š Documentation

For comprehensive API documentation, configuration options, and advanced usage patterns, see:

๐Ÿ“– Complete API Reference

๐Ÿ“œ License

This project is licensed under the Apache 2.0 License. See the LICENSE file for details.

๐Ÿ™ Acknowledgements

pyvider.telemetry builds upon these excellent open-source libraries:

  • structlog - The foundation for structured logging
  • attrs - Powerful data classes and configuration management

๐Ÿค– Development Transparency

AI-Assisted Development Notice: This project was developed with significant AI assistance for code generation and implementation. While AI tools performed much of the heavy lifting for writing code, documentation, and tests, all architectural decisions, design patterns, functionality requirements, and final verification were made by human developers.

Human Oversight Includes:

  • Architectural design and module structure decisions
  • API design and interface specifications
  • Feature requirements and acceptance criteria
  • Code review and functionality verification
  • Performance requirements and benchmarking validation
  • Testing strategy and coverage requirements
  • Release readiness assessment

AI Assistance Includes:

  • Code implementation based on human specifications
  • Documentation generation and formatting
  • Test case generation and implementation
  • Example script creation
  • Boilerplate and repetitive code generation

This approach allows us to leverage AI capabilities for productivity while maintaining human control over critical technical decisions and quality assurance.

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

pyvider_telemetry-0.0.16.tar.gz (79.7 kB view details)

Uploaded Source

Built Distribution

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

pyvider_telemetry-0.0.16-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

Details for the file pyvider_telemetry-0.0.16.tar.gz.

File metadata

  • Download URL: pyvider_telemetry-0.0.16.tar.gz
  • Upload date:
  • Size: 79.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.8

File hashes

Hashes for pyvider_telemetry-0.0.16.tar.gz
Algorithm Hash digest
SHA256 0897cc0de49ab52538ccccb2e0013cfcc64783045de038d2c6110c4f1b450b6d
MD5 ae78c193a11a57983e4aff280aa87c11
BLAKE2b-256 a872037f2746257010650797a929e019b47cf53fe075b027618e50be9e43213c

See more details on using hashes here.

File details

Details for the file pyvider_telemetry-0.0.16-py3-none-any.whl.

File metadata

File hashes

Hashes for pyvider_telemetry-0.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 13f550eb19b5ad50af705856cfcb6c946ccf72d3263fcbb7087ad48224d87145
MD5 3e82653af0c7adac55abbf817584bb5e
BLAKE2b-256 48e5fe68ec31bff7628b9c73a3c3588e5cbb04dc540941fe7bb0e64408c17945

See more details on using hashes here.

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