Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP request processor #46

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

HTTP request processor #46

wants to merge 2 commits into from

Conversation

multani
Copy link
Owner

@multani multani commented Sep 21, 2024

This adds a new HTTP-specific processor that formats logs according to the HttpRequest Google Cloud Logging log format.

See: https://cloud.google.com/logging/docs/structured-logging#structured_logging_special_fields
See: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#httprequest

Fix: #32


This introduces:

  • A new class to represent the current HTTP Request. It maps to what GCP supports, but with specific attributes which are a bit more agnostic (size is a number, not a string, for instance.)
  • A new processor that "knows" how to convert the previous HTTP request object for logging

This can be used in different ways:

Either the user creates the HTTPRequest object itself and logs it directly:

def handler(request):
    r = HTTPRequest(method=request.method, ...)
    logger.info("new request coming", http_request=r)

Or this is implemented as part of a framework (inside WSGI or ASGI or framework-specific middleware for instance), in which case we can offer a dedicated adapter from the framework objects to the HTTPRequest format.

For this case, the pull request offers an adapter from Starlette request/response + a test with a basic Starlette middleware.

@multani
Copy link
Owner Author

multani commented Sep 21, 2024

@petemounce you may be interested by this: this implements something similar to what we discussed in #32

  • I reused part of the code you show me in httpRequest processor #32 to write the Starlette middleware (I assume this is what you actually had in httpRequest processor #32?)
  • This shows how the adapter from Starlette could be used. The plan would be to not ship the middleware itself, but proposed a simpler adapter that could be reused inside your own middleware.

@multani multani mentioned this pull request Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

httpRequest processor
1 participant