Skip to main content

Telex APM middleware for FastAPI.

Project description

Telex Python APM Middleware

The Telex Python APM Middleware is a FastAPI middleware that monitors incoming HTTP requests. It sends request data (if the response status code is 400 or higher) to a specified Telex webhook for monitoring and analytics.

Installation

You can easily install the Telex Python APM Middleware via pip:

pip install telex-python-apm

Setup and Usage

  1. Import the Middleware In your FastAPI app, import the MonitorMiddleware class from the telex_python_apm.fastapi.middleware package.
  2. Add the Middleware to FastAPI Use app.add_middleware() to add the MonitorMiddleware and pass the webhook_url parameter.
  3. Set the Webhook URL Set your Telex channel webhook URL where the request data will be sent.

Example FastAPI Application

from fastapi import FastAPI
from telex_python_apm.fastapi.middleware import MonitorMiddleware

app = FastAPI()

# Set your Telex channel webhook URL
WEBHOOK_URL = "https://ping.telex.im/v1/webhooks/25..."

# Add the APM middleware to the FastAPI app
app.add_middleware(MonitorMiddleware, webhook_url=WEBHOOK_URL)

@app.get("/test")
async def test_route():
    return {"message": "This is a test route"}

@app.get("/client_error", status_code=400)
async def error_route():
    return {"error": "This is an error"}, 400

@app.get("/server_error", status_code=500)
async def error_route():
    return {"error": "This is an error"}, 500

Explanation

  • MonitorMiddleware: Monitors incoming requests and sends request details to the specified Telex webhook if the response status code is 400 or higher.
  • webhook_url: A URL pointing to your Telex channel webhook, which receives the request data for monitoring purposes.

Run Your Application

Once the middleware is set up, you can start your FastAPI application using uvicorn:

uvicorn main:app --reload

Replace main with the name of your Python file if necessary. The app will start on http://127.0.0.1:8000.

License

This package is licensed under the MIT License.

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

telex_python_apm-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

telex_python_apm-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: telex_python_apm-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.1

File hashes

Hashes for telex_python_apm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 308acbbc6e3e499b734fc519e7d53db1d2862e9834f80bef29429b9b5d2352de
MD5 c1032038866316c23f6cac9844516bf9
BLAKE2b-256 e342b65ded3eb1139f2394fb97e6433c6be0c5500d5861604a1cde370f3ed070

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for telex_python_apm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 397f284f3ff45acd9f413ffae2a90fe1c4df192feb5d20d3bbb0f1d83b559bc6
MD5 8463bec9784eeba9741f29320a52f9f5
BLAKE2b-256 71cfa7d0b9c355d13781d71af1d3abb5c92e8f3dd237456469a80d958ed8b7c0

See more details on using hashes here.

Supported by

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