feat: added logging and otel - #232
Conversation
|
@wim07101993 must be a member of the zitadel team on Vercel to deploy. Learn more about collaboration on Vercel and other options here. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR modernizes the server’s observability and lifecycle wiring by introducing structured logging (slog) and OpenTelemetry-based logging export, adding request/operation identification middleware, and refactoring startup/shutdown into more modular components.
Changes:
- Added new instrumentation configuration and logging/OTEL initialization during server startup.
- Refactored startup/shutdown flow (including a shutdown helper) and migrated various
log.*calls toslog. - Introduced HTTP middleware for request IDs, operation IDs, and request logging.
Reviewed changes
Copilot reviewed 29 out of 33 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/server/config.go | Extends server config to include instrumentation configuration. |
| cmd/server/server.go | Refactors server startup/shutdown flow; adds instrumentation setup; adds HTTP middleware wiring. |
| cmd/server/shutdown.go | Introduces shutdown hook aggregation/execution helper. |
| go.mod | Adds dependencies for slog fanout and OpenTelemetry logging/export. |
| go.sum | Updates checksums for new/updated dependencies. |
| internal/api/middleware/logging.go | Adds request logging middleware and response-writer wrapper for status tracking. |
| internal/api/middleware/operation_id.go | Adds ogen middleware to inject operation IDs into context. |
| internal/api/middleware/request_id.go | Adds request ID generation and context storage middleware. |
| internal/api/integration_test/setup_pg_test.go | Migrates integration test logging to slog. |
| internal/api/integration_test/setup_spanner_test.go | Migrates integration test logging to slog. |
| internal/bootstrap/users/import.go | Migrates bootstrap logging to slog. |
| internal/build/info.go | Adds build metadata helpers (version/commit/date) for logging/resource attributes. |
| internal/domain/auth_check.go | Adds go:generate enumer directive for AuthCheckType. |
| internal/instrumentation/config.go | Introduces instrumentation config types (log format, masking, exporter wiring). |
| internal/instrumentation/logformat_enumer.go | Generated enum helpers for log format configuration. |
| internal/instrumentation/otel/exporter_config.go | Adds OTEL exporter config and exporter type enum. |
| internal/instrumentation/otel/exportertype_enumer.go | Generated enum helpers for OTEL exporter types. |
| internal/instrumentation/otel/logging.go | Implements OTEL log exporter/provider construction. |
| internal/instrumentation/zlog/context.go | Adds context-based logging helpers built on slog-context. |
| internal/instrumentation/zlog/error_context_logger.go | Adds an error-context logger wrapper with Panic/Fatal helpers. |
| internal/instrumentation/zlog/extractors/err_cause.go | Adds extractor for context cancellation/error “cause”. |
| internal/instrumentation/zlog/extractors/request_details.go | Adds placeholder extractor for request details. |
| internal/instrumentation/zlog/level.go | Defines logging levels (including sloggcp-specific levels). |
| internal/instrumentation/zlog/logger.go | Adds helper to enrich loggers with stream/version attributes. |
| internal/instrumentation/zlog/replacers/err_replacer.go | Adds replacer for error key mapping (GCP error reporting). |
| internal/instrumentation/zlog/source.go | Adds global toggle state for “add source” behavior. |
| internal/instrumentation/zlog/stream.go | Adds stream enum and enablement map for log stream filtering. |
| internal/instrumentation/zlog/stream_enumer.go | Generated enum helpers for log streams. |
| internal/service/postgres_testmain_test.go | Migrates test setup logging to slog. |
| internal/storage/database/config.go | Migrates fallback DB dialect logging to slog. |
| internal/storage/database/dialect/postgres/embedded/start.go | Migrates embedded Postgres shutdown logging to slog. |
| internal/storage/database/repository/auth_attempt.go | Migrates unsupported auth-check logging to slog. |
| internal/storage/database/repository/repository_test.go | Migrates repository integration test setup logging to slog. |
Files not reviewed (3)
- internal/instrumentation/logformat_enumer.go: Language not supported
- internal/instrumentation/otel/exportertype_enumer.go: Language not supported
- internal/instrumentation/zlog/stream_enumer.go: Language not supported
|
@mridang tracing and other metrics are currently not implemented indeed. I thought to first fix logging, than move on to the other metrics. |
|
@mridang must be a member of the zitadel team on Vercel to deploy. Learn more about collaboration on Vercel and other options here. |
This pull request adds structured logging and OpenTelemetry-based instrumentation. The configuration system is extended to support detailed instrumentation settings, and several new dependencies are added to support these features.
Parts of this have been taken from the current otel implementation in zitadel.