The Devzery Middleware SDK enables easy integration of request and response logging functionality into your Django application, enhancing the debugging and monitoring of API requests and responses.
The Devzery Middleware SDK helps you:
- Monitor API traffic: Capture detailed logs of requests and responses for all API calls in your application.
- Debug efficiently: Identify issues in real-time by analyzing API behavior through captured logs.
- Improve reliability: Track and monitor API performance across environments (e.g., staging, production).
By integrating this SDK, you can streamline debugging and enhance observability for your microservices.
Prerequisites
- Basic understanding of Python and Django.
- Django project set up and running.
- Devzery API Key for integration.
System Requirements
- Python version: >= 3.7
- Internet connectivity to send logs to Devzery.
Step 1: 📦 Install Devzery
pip install devzeryStep 2: Add the middleware to your Django settings.py file:
Add RequestResponseLoggingMiddleware to the MIDDLEWARE list.
MIDDLEWARE = [
# Other middlewares...
"devzery.django.middleware.DevzeryDjangoMiddleware",
]Step 3: Configure your Devzery API key and server name:
Add your Devzery API credentials in the settings.py file
DEVZERY_API_KEY = "YOUR_API_KEY" # Replace with your Devzery API key
DEVZERY_SERVER_NAME = "YOUR_MICROSERVICE_NAME" # Replace with an identifier for your microserviceMake sure to apply the middleware before defining your routes or other middlewares.
Example:
MIDDLEWARE = [
"devzery.django.middleware.DevzeryDjangoMiddleware",
]
DEVZERY_API_KEY = "YOUR API KEY"
DEVZERY_SERVER_NAME = "ANY NAME AS YOU WISH, FOR YOU TO IDENTIFY THE MICROSERVICE"Step 4: Run your Django application
python manage.py runserverThe middleware will now automatically log request and response data for each incoming request.
Step 5: Verify SDK Integration:
- Start using your application either by interacting with the User Interface or hitting APIs.
- Go back to the Devzery dahsboard and check for the integration status whether it is successful or not.
Step 1: 📦 Install Devzery
pip install devzeryStep 2: Add the middleware to your Flask application:
from devzery import Devzery
from flask import Flask
# Method 1: Pass app during initialization
app = Flask(__name__)
devzery = Devzery(
app=app,
api_key='your-api-key',
source_name='your-source-name'
)
middleware = devzery.flask_middleware()
# Method 2: Using factory pattern
app = Flask(__name__)
devzery = Devzery(
api_key='your-api-key',
source_name='your-source-name'
)
middleware = devzery.flask_middleware(app)Step 3: Run your Flask application
python app.pyThe middleware will now automatically log request and response data for each incoming request.
Step 4: Verify SDK Integration:
- Start using your application either by interacting with the User Interface or hitting APIs.
- Go back to the Devzery dashboard and check for the integration status whether it is successful or not.
Parameters and Payloads
apiKey: Authenticates requests to the Devzery API.serverName: Identifies your Mircoservice in logs.
| Prameter | Type | Description | Required |
|---|---|---|---|
apiKey |
String |
Your unique Devzery API key | Yes |
serverName |
String |
Mircoservice name or identifier | Yes |
Overview of Features
- Captures request and response data automatically.
- Sends data to Devzery for centralized logging.
- Built-in error handling and debugging logs.
Detailed Functionality
- Request Logging: Captures HTTP method, headers, and body.
- Response Logging: Captures status codes, headers, and response body.
- Error Reporting: Logs transmission errors to the console.
Verify API Key:
- Ensure the API key provided is correct and active.
Check Microservice Name:
- Confirm that the server name matches the microservice name and URL being logged.
Environment Mismatch:
- Ensure the SDK is integrated into the same environment you want to monitor (e.g., staging or production). e.g., Logs will not appear if APIs are hit on production while Devzery SDK is integrated on staging.
Middleware not logging data:
- Ensure the middleware is applied before defining routes.
Error Codes
- 401 Unauthorized: Invalid API key.
- 500 Internal Server Error: Devzery server issue.
Best Practices
- Use environment variables for sensitive data.
- Apply middleware before any route definitions or other middlewares.
- Monitor console logs during development for debugging.
Glossary
- API Key: A unique identifier for authenticating API requests.
- Middleware: A function that processes requests and responses in a python application.
- Email: [email protected]
- Feedback Mechanism: Submit feedback or issues on the GitHub Repository.
Changelog:
v1.0.0Initial release with basic request and response logging.
License
- The SDK is distributed under the
Apache 2.0 License