Skip to content

Comments

Add structured logging and OpenMetrics endpoint#39

Merged
yulmwu merged 4 commits intomainfrom
feat/advanced-logging
Feb 20, 2026
Merged

Add structured logging and OpenMetrics endpoint#39
yulmwu merged 4 commits intomainfrom
feat/advanced-logging

Conversation

@yulmwu
Copy link
Member

@yulmwu yulmwu commented Feb 20, 2026

  • Add structured logging
  • Removed Discord/Slack webhook sender
  • (WIP) Add OpenMetrics endpoint

Refs: #9

@yulmwu yulmwu self-assigned this Feb 20, 2026
@yulmwu yulmwu added enhancement New feature or request feature labels Feb 20, 2026
@yulmwu yulmwu requested a review from Copilot February 20, 2026 05:48
@codecov
Copy link

codecov bot commented Feb 20, 2026

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/slog structured 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.

@yulmwu
Copy link
Member Author

yulmwu commented Feb 20, 2026

We will now apply the same changes to the container-provisioner as well.

@yulmwu
Copy link
Member Author

yulmwu commented Feb 20, 2026

A critical issue where most 5xx errors were not being logged has been fixed. This issue does not affect the container-provisioner.

@yulmwu yulmwu marked this pull request as ready for review February 20, 2026 09:02
@yulmwu
Copy link
Member Author

yulmwu commented Feb 20, 2026

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" }
            }
        }
    }
}

@yulmwu yulmwu merged commit 702d206 into main Feb 20, 2026
2 checks passed
@yulmwu yulmwu deleted the feat/advanced-logging branch February 20, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant