Skip to content

Feat/gcp json formatter#19775

Open
shcherbak wants to merge 6 commits into
element-hq:developfrom
shcherbak:feat/GcpJsonFormatter
Open

Feat/gcp json formatter#19775
shcherbak wants to merge 6 commits into
element-hq:developfrom
shcherbak:feat/GcpJsonFormatter

Conversation

@shcherbak
Copy link
Copy Markdown

Problem

When Synapse runs on GKE, all log entries appear in Google Cloud Logging with severity: ERROR, regardless of the actual Python log level. This happens because GKE's logging agent automatically
assigns ERROR to anything written to stderr.

Switching to stdout alone is not sufficient: GCL and the underlying fluentbit/fluentd agents recognise the severity JSON field specifically. The existing JsonFormatter and TerseJsonFormatter
both emit "level", which is not mapped automatically.

Fix

Add GcpJsonFormatter to synapse.logging. It outputs one JSON line per record with the four fields GCL expects:

  • severity - Python levelname verbatim (DEBUG, INFO, WARNING, ERROR, CRITICAL), which GCL maps directly to the correct entry severity
  • message - formatted log message, with exception traceback appended if present
  • logger - logger name (synapse.access.http.8008, etc.)
  • time - UTC timestamp in RFC 3339 with millisecond precision

Usage in log_config.yaml:

  formatters:
    gcp_json:
      class: synapse.logging.GcpJsonFormatter
  handlers:
    console:
      class: logging.StreamHandler
      formatter: gcp_json
      stream: ext://sys.stdout

@shcherbak shcherbak requested a review from a team as a code owner May 12, 2026 20:28
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.

1 participant