feat(logging): add streams (#11435)

# Which Problems Are Solved

Streams allow differentiating logs produced by different components of
Zitadel.

# How the Problems Are Solved

The `backend/v3/instrumentation/logging` package now exposes convenience
function for setting and getting a logger from the context. As well as
high-level functions to emit log records at various levels. When
constructing a new logger a "stream" needs to be specified:

- **runtime**: General runtime logs, such as startup and shutdown
messages. Default for logs that do not belong to the other categories.
- **request**: Logs for incoming API and HTTP requests.
- **event_handler**: Logs for event handling in projections.
- **queue**: Logs for the job queue processing.
- **event_pusher**: Logs for event pushing to the database. Disabled by
default, contains sensitive information.

Each line from the returned logger contains a `stream` field as well as
a `version` field with the current Zitadel version.

## Runtime config

Streams can be enabled by passing an array of stream names in the
runtime config. Because some log streams may contain sensitive data
(especially events), it is now also possible to mask values by their
key.

# Additional Changes

- Wrap `slogctx` in the `logging` package. (Except API error converter
packages, because of import cycle)
- Add some docs to `logging` package so other devs understand how to add
logging to Zitadel
- Add `logging.OnError` and `logging.WithError` helper functions with
`Panic()` and `Fatal()` methods, to preserve current calls in the `cmd`
packages.
- Add instance context extractor.
- Only output request details in the request info log. Request ID
remains propagated through context.
- Moved middleware functionality into protocol specific packages. 
- Removed setting of URI to context in metric middleware. There were ony
setters and no getters. (Unused value)
- Reuse a single statusWriter in the middleware package for middlewares
that need to know the response status.

# Additional Context

- Closes #11333
- Closes #11331 
- Partly #11330

---------

Co-authored-by: Silvan <[email protected]>
This commit is contained in:
Tim Möhlmann
2026-02-04 11:51:43 +01:00
committed by GitHub
co-authored by Silvan
parent b99271755b
commit 11dbb1b277
112 changed files with 2679 additions and 981 deletions
+30 -4
View File
@@ -46,14 +46,36 @@ Instrumentation:
Log:
# Log lines lower than this level are not emitted.
Level: "INFO" # ZITADEL_INSTRUMENTATION_LOG_LEVEL
# Streams enable logging for specific parts of the application.
Streams: # ZITADEL_INSTRUMENTATION_LOG_STREAMS (comma separated list)
- runtime # General runtime logs, such as startup and shutdown messages.
- request # Logs for incoming API and HTTP requests.
- event_handler # Logs for event handling in projections.
- queue # Logs for the job queue processing.
# - event_pusher # Logs for event pushing to the database. Warning: contains sensitive information.
# Mask replaces sensitive information with Value in logs matched by Key
Mask:
# Keys are the attribute keys to be masked in logs.
# Keys are unqualified attribute names and apply to all attributes with the specified name,
# regardless of their position in the attribute hierarchy.
# Eg. "some_key" matches "some_key" and "parent.some_key" etc.
# If the matched log attribute is a nested object or array,
# the entire structure is replaced with the specified Value.
Keys: # ZITADEL_INSTRUMENTATION_LOG_MASK_KEYS (comma separated list)
# - "first_name"
# - "last_name"
# Value is the string that replaces the original value of masked attributes.
Value: "****" # ZITADEL_INSTRUMENTATION_LOG_MASK_VALUE
# Enable printing structured logs to standard error in the specified format.
# When disabled, the legacy Log configuration is used.
# Important: when legacy Log is customized, please add a format and customize before upgrading to v5
# The following formats are supported:
# - "disabled": Disables logging
# - "disabled": Disables logging (or fallback to legacy Log config)
# - "text": Logs are printed on StdErr as human-readable text
# - "json": Logs are printed on StdErr as JSON objects
# - "gcp": JSON formatted logs compatible with Google Cloud Platform logging. Need to configure GoogleProjectID below!
# - "gcp_error_reporting": JSON formatted logs compatible with Google Cloud Platform Error Reporting. Need to configure GoogleProjectID below!
Format: "text" # ZITADEL_INSTRUMENTATION_LOG_STDERR
# - "gcp": JSON formatted logs compatible with Google Cloud Platform logging.
# - "gcp_error_reporting": JSON formatted logs compatible with Google Cloud Platform Error Reporting.
Format: "disabled" # ZITADEL_INSTRUMENTATION_LOG_STDERR
# Adds the source file and line number where the log line was emitted.
# Not to be confused with the source of an error.
AddSource: true # ZITADEL_INSTRUMENTATION_LOG_ADDSOURCE
@@ -63,6 +85,10 @@ Instrumentation:
ReportLocation: true # ZITADEL_INSTRUMENTATION_LOG_ERRORS_REPORTLOCATION
# Adds stack traces to logged errors.
StackTrace: false # ZITADEL_INSTRUMENTATION_LOG_ERRORS_STACKTRACE
# Exporter configures where the OTEL formatted logs are exported to.
# You typically want to disable this unless you have a OTEL collector setup.
# Enabling stdOut or stdErr here will result in duplicate logs (of different format)
# if there's also a Format set above.
Exporter:
# The following exporter types are supported:
# - "none": Disables OTEL log exporter