Fastapi-gae-logging

Latest version: v0.0.9

Safety actively analyzes 707435 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 2

0.0.9

**Breaking changes**
- Request payload is now logged under a new nested field `request_payload` in the `jsonPayload` field of each request lifecycle parent request. Check screenshot in readme to locate the new structure in parent log when looking into Google Cloud Logging Explorer.

**New features**
- Added optional logging of request headers into the parent log. This is optional but defaults to true. The headers are placed into `request_headers` nested field in the `jsonPayload` field of parent log.
- Request payload is parsed automatically before logged in `request_payload` nested field. Parsing happens based on content type of incoming request and currently there are 3 types supported:
- `application/json`
- `application/x-www-form-urlencoded`
- `text/plain`
- User can add more parsers or override existing ones by passing extra parsers as a dict during logging initialization. Example:



from fastapi import FastAPI
from fastapi.responses import JSONResponse
from fastapi.exceptions import HTTPException
import logging
import os

app = FastAPI()

async def custom_payload_parser_plain_text(request: Request):
try:
body_bytes = await request.body()
incoming_payload = body_bytes.decode('utf-8')
return f"This was the original request payload: {incoming_payload}"
except Exception as e:
return f"Failed to read request payload as plain text: {e} | {traceback.format_exc()}"



if os.getenv('GAE_ENV', '').startswith('standard'):
import google.cloud.logging
from google.cloud.logging_v2.handlers import setup_logging
from fastapi_gae_logging import FastAPIGAELoggingHandler

client = google.cloud.logging.Client()
overriding default parsing for payload when content type is 'text/plain'
gae_log_handler = FastAPIGAELoggingHandler(
app=app,
client=client,
custom_payload_parsers={
"text/plain": custom_payload_parser_plain_text
}
)
use the log_payload parameter if you want to opt-out from payload logging
gae_log_handler = FastAPIGAELoggingHandler(app=app, client=client, log_payload=False)
setup_logging(handler=gae_log_handler)

0.0.8

Dropped usage and dependency directly on FastAPI and replaced with Starlette instead. This way this package can be used with pure Starlette applications as well and even maybe with any other ASGI Starlette based frameworks that implement or inherit Starlette's `add_middleware` method for attaching pure ASGI middlewares.

Kudos to iffius for pointing that out!

0.0.7

- Polished some docstrings
- Loosened up dependencies on fastapi and google-cloud-logging

0.0.6

Dummy release to sync repo state with PyPi package state

0.0.5

- Added new parameter for opting-out payload logging in docstring
- Updated Readme to include definitions of API

0.0.4

- Added option to opt out for logging payload
- Updated readme with absolute image addresses to fix render in PyPi

Page 1 of 2

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.