Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

feat(helm): let a deployment configure logging

Petr Bauch29b424135162
diff --git a/deploy/remote/helm/switch/templates/_helpers.tpl b/deploy/remote/helm/switch/templates/_helpers.tpl
index 3baa3d9ab..bdbef56fc 100644
--- a/deploy/remote/helm/switch/templates/_helpers.tpl
+++ b/deploy/remote/helm/switch/templates/_helpers.tpl
@@ -257,6 +257,16 @@ the first connection of a rolled-out pod.
{{- end -}}
{{- end }}
+{{/*
+Reject a log format switch-core would refuse at startup, so a typo is a render
+error rather than a crash loop.
+*/}}
+{{- define "switch.validateLogging" -}}
+{{- if not (has .Values.switchCore.logging.format (list "text" "json")) -}}
+{{- fail (printf "switchCore.logging.format must be text or json, not %q." .Values.switchCore.logging.format) -}}
+{{- end -}}
+{{- end }}
+
{{/*
switch-core container env. Shared by the switch-core Deployment and the
pre-upgrade migration Job so they always run against the same configuration
@@ -348,6 +358,18 @@ Include with `nindent 12`.
value: {{ .Values.switchCore.cookieSecure | quote }}
- name: SWITCH_LOG_LEVEL
value: {{ .Values.switchCore.logLevel | default "INFO" | quote }}
+- name: LOG_FORMAT
+ value: {{ .Values.switchCore.logging.format | quote }}
+- name: LOG_LEVEL
+ value: {{ .Values.switchCore.logging.rootLevel | quote }}
+- name: TENANT_ID
+ value: {{ .Values.switchCore.logging.tenantId | quote }}
+- name: SERVICE_NAME
+ value: {{ .Values.switchCore.logging.serviceName | quote }}
+{{- with .Values.switchCore.logging.environment }}
+- name: ENVIRONMENT
+ value: {{ . | quote }}
+{{- end }}
# switch-core sits behind the cluster/ALB and enforces its own
# BearerAuthMiddleware, so fastmcp's browser-oriented DNS-rebinding
# Host/Origin guard (default-on since mcp 1.28) only rejects the
diff --git a/deploy/remote/helm/switch/templates/switch-core/deployment.yaml b/deploy/remote/helm/switch/templates/switch-core/deployment.yaml
index 42cb0a4ae..95873ebaf 100644
--- a/deploy/remote/helm/switch/templates/switch-core/deployment.yaml
+++ b/deploy/remote/helm/switch/templates/switch-core/deployment.yaml
@@ -2,6 +2,7 @@
{{- fail "switchCore.replicaCount must be 1: switch-core keeps live Matrix sync sessions in memory and cannot be horizontally scaled (a second replica would duplicate every client and split session state)." }}
{{- end }}
{{- include "switch.validateDbTls" . }}
+{{- include "switch.validateLogging" . }}
apiVersion: apps/v1
kind: Deployment
metadata:
diff --git a/deploy/remote/helm/switch/values.yaml b/deploy/remote/helm/switch/values.yaml
index 4ad6a6650..6bde69d9d 100644
--- a/deploy/remote/helm/switch/values.yaml
+++ b/deploy/remote/helm/switch/values.yaml
@@ -90,6 +90,28 @@ switchCore:
image: switch-core:latest
imagePullPolicy: Always
logLevel: INFO
+
+ # Logging. "text" is for reading in a terminal; "json" is what a log pipeline
+ # wants, and the only format that carries the context fields as fields — the
+ # tenant, and the request, agent and user a line belongs to — rather than
+ # inside the message. Set format: json anywhere the logs are collected.
+ #
+ # tenantId is a deployment-wide constant while Switch serves one organisation
+ # per deployment. Setting it per deployment is what lets one pipeline hold
+ # several and still tell them apart, so name the customer or the environment
+ # rather than leaving it at "default".
+ #
+ # environment and serviceName are emitted as `env` and `service`, the names
+ # a collector expects to group and filter on.
+ # rootLevel governs everything, libraries included; logLevel above is
+ # switch-core's own and is usually the one to change.
+ logging:
+ format: text
+ rootLevel: INFO
+ tenantId: default
+ environment: ""
+ serviceName: switch-core
+
# Public base URL the gateway is served on (used for links / OIDC redirects).
frontendBaseUrl: ""
# Public origin (scheme + host, no path) of the gateway HTTP API itself, used