Skip to content

refactor: migrate to use build_info and log_utils crates for build information and logging framework#161

Merged
ShankarSinghC merged 7 commits intomainfrom
use-log-utils-and-build-info
Mar 24, 2026
Merged

refactor: migrate to use build_info and log_utils crates for build information and logging framework#161
ShankarSinghC merged 7 commits intomainfrom
use-log-utils-and-build-info

Conversation

@SanchithHegde
Copy link
Copy Markdown
Member

@SanchithHegde SanchithHegde commented Mar 23, 2026

Description

This PR migrates the code to use libraries from the https://github.com/juspay/framework-libs-rs repository, for obtaining the cargo workspace members and the logging framework.

This PR includes the following changes:

  • Removes the cargo_workspace module from the build script and uses the build_info crate instead.
  • Migrates the logging framework to use the log_utils crate.
  • Includes the build version information in logs using vergen crate (enabled via build_info crate).
  • Includes the version information in a response header for all responses
  • Generates a request ID if not provided in request headers, and also propagates the same to response headers.
  • Copies over the .gitignore file as .dockerignore, so that the git working directory is clean when building the Docker image (git status would not report working directory as dirty).

Testing

  1. Compared the logs (and fields) for a request on main branch and current branch, and noticed no differences in terms of keys included:

    Request: curl -i http://localhost:3001/

    Screenshot of diff

    (Tool used: https://semanticdiff.com/online-diff/json/)

  2. Ran using command cargo run --features vergen, and confirmed that the build_version field is present in logs:

    Screenshot of log with a build_version field

  3. Confirmed that the version is included in the response headers when run with the vergen feature enabled:

    $ curl -i http://localhost:3001/
    HTTP/1.1 404 Not Found
    x-version: v0.7.0-7-ge55438ce9a93-dirty
    content-length: 0
    date: Mon, 23 Mar 2026 10:25:20 GMT
  4. When no x-request-id header is provided, one is generated automatically and is available in response headers:

    $ curl -i http://localhost:3001/
    HTTP/1.1 404 Not Found
    x-request-id: 019d1c0f-3a9a-7ad3-adda-1f0ed29e15bd
    x-version: v0.7.0-8-gf5c1cbd7738c-dirty
    content-length: 0
    date: Mon, 23 Mar 2026 18:57:33 GMT

    And the same request ID is included in logs:

    {
      "message": "[REQUEST - EVENT] finished processing request",
      // ...
      "request_id": "019d1c0f-3a9a-7ad3-adda-1f0ed29e15bd"
    }
  5. When a value is provided in the x-request-id header, it is included in logs and the same is visible in response headers:

    $ curl -H 'x-request-id: test-request-id' -i http://localhost:3001/
    HTTP/1.1 404 Not Found
    x-request-id: test-request-id
    x-version: v0.7.0-8-gf5c1cbd7738c-dirty
    content-length: 0
    date: Mon, 23 Mar 2026 18:58:34 GMT
    {
      "message": "[REQUEST - EVENT] finished processing request",
      // ...
      "request_id": "test-request-id"
    }

P.S.: I intentionally changed the log formatting to use prettified JSON for readability. Otherwise, as per the changes in the PR, using json log format would print compact JSON logs itself, not prettified JSON.

@SanchithHegde SanchithHegde self-assigned this Mar 23, 2026
@SanchithHegde SanchithHegde changed the title refactor: use build_info crate to obtain cargo workspace members refactor: migrate to use build_info and log_utils crates for build information and logging framework Mar 23, 2026
Comment thread src/logger/setup.rs
Comment on lines +19 to +21
let mut workspace_members = build_info::cargo_workspace_members!();
workspace_members.extend(build_info::framework_libs_workspace_members());
workspace_members.extend(crates_to_filter.iter().copied());
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is to enable logs for crates in this repo, crates from the framework-libs-rs repo and any additional crates passed in crates_to_filter.

Comment thread src/logger/setup.rs
level: config.console.level.into_level(),
log_format,
filtering_directive: Some(console_filter_directive),
print_filtering_directive: DirectivePrintTarget::Stdout,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Let me know if you would prefer this printed to stderr, or not printed at all.

Currently, this line is printed to stdout at the beginning:

[INFO] log_utils: Using console filtering directive: WARN,tartarus=DEBUG,locker=DEBUG,hyperswitch_masking=DEBUG,log_utils=DEBUG,tower_http=DEBUG,build_info=DEBUG

Note that this line is printed as is, even if the JSON formatting is enabled.

Comment thread src/app.rs
@ShankarSinghC ShankarSinghC merged commit b5ca83a into main Mar 24, 2026
10 checks passed
@ShankarSinghC ShankarSinghC deleted the use-log-utils-and-build-info branch March 24, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants