Skip to main content

No project description provided

Project description

Organization Logo

Flytrap Flask SDK

The Flytrap Flask SDK is a lightweight tool designed for Flask applications. It enables seamless error monitoring and reporting to the Flytrap system, capturing both global and manually handled errors with minimal setup.

This guide will walk you through setting up the Flytrap Flask SDK in your project and exploring its features. If you want to use Flytrap in a production environment, refer to the Flytrap Installation Guide for complete setup instructions.

To learn more about Flytrap, check out our case study.

License: MIT

🚀 Getting Started

To start using Flytrap in your project:

  1. Visit the Flytrap Dashboard and log in.
  2. Click on New Project to create a project.
  3. You’ll be provided with a Project ID, API Key, and API Endpoint specific to your project. These values are essential for configuring the SDK.

📦 Installation

Install the Flytrap Flask SDK via pip:

pip install flytrap_flask

For more details about the package, visit the Flytrap Flask SDK on PyPi.

🛠️ Usage

  1. Initialize Flytrap: In your main application file (e.g., app.py), import the Flytrap module and initialize it with your project credentials:

    import flytrap
    
    flytrap.init({
        "project_id": "YOUR_PROJECT_ID",  # Replace with your Project ID
        "api_endpoint": "YOUR_ENDPOINT",  # Replace with your API Endpoint
        "api_key": "YOUR_API_KEY",        # Replace with your API Key
    })
    
  2. Automatically Capture Global Errors: The Flytrap Flask SDK sets up a sys.excepthook to automatically log uncaught exceptions globally, even outside Flask request cycles. This ensures all unhandled errors are captured and sent to Flytrap without additional configuration.

  3. Set Up Flask Middleware: Add the Flytrap error handler to your Flask app to automatically capture unhandled errors:

    from flask import Flask
    import flytrap
    
    app = Flask(__name__)
    
    flytrap.setup_flask_error_handler(app)
    

    This middleware intercepts any unhandled errors in your Flask routes and logs them to Flytrap, along with request metadata (e.g., HTTP method and path).

  4. Manually Capturing Exceptions: For exceptions caught in a try/except block, use the capture_exception method to log the error to Flytrap manually:

    try:
        # Your code here
        raise Exception("Something went wrong!")
    except Exception as e:
        flytrap.capture_exception(e)
    

🛠️ Example App Setup

Here’s a complete example of using Flytrap in a Flask application:

from flask import Flask
import flytrap

app = Flask(__name__)

# Initialize the Flytrap SDK
flytrap.init({
    "project_id": "YOUR_PROJECT_ID",  
    "api_endpoint": "YOUR_ENDPOINT",  
    "api_key": "YOUR_API_KEY"        
})

# Set up Flytrap middleware
flytrap.setup_flask_error_handler(app)

@app.route("/")
def home():
    return "Hello, World!"

@app.route("/unhandled-error")
def unhandled_error():
    raise Exception("Unhandled error in route")

@app.route("/handled-error")
def handled_error():
    try:
        raise Exception("Handled error in route")
    except Exception as e:
        flytrap.capture_exception(e)
        return "Handled error logged", 400

if __name__ == "__main__":
    app.run(debug=True, port=3003)

🖥️ Local End-to-End Testing with Flytrap Architecture

For full local integration with the Flytrap architecture:

  1. Install the Flytrap API: Follow the Flytrap API Repository setup guide.
  2. Install the Flytrap Processor: Refer to the Flytrap Processor Repository for instructions.
  3. View Errors in the Dashboard: Set up the Flytrap Dashboard to view and manage reported errors.
  4. Integrate the Flytrap SDK in your project.

Testing the Complete Setup

  1. Trigger errors in your application integrated with a Flytrap SDK.
  2. Confirm that errors are logged by checking:
  • Flytrap Processor Logs: Ensure errors are processed correctly.
  • Flytrap Dashboard: View processed errors, including stack traces and context.

🚀 Production Setup

If you’re looking for detailed instructions to deploy Flytrap in a production environment, refer to:

For questions or issues, feel free to open an issue in this repository or contact the Flytrap team. 🚀


🪰🪤🪲🌱🚦🛠️🪴

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

flytrap_flask-1.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

flytrap_flask-1.0.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file flytrap_flask-1.0.1.tar.gz.

File metadata

  • Download URL: flytrap_flask-1.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for flytrap_flask-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6e68268b099538e38354242e31e527e8898e9354bc4fdd1969b3b93f4f91d4fc
MD5 73e69d8a76266701482eaa1d11d0d873
BLAKE2b-256 45ab5c77177050345bf9d00e9eb8061157b54f1b63c08703b878a87a0789f3b0

See more details on using hashes here.

File details

Details for the file flytrap_flask-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: flytrap_flask-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for flytrap_flask-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e002266d36f76b4c3d7612066e9f83be4c676f0fda4014e818e12bb2acb749d8
MD5 fe30a9f1832af848d7184c230cf06bd2
BLAKE2b-256 86a25e48f5a216d0ef9467f487dc53a5c43df26971ec9621215d904d7eaa5c4a

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