-
Notifications
You must be signed in to change notification settings - Fork 5
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
httpRequest processor #32
Comments
That would be a great addition to add, yes! The canonical documentation for this would be:
I wouldn't be surprised that if the I'm totally in to add support for this. My only concern is that GCP specifies very specific fields to be logged, and as you discovered, they need to have the right types. Maybe we could do it in 2 steps: First, we add a processor like the Then, we can check how we could provide a better "user experience" to log this field correctly. I would need to think a bit more about it, but I would probably see a dedicated dataclass
For instance: @dataclass
class HTTPRequest:
method: str | None
url: str | None
size: int | None
def format(self):
"""Format as https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#httprequest"""
# TODO: filter out all None values
return {
"requestMethod": self.method,
"requestUrl": self.url,
"requestSize": str(self.size),
} In your middleware, you would do something like: self.logger.info(
f"""{client_host}:{client_port} - "{http_method} {url} HTTP/{http_version}" {status_code}""",
httpRequest=HTTPRequest(method=http_method, url=url)) This way:
What do you think? |
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
I've started to draft a solution in #46 |
We have a logging middleware that stamps each request with a canonical log-line. That attaches http request metadata as well as other things. That in turn causes GCP Logging to render those bits of metadata as lozenge-blobs in the UI, making them stand out a bit and also making the canonical log lines themselves stand out from the regular noise.
It was surprisingly fiddly to get this to work.
I'm not sure if you'd like to add some level of support? Here's something that resembles what I ended up doing:
... and then we have a structlog processor:
This was some time ago, and I don't remember the specifics but I do remember it being particularly papercutty. Perhaps if a field was not serialized how GCP expects (I vaguely recall things that are clearly numbers -- except status-code -- being necessary to pass as strings?) the whole thing didn't appear? Stuff like that.
The text was updated successfully, but these errors were encountered: