Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(logging): add a logging middleware to log all api requests #3437

Merged
merged 5 commits into from
Jan 25, 2024

Conversation

lsampras
Copy link
Member

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

  • Create a request middleware to create a top level span consisting of all the metadata fields
  • Update the subscriber layer to propogate the metadata fields to the top layer

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

  • Currently we don't have guaranteed keys/metadata present at the top level
  • finding the relavant info (payment_id/connector etc) requires context about the lower level functions where this info is extracted
  • instead this change provides a single log line that is guaranteed to be present for all API calls
  • And this log line would have all the relevant fields needed for analysis/debugging

How did you test it?

run the application locally
all api requests should have the following log line at the end of request

  • the fields should be populated when available
  • These log line will be generated even for health & non-existent paths (e.g / or /favicon.ico)
{
    "message": "[GOLDEN_LOG_LINE - EVENT] REQUEST MIDDLEWARE END",
    "hostname": "<MY_MACHINE>.local",
    "pid": 62901,
    "env": "development",
    "level": "INFO",
    "target": "router::middleware",
    "service": "router",
    "line": 61,
    "file": "crates/router/src/middleware.rs",
    "fn": "golden_log_line",
    "full_name": "router::middleware::golden_log_line",
    "time": "2024-01-24T06:35:06.771569000Z",
    "merchant_id": "merchant_1706060159",
    "request_id": "018d3a2d-e583-7581-8992-8596b3052995",
    "extra": {
        "trace_id": "00000000000000000000000000000000",
        "http.method": "POST",
        "http.route": "/payments",
        "http.flavor": "1.1",
        "http.user_agent": "PostmanRuntime/7.33.0",
        "payment_id": "payment_intent_id = \"pay_y8XHx5whOaWTdoGrgAAf\"",
        "otel.name": "HTTP POST /payments",
        "http.client_ip": "::1",
        "http.host": "localhost:8080",
        "http.target": "/payments",
        "http.scheme": "http",
        "otel.kind": "server"
    }
}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible
  • I added a CHANGELOG entry if applicable

@lsampras lsampras added A-framework Area: Framework A-core Area: Core flows C-feature Category: Feature request or enhancement labels Jan 24, 2024
@lsampras lsampras self-assigned this Jan 24, 2024
@lsampras lsampras requested review from a team as code owners January 24, 2024 06:55
@lsampras lsampras requested a review from a team as a code owner January 24, 2024 07:27
@likhinbopanna likhinbopanna added this pull request to the merge queue Jan 25, 2024
Merged via the queue into main with commit c2946cf Jan 25, 2024
10 checks passed
@likhinbopanna likhinbopanna deleted the add_final_log_line branch January 25, 2024 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows A-framework Area: Framework C-feature Category: Feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logging framework - Add a endrequest log line which should be a common line for accumulating all parameters
4 participants