Skip to content

lfpratik/devtrack-sdk

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

56 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ DevTrack SDK

Plug-and-play request tracking middleware for FastAPI apps.
Built for devs who care about API usage, performance, and observability.

Status GitHub Issues GitHub Pull Requests License PyPI - Downloads


🧭 Table of Contents


🧐 About

DevTrack SDK is a powerful and lightweight middleware for FastAPI apps that automatically logs HTTP requests. Track path, method, status, duration, user agent, and more β€” right from your app with no extra configuration. Perfect for development, testing, and production environments.

Key Features:

  • ✨ Zero configuration required
  • πŸš€ Lightweight and non-blocking
  • πŸ“Š Comprehensive request tracking
  • πŸ”’ Security-first design
  • 🎯 Easy integration with FastAPI

🏁 Getting Started

🧰 Prerequisites

python >= 3.8
pip install fastapi httpx starlette

πŸ“₯ Installation

pip install devtrack-sdk

🧩 Middleware Integration

from fastapi import FastAPI
from devtrack_sdk.middleware import DevTrackMiddleware
from devtrack_sdk.controller import router as devtrack_router

app = FastAPI()
app.include_router(devtrack_router)
app.add_middleware(DevTrackMiddleware)

That's it! Your app is now tracking requests automatically.


πŸ”§ Configuration

Basic Configuration

The middleware works out of the box with sensible defaults. You can customize it by passing options:

app.add_middleware(
    DevTrackMiddleware,
    exclude_path=["/endpoint1", "/endpoint2"]  # Paths to exclude from tracking
)

Environment-based Settings

For different environments, you can configure the middleware accordingly:

import os

middleware_config = {
    "development": {
        "skip_paths": ["/docs", "/redoc", "/health"],
    },
    "production": {
        "skip_paths": ["/health", "/metrics"],
    }
}

env = os.getenv("ENV", "development")
app.add_middleware(DevTrackMiddleware, exclude_path=middleware_config[env]["skip_paths"])

πŸš€ Deployment

uvicorn main:app --reload

Test the tracking endpoint:

curl http://localhost:8000/__devtrack__/stats

🎈 Usage & CLI Tool

CLI Tool

DevTrack SDK now comes with a CLI tool (available as the "devtrack" command) to help you manage your project. For example, you can run:

devtrack -- version

to display the current SDK version, or

devtrack stat

to detect and display stats (for example, from your local endpoint).

Below is a demo screenshot of the CLI tool in action:

CLI Demo

Accessing Stats

All tracked data is stored in memory and served via:

GET /__devtrack__/stats

Response format:

{
    "total": 42,
    "entries": [
        {
            "path": "/api/users",
            "method": "GET",
            "status_code": 200,
            "timestamp": "2024-03-20T10:00:00Z",
            "duration_ms": 150.5,
            // ... other fields
        }
    ]
}

πŸ“Š Logged Fields

Each request is logged with these fields:

  • path: request endpoint
  • method: HTTP method (GET, POST, etc.)
  • status_code: HTTP response code
  • timestamp: ISO timestamp (UTC)
  • client_ip: origin IP address
  • duration_ms: time taken for request to complete
  • user_agent: browser/client making the request
  • referer: previous page (if any)
  • query_params: any query string data
  • request_body: POST/PUT payload (filtered)
  • response_size: response size in bytes
  • user_id, role: if available from headers
  • trace_id: unique ID for each request

πŸ” Security

DevTrack SDK is designed with security in mind:

  • πŸ”’ No API keys required for basic usage
  • πŸ›‘οΈ Automatic filtering of sensitive data
  • πŸ” Optional authentication for stats endpoint (coming soon)
  • 🚫 Configurable path exclusions
  • πŸ” Environment-aware configuration

For production deployments, we recommend:

  • Using environment variables for configuration
  • Implementing proper access control for the stats endpoint
  • Excluding sensitive paths from tracking
  • Monitoring the stats endpoint for unusual activity

πŸ§ͺ Testing

Run the test suite:

pytest tests/

The SDK includes comprehensive tests for:

  • Middleware functionality
  • Request tracking
  • Path exclusions
  • Error handling
  • Performance impact

⛏️ Built Using

  • πŸ”Ή FastAPI – Modern, fast web framework
  • πŸ”Ή Starlette – ASGI framework/toolkit
  • πŸ”Ή httpx – Modern HTTP client

βœ… TODO

Upcoming features and improvements:

  • In-memory logging
  • Full request metadata
  • Simplified configuration
  • 🚫 Path exclusion patterns
  • 🧰 CLI tool (with "version" and "stat" commands)
  • ⏱️ Latency percentiles (P50, P95, P99)
  • 🧩 devtrack.json configuration
  • πŸ” Token-based authentication
  • 🎯 @track() decorator
  • πŸ“ˆ Dashboard UI
  • πŸ’Ύ Database support
  • πŸ“¦ Log exporters

For more detailed plans and tasks, please refer to the TODO in the project repository.


πŸ’‘ Suggestions Welcome!

Have an idea to improve DevTrack SDK?
We'd love to hear from you β€” whether it's a feature request, performance tweak, or integration idea.

πŸ‘‰ Open an issue to share your thoughts
or
πŸ’¬ Join the discussion in GitHub Discussions

Together we can make DevTrack even better for the FastAPI ecosystem. πŸš€


🀝 Contributing

We ❀️ contributions! Please:

  1. Fork this repo
  2. Create your branch (git checkout -b feat/awesome-feature)
  3. Commit your changes (git commit -m '✨ Add awesome feature')
  4. Push to the branch (git push origin feat/awesome-feature)
  5. Open a Pull Request

Run pre-commit run --all-files before committing πŸ™


✍️ Authors


πŸŽ‰ Acknowledgements

  • ✨ Inspired by FastAPI's middleware design
  • πŸ’‘ Thanks to the open-source community for tooling and inspiration

About

Plug-and-play API analytics middleware for FastAPI. Track endpoint usage, latency, and status codes with minimal setup.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%