Skip to content

Releases: chrisK824/fastapi-gae-logging

v0.0.10

29 Mar 13:28
Compare
Choose a tag to compare
  • Memory leak issue fix, kudos to @pharmac1st for spotting it out and contributing :)

v0.0.9

01 Dec 15:39
Compare
Choose a tag to compare

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)

v0.0.8

15 Oct 17:09
Compare
Choose a tag to compare

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!

v0.0.7

03 Sep 07:03
Compare
Choose a tag to compare
  • Polished some docstrings
  • Loosened up dependencies on fastapi and google-cloud-logging

v0.0.6

30 Aug 09:33
Compare
Choose a tag to compare

Dummy release to sync repo state with PyPi package state

v0.0.5

30 Aug 09:27
Compare
Choose a tag to compare
  • Added new parameter for opting-out payload logging in docstring
  • Updated Readme to include definitions of API

v0.0.4

30 Aug 09:12
Compare
Choose a tag to compare
  • Added option to opt out for logging payload
  • Updated readme with absolute image addresses to fix render in PyPi

v0.0.3

29 Aug 14:52
Compare
Choose a tag to compare

Updated readme file to include screenshots with the effects of the module when viewing FastAPI app's logs in Google Cloud Log Explorer.

V0.0.2

27 Aug 15:15
Compare
Choose a tag to compare
  • Fixed bug where request body couldn't be logged after being used in logging middleware
  • Updated readme file to document current behaviour for request payload logging

Initial release

26 Aug 15:33
Compare
Choose a tag to compare
0.0.1

add first version