-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify the internal definition of processors (#36)
This removes the weird "extend(class().setup())" pattern in favor of a more straightforward approach: * Some processors are simply functions: let's define them as such * Some processors need other processors to run in the big picture: they are connected by specific "setup" functions
- Loading branch information
Showing
5 changed files
with
118 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
import structlog.processors | ||
from structlog.typing import Processor | ||
|
||
from . import errors, processors | ||
from . import error_reporting, processors | ||
|
||
|
||
def build_processors( | ||
service: str | None = None, | ||
version: str | None = None, | ||
) -> list[Processor]: | ||
procs = [] | ||
|
||
procs.extend(processors.CoreCloudLogging().setup()) | ||
procs.extend(processors.LogSeverity().setup()) | ||
procs.extend(processors.CodeLocation().setup()) | ||
procs.extend(errors.ReportException().setup()) | ||
procs.extend(errors.ReportError(["CRITICAL"]).setup()) | ||
procs.extend(errors.ServiceContext(service, version).setup()) | ||
procs.extend(processors.FormatAsCloudLogging().setup()) | ||
procs: list[Processor] = [] | ||
|
||
# Add a timestamp in ISO 8601 format. | ||
procs.append(structlog.processors.TimeStamper(fmt="iso")) | ||
procs.append(processors.init_cloud_logging) | ||
|
||
procs.extend(processors.setup_log_severity()) | ||
procs.extend(processors.setup_code_location()) | ||
|
||
# Errors: log exceptions | ||
procs.extend(error_reporting.setup_exceptions()) | ||
|
||
# Errors: formatter for Error Reporting | ||
procs.append(error_reporting.ReportError(["CRITICAL"])) | ||
|
||
# Errors: add service context | ||
procs.append(error_reporting.ServiceContext(service, version)) | ||
|
||
# Finally: Cloud Logging formatter | ||
procs.append(processors.finalize_cloud_logging) | ||
|
||
# Format as JSON | ||
procs.append(structlog.processors.JSONRenderer()) | ||
|
||
return procs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters