Skip to content

Logging Contract ​

All KIW apps ship their stdout to the same daily OpenSearch index (tenant-kdkp-kiw-logs-*). Fluent Bit parses each JSON line into log_json.*, and OpenSearch fixes a field's type the first time it sees it in each daily index. If two apps write the same field name with different types (a number in one, a string in another), the index gets a mapping conflict: Discover fails and queries on that field break for every app.

This contract defines the fields every service writes, and their types. Our shared libraries implement it, so an app that uses them is compliant without extra work:

Third-party apps (Open WebUI, Firecrawl, Docling, vLLM) are not bound by it; the index template absorbs their fields.

Rules ​

  1. One JSON object per line on stdout. No log files, no multi-line output, no colored console output in deployed environments.
  2. Reserved fields have exactly the type listed below, in every app.
  3. Custom fields are flat scalars (string, number, boolean) with one type per field name across all apps. Do not log nested objects or arrays; flatten them (status_code, not response: {status: ...}) or serialize them to a JSON string under a <key>_json name (options_json), never under the name another app uses for an object: OpenSearch rejects the whole line when a field's type differs from the index mapping. As a safety net, dcc_backend_common.logger does this automatically in production: a nested value under key is written as a JSON string to key_json and key is dropped; other objects become str() under their own key, and NaN/Infinity floats become strings.
  4. Never reuse a reserved field name for something else (e.g. error as an object, level as a number, time as epoch millis).
  5. No secrets, prompts, document contents or personal data in any field. Log ids, sizes and counts instead.

Reserved Fields ​

FieldTypeRequiredContent
timestampstringyesISO-8601 in UTC, e.g. 2026-11-20T08:15:30.123Z
levelstringyesOne of debug, info, warning, error, critical (lowercase)
messagestringyes*Human-readable text
eventstringnoClosed vocabulary for dashboards and monitors, see Events
appstringyesStable service name. New services use the repo name (text-mate-frontend); existing backend values (textmate, transcribo, AnonyMate, ...) stay so dashboards keep working
loggerstringyesLogger name (Python module, or ssr / api in Nuxt)
request_idstringwhen availableUUID from the X-Request-ID header
errorstringon errorsShort error text (str(exc), err.message)
error_typestringon errorsException class name, e.g. TimeoutError
exceptionstringon errorsFull traceback / stack as one string
methodstringHTTP logsHTTP method
pathstringHTTP logsRoute template in FastAPI (/items/{item_id}, <unmatched> for 404s); in Nuxt the request path without query string
status_codeintegerHTTP logsHTTP status
duration_snumberHTTP logsDuration in seconds

* A line carries message, event, or both.

If a value under status_code or duration_s cannot be converted losslessly to the listed type (e.g. "OK", NaN), dcc_backend_common.logger moves it to status_code_raw / duration_s_raw as a string so the reserved field keeps its type. It coerces the other reserved fields to strings, and turns an exception passed as error=exc into error (str(exc)) plus error_type.

module, func_name and lineno (Python) are allowed extras with the obvious types.

Level names ​

Use exactly the five names above. Libraries with other names map onto them:

SourceMaps to
pino trace / debugdebug
pino warnwarning
pino fatalcritical

Events ​

event is a closed vocabulary: dashboards and alerting monitors term-match and aggregate on it, which only works while it stays a small, fixed set. Free text goes into message.

EventEmitted by
request_finished / request_failedlogging middleware
app_eventusage logger (log_event)
llm_callusage logger
health check failed / health check recoveredhealth probe router

Apps extend it with init_logger(extra_event_types={...}). In Nuxt, event is set explicitly in the log object and must follow the same rule.

Correlation ​

  • Backends bind request_id from X-Request-ID via the logging middleware.
  • Frontends forward X-Request-ID on every backend call, so one user action can be followed across frontend and backend in OpenSearch.
  • Forward the header when calling downstream services.

Configuration per environment ​

VariableApp typeValue in k8s
IS_PRODPythontrue (JSON output; required, init_logger fails without it)
LOG_LEVELPythondebug on test, info on uat / prod
NODE_ENVNuxtproduction (JSON output; set by the production image)
NUXT_PUBLIC_LOGGER_APPNuxtService name for the app field (required), e.g. text-mate-frontend
NUXT_PUBLIC_LOGGER_LOGLEVELNuxtdebug on test, info or warn on uat / prod

Run Python services with plain uvicorn ... --no-access-log, not fastapi run (its Rich handlers bypass the JSON pipeline).

Example ​

json
{"timestamp":"2026-11-20T08:15:30.123Z","level":"error","app":"text-mate-backend","logger":"text_mate.services.check","request_id":"550e8400-e29b-41d4-a716-446655440000","message":"Language check failed","error":"Connection refused","error_type":"ConnectError","exception":"Traceback (most recent call last): ..."}

Querying ​

In OpenSearch Dashboards (Discover or Dev Tools), filter on log_json.app and log_json.level:

log_json.app:"text-mate-backend" and log_json.level:(error or critical)

Developed with ❤️ by the DCC. Documentation released under the MIT License.