mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-06 09:13:19 +03:00
[PR #760] [MERGED] feat: Support OTel and JSON for logs (via log/slog) #629
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/pocket-id/pocket-id/pull/760
Author: @ItalyPaleAle
Created: 7/20/2025
Status: ✅ Merged
Merged: 7/27/2025
Merged by: @kmendell
Base:
main← Head:log-slog-1📝 Commits (10+)
775a60eInitial work on OTel support for logs with slog2fb9f42Converted Gin to slog3488a5fExample of contextual logsb8fe400Contextual logs when sending emailsa692ee3Merge branch 'main' of https://github.com/pocket-id/pocket-id into log-slog-1d27eeabSome more logs updated5e394c5Merge branch 'main' into log-slog-1ef7e9fbMerge branch 'main' into log-slog-1fb5f0d4Merge branch 'main' into log-slog-1d91bfd0Merge branch 'main' into log-slog-1📊 Changes
20 files changed (+432 additions, -204 deletions)
View changed files
📝
Dockerfile(+2 -2)📝
backend/go.mod(+11 -7)📝
backend/go.sum(+18 -10)📝
backend/internal/bootstrap/application_images_bootstrap.go(+7 -5)📝
backend/internal/bootstrap/bootstrap.go(+10 -6)📝
backend/internal/bootstrap/db_bootstrap.go(+22 -20)➕
backend/internal/bootstrap/observability_boostrap.go(+210 -0)➖
backend/internal/bootstrap/otel_boostrap.go(+0 -107)📝
backend/internal/bootstrap/router_bootstrap.go(+23 -17)📝
backend/internal/bootstrap/services_bootstrap.go(+5 -1)📝
backend/internal/common/env_config.go(+1 -0)📝
backend/internal/common/version.go(+3 -0)📝
backend/internal/controller/oidc_controller.go(+2 -2)📝
backend/internal/service/app_config_service.go(+0 -1)📝
backend/internal/service/audit_log_service.go(+8 -5)📝
backend/internal/service/geolite_service.go(+7 -7)📝
backend/internal/service/jwt_service.go(+3 -4)📝
backend/internal/service/ldap_service.go(+9 -8)📝
backend/internal/service/user_service.go(+6 -2)➕
backend/internal/utils/slogfanout.go(+85 -0)📄 Description
This PR adds support for sending logs to a collector using OpenTelemetry (OTel). Additionally, it allows printing log lines as JSON.
OTel for logs
We added support for OTel for traces and metrics with #495. The missing piece for observability was logs, which did not support OTel yet.
OTEL_LOGS_EXPORTER=otlpandOTEL_EXPORTER_OTLP_ENDPOINT).log/slogpackage, and configures slog as the default logger.log. Printfunctions are automatically converted to slog calls (and sent to an OTel collector, if configured)Log as JSON
This was an easy add since we were implementing slog support.
You can now set
LOG_JSON=trueand logs are printed out as JSON! JSON-formatted logs are often preferred when logs are sent to tools that parse them.JSON logging is disabled by default.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.