Skip to content

Conversation

@gwynne
Copy link
Member

@gwynne gwynne commented Apr 14, 2025

These changes are now available in 1.52.1

While this has no visible impact when using the "default" StreamLogHandler, it becomes quite visible when using smarter log handlers which respect the structural representation afforded by Logger.MetadataValue.

For example, with StreamLogHandler, with or without these changes, a given query might get logged like this:

2025-04-14T06:53:04-0500 debug test : action=update filters=["[\"relation\": \"and\", \"group\": \"[\\\"[\\\\\\\"value\\\\\\\": \\\\\\\"00000000-0000-0000-0000-000000000000\\\\\\\", \\\\\\\"field\\\\\\\": \\\\\\\"composite+planet.system_id\\\\\\\", \\\\\\\"method\\\\\\\": \\\\\\\"=\\\\\\\"]\\\", \\\"[\\\\\\\"field\\\\\\\": \\\\\\\"composite+planet.nrm_ord\\\\\\\", \\\\\\\"method\\\\\\\": \\\\\\\"=\\\\\\\", \\\\\\\"value\\\\\\\": \\\\\\\"1\\\\\\\"]\\\"]\"]"] input=["[\"name\": \"AA\"]"] limits=[] offsets=[] schema=composite+planet sorts=[] [FluentKit] Running query

With a smarter log handler (an only slightly modified version of StreamLogHandler in fact), but without these changes, it looks like this:

2025-04-14T06:58:36-0500 debug test : action="update" filters=[[group: [[field: "composite+planet.system_id", method: "=", value: "00000000-0000-0000-0000-000000000000"], [field: "composite+planet.nrm_ord", method: "=", value: "1"]], relation: "and"]] input=[[name: ""AA""]] limits=[] offsets=[] schema="composite+planet" sorts=[] [FluentKit] Running query

Notice that "1" is in quotes and ""AA"" is double-quoted. But with these changes, and the modified handler, the log now looks like this:

2025-04-14T06:59:29-0500 debug test : action="update" filters=[[group: [[field: "composite+planet.system_id", method: "=", value: "00000000-0000-0000-0000-000000000000"], [field: "composite+planet.nrm_ord", method: "=", value: 1]], relation: "and"]] input=[[name: "AA"]] limits=[] offsets=[] schema="composite+planet" sorts=[] [FluentKit] Running query

…metadata. This has no visible impact when using the "default" StreamLogHandler, but it's quite visible with smarter log handlers.
@gwynne gwynne added enhancement New feature or request semver-patch Internal changes only labels Apr 14, 2025
@gwynne gwynne requested review from 0xTim, MahdiBM and ptoffy April 14, 2025 12:02
@codecov
Copy link

codecov bot commented Apr 14, 2025

Codecov Report

Attention: Patch coverage is 0% with 23 lines in your changes missing coverage. Please review.

Project coverage is 23.86%. Comparing base (0f1b8bf) to head (e707978).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...FluentKit/Query/Database/DatabaseQuery+Value.swift 0.00% 12 Missing ⚠️
...FluentKit/Query/Database/DatabaseQuery+Range.swift 0.00% 8 Missing ⚠️
...urces/FluentKit/Query/Database/DatabaseQuery.swift 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #635      +/-   ##
==========================================
- Coverage   23.91%   23.86%   -0.06%     
==========================================
  Files         149      149              
  Lines        9327     9347      +20     
==========================================
  Hits         2231     2231              
- Misses       7096     7116      +20     
Files with missing lines Coverage Δ
...urces/FluentKit/Query/Database/DatabaseQuery.swift 21.42% <0.00%> (ø)
...FluentKit/Query/Database/DatabaseQuery+Range.swift 0.00% <0.00%> (ø)
...FluentKit/Query/Database/DatabaseQuery+Value.swift 30.76% <0.00%> (-13.68%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gwynne gwynne merged commit 1385c48 into main Apr 14, 2025
16 checks passed
@gwynne gwynne deleted the improve-logging-metadata branch April 14, 2025 12:36
bwdmr pushed a commit to bwdmr/fluent-kit that referenced this pull request Dec 17, 2025
…metadata (vapor#635)

Slightly improve the way database queries are represented in logging metadata. This has no visible impact when using the "default" StreamLogHandler, but it's quite visible with smarter log handlers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request semver-patch Internal changes only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants