Elasticsearch Logger Middleware for FastAPI
Project description
Elasticsearch Logger Middleware for FastAPI
Elasticsearch Logger Middleware for FastAPI is designed to facilitate detailed and efficient logging directly to Elasticsearch servers from FastAPI applications. It streamlines the logging processes by capturing detailed HTTP requests data and automates telemetry to provide insights into application performance.
Key Features
- Elasticsearch Integration: Send logs directly to an Elasticsearch server.
- Flexible Configuration: Configure to suit various environment needs.
- Automated Detailed Data Logging: Automatically captures headers, query parameters, and the request body.
- Effortless Telemetry: Automatically generates telemetry for monitoring request times.
- Enhanced Data Control: Limit payload sizes for efficient Elasticsearch indexing.
Installation
To install this middleware, ensure you have Python installed and then run:
pip install fastapi-elasticsearch-middleware
Usage
Configure the middleware by creating a config
dictionary in your FastAPI application as follows:
config = {
'url': 'http://localhost:9200',
'user': 'elasticsearch_user',
'password': 'password',
'index': 'my_app_logs',
'environment': 'development',
'limit': True,
'debug': False
}
The debug
parameter prevents sending logs to Elasticsearch.
Integrate the middleware into your FastAPI application like this:
from fastapi import FastAPI
from fastapi_elasticsearch_middleware.elasticsearch_middleware import ElasticsearchLoggerMiddleware
app = FastAPI()
app.add_middleware(ElasticsearchLoggerMiddleware, config=config)
How It Works
The middleware captures each HTTP request, processes it, and sends log data to your Elasticsearch server based on the configured parameters. It includes detailed logs of request headers, body data, and response metrics.
How to Contribute
We welcome contributions from the community and are pleased to have you join us. Here are some guidelines that will help you get started.
Prerequisites
Before contributing, please ensure you have the following:
- A basic understanding of Python and FastAPI.
- A basic understanding of Middlewares.
Setting Up Your Development Environment
- Fork the Repository: Start by forking the repository to your GitHub account.
- Clone the Repository: Clone your fork to your local machine.
git clone https://github.com/GGontijo/fastapi-elasticsearch-middleware cd repository-name
- Install Dependencies: Install the required dependencies.
pip install -r requirements.txt
Making Changes
- Create a New Branch: Create a new branch for your feature or bug fix.
git checkout -b awesome-feature
- Make Your Changes: Implement your feature or fix a bug. Be sure to adhere to the coding standards and include comments where necessary.
Submitting a Pull Request
- Commit Your Changes: Once your tests pass, commit your changes.
git commit -m 'Add some feature'
- Push to GitHub: Push your changes to your fork on GitHub.
git push origin awesome-feature
- Open a Pull Request: Go to the original repository and click the Compare & pull request button. Then submit your pull request with a clear title and description.
Code Review
Once your pull request is opened, it will be reviewed by the maintainers. Some changes may be requested. Please be patient and responsive. Once the pull request has been approved, it will be merged into the master branch.
Thank you for contributing!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fastapi_elasticsearch_middleware-1.1.3.tar.gz
.
File metadata
- Download URL: fastapi_elasticsearch_middleware-1.1.3.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0c5d1e9421abb08811d8bcc4692db087f81a20876fd6d3166c628c7de5f0f70 |
|
MD5 | d51d89f1f8e228d1b9c38130c8c57542 |
|
BLAKE2b-256 | 0fb1e6c14bbd823c321c4adb8afe9a5b458271b9ddacf7df8e5411e8d4b4d220 |
File details
Details for the file fastapi_elasticsearch_middleware-1.1.3-py3-none-any.whl
.
File metadata
- Download URL: fastapi_elasticsearch_middleware-1.1.3-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c00447781cdec8dab2d59a826b34b07325ecbde1e661c8fe4b9e599a648b31d8 |
|
MD5 | 9170c86c80e4b1a473779a17d8f101a1 |
|
BLAKE2b-256 | ca3da5944f1a92187e54b211e0cd7f0a8bcbfd6e66b3a387f9aae9c4cbab27f7 |