-
Notifications
You must be signed in to change notification settings - Fork 314
Adjust logger to display structured JSON in its output #1264
Description
We want to use structured logging so that k8s cloud services can interpret traces correctly
This is an example PR shamelessly stolen from the Timesketch project: https://github.com/google/timesketch/pull/3701/changes#diff-5a25e1fd90149256566394d20e2e0f63896c97c93f3fa5f3dc2a572784824e8fR245
We need to adjust /home/tomchop/yeti-docker/dev/yeti/core/logger.py to be compatible with this. (maybe it's just a log_format matter)
Currently, this INFO log gets posted to Google Cloud logs as an ERROR:
{
"textPayload": "2026-02-11 18:51:51,245 - yeti.audit.log - INFO - Authorized request - user@domain.com - /api/v2/dfiq/search - POST - {"query": {"name": ""}, "count": 100, "page": 0, "filter_aliases": [["dfiq_tags", "list"], ["dfiq_id", "text"]], "type": "scenario"} - 10.100.12.73 - 200",
"insertId": "2c8xl9jqdzte2v5e",
"resource": {
"type": "k8s_container",
"labels": {
"project_id": "my-gcp-project",
"location": "us-central1",
"pod_name": "yeti-pod",
"cluster_name": "my-gcp-project-prod",
"container_name": "api",
"namespace_name": "yeti"
}
},
"timestamp": "2026-02-11T18:51:51.246713161Z",
"severity": "ERROR",
"labels": {
"compute.googleapis.com/resource_name": "gk3-my-gcp-project-prod-pool-2-4adf5e01-6okd",
"k8s-pod/app_kubernetes_io/managed-by": "google-cloud-deploy",
"k8s-pod/pod-template-hash": "7df475df74",
"k8s-pod/skaffold_dev/run-id": "39334c7123834184a8e36d75ad87ccd0",
"logging.gke.io/top_level_controller_name": "prod-yeti-api",
"logging.gke.io/top_level_controller_type": "Deployment",
"k8s-pod/app_kubernetes_io/instance": "prod",
"k8s-pod/app_kubernetes_io/name": "yeti",
"k8s-pod/app_kubernetes_io/component": "api"
},
"logName": "projects/my-gcp-project/logs/stderr",
"receiveTimestamp": "2026-02-11T18:51:55.933154967Z"
}