Add structured logging and OpenMetrics endpoint#39
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR modernizes the logging infrastructure by migrating from a custom file-based logging system with webhook support to Go's standard log/slog package for structured JSON logging. The webhook functionality for Discord and Slack has been removed as indicated in the related issue #9.
Changes:
- Replaced custom logging implementation with Go's
log/slogstructured logging library - Removed Discord/Slack webhook integration and all related configuration
- Updated all logging call sites to use structured logging with JSON output and proper attribute typing
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/logging/logging.go | Complete rewrite to use slog with custom handlers for level-based routing (stdout/stderr/file), removed webhook sender implementation |
| internal/logging/logging_test.go | Removed webhook-related tests, updated test logger initialization to include Options parameter |
| internal/http/middleware/request_logger.go | Converted from string-formatted logs to structured logging with slog.Group for HTTP attributes |
| internal/http/middleware/recovery_logger.go | New middleware for panic recovery using structured logging (replaces gin.Recovery) |
| internal/http/middleware/request_logger_test.go | Updated tests to parse JSON logs and extract structured fields instead of string matching |
| internal/http/router.go | Updated middleware setup to use new RecoveryLogger and removed gin default writers |
| internal/config/config.go | Removed webhook-related configuration fields (DiscordWebhookURL, SlackWebhookURL, etc.) and updated FormatForLog to return structured map instead of string |
| internal/config/config_test.go | Updated tests to remove webhook configuration validation and adapt to new FormatForLog signature |
| cmd/server/main.go | Converted all log statements to structured logging with slog, added Options parameter to logger initialization |
| internal/http/integration/testenv_test.go | Updated logger initialization with Options parameter |
| README.md | Added JSON schema documentation for log format, removed webhook-related environment variables |
| .env.example | Removed webhook-related environment variable examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
We will now apply the same changes to the container-provisioner as well. |
|
A critical issue where most 5xx errors were not being logged has been fixed. This issue does not affect the container-provisioner. |
|
The JSON schema for structured logging is as follows. It may differ slightly from the actual implementation; please use analysis tools such as Ajv or AWS Glue Crawler if necessary. {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "SMCTF Log Event",
"type": "object",
"additionalProperties": true,
"required": ["ts", "level", "msg", "app"],
"properties": {
"ts": {
"type": "string",
"format": "date-time",
"description": "RFC3339 timestamp with timezone"
},
"level": {
"type": "string",
"enum": ["debug", "info", "warn", "error"]
},
"msg": { "type": "string" },
"app": { "type": "string" },
"legacy": { "type": "boolean" },
"error": {},
"stack": { "type": "string" },
"http": {
"type": "object",
"additionalProperties": true,
"properties": {
"method": { "type": "string" },
"path": { "type": "string" },
"status": { "type": "integer" },
"latency": { "type": "string" },
"ip": { "type": "string" },
"query": { "type": "string" },
"user_agent": { "type": "string" },
"content_type": { "type": "string" },
"content_length": { "type": "integer" },
"user_id": { "type": "integer" },
"body": { "type": "string" }
}
}
}
} |
Refs: #9