Skip to content

Implement Cloud Logging with setup_logging() #236

@aaronjae22

Description

@aaronjae22

While I was working on implementing our CloudRunTraceFilter on Trust Registry and after doing a vast research about google.cloud.logging I found something that could be useful and if it works could be implemented instead of our own middleware.

I know that we agree on not adding Cloud Logging to our ActivityPub-Testbed project but since this is a minimal implementation we could make a good use of it. And since schemaindex is already working as expected, trust registry has its own implementation, I thought I could add it over here and see how it behaves.

Now when we call client.setup_logging() from the google-cloud-logging library, it will set up a complete logging pipeline that automatically handles trace correlation without any custom middleware or filters.

setup_logging() detects the Django framework and enables automatic trace extraction, extracts X-Cloud-Trace-Context headers from requests, then creates a CloudLoggingHandler and attaches it to Python's root logger (all loggers like Django, testbed, gunicorn inherit from root and automatically use this handler).

It's frustrating that we couldn't find this earlier. Google official docs does not provide a very organized way of analyzing their own libraries. They are scatter all around.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions