Skip to content

[O2B-1645] Distinguish the type of API clients in the API logs - #2298

Merged
graduta merged 3 commits into
mainfrom
feature/O2B-1645/distinguish-type-of-API-clients
Oct 26, 2026
Merged

graduta merged 3 commits into
mainfrom
feature/O2B-1645/distinguish-type-of-API-clients

Conversation

@graduta

@graduta graduta commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

I have a JIRA ticket

  • branch and/or PR name(s) include(s) JIRA ID
  • issue has "Fix version" assigned
  • issue "Status" is set to "In review"
  • PR labels are selected

Notable changes for users:

  • N/A

Notable changes for developers:

  • Every API log entry (HTTP and gRPC) now has two new fields, client and device, so that the traffic can be split by kind of client in OpenSearch
  • client is identified from the User-Agent the caller declares: browser, curl, wget, python, node, go, java, postman, grpc-node, grpc-cxx, grpc-python, grpc-go, grpc-java, grpc-other or unknown. Postman is identified for both HTTP (PostmanRuntime/x) and gRPC (grpc-node-js/x-postman.y)
  • device is only set for browsers (null otherwise): phone, tablet or desktop, deduced from the User-Agent and the Sec-CH-UA-Mobile client hint. An iPad requesting the desktop version of websites can not be told apart from a Mac
  • Both are self-reported by the caller, so they are meant for statistics only and must never be used for security purposes
  • The classifier is identifyClient (new, with its ApiClients and ApiDevices enums). It is called by ApiRequestLogger, so the HTTP middleware and the gRPC binding only provide the raw user-agent
  • The reverse proxy (nginx) must forward the User-Agent header, which is the default behavior
  • The documentation of the API log is updated, and the maximum length of the logged params is fixed in it (500 characters, not 1000)

Changes made to the database:

  • N/A

@graduta
graduta requested a review from isaachilly as a code owner October 26, 2026 15:35
@graduta graduta self-assigned this Oct 26, 2026
@graduta
graduta requested a balanced review from Copilot October 26, 2026 15:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The additive logging changes are consistent across both protocols, have focused test coverage, and have no identified blocking issues.

No open issues 🎉

What changed in this PR

Adds client and device classification to the shared HTTP and gRPC API logs, enabling traffic analysis by client type in OpenSearch.

Changes:

  • Introduces a shared User-Agent classifier and client/device enums.
  • Passes request headers into the logger and adds classification tests for both protocols.
  • Documents the new fields and corrects the documented params truncation limit to 500 characters.
File Description
test/​lib/​server/​utilities/​index.js Registers classifier tests.
test/​lib/​server/​utilities/​identifyClient.test.js Tests client types, browser devices, and missing User-Agent values.
test/​lib/​server/​utilities/​ApiRequestLogger.test.js Verifies classification fields in log entries.
test/​lib/​server/​middleware/​accessLog.middleware.test.js Tests HTTP classification and mobile hints.
test/​gRPC/​serviceImplementation.test.js Verifies gRPC client classification in logs.
lib/​server/​utilities/​identifyClient.js Implements client and browser-device classification.
lib/​server/​utilities/​ApiRequestLogger.js Adds client and device to shared log entries.
lib/​server/​middleware/​accessLog.middleware.js Passes User-Agent and mobile hints to the logger.
lib/​server/​gRPC/​bindGRPCController.js Passes gRPC User-Agent metadata to the logger.
lib/​domain/​enums/​ApiDevices.js Defines browser-device categories.
lib/​domain/​enums/​ApiClients.js Defines client categories.
docs/​backend-architecture.md Documents classification fields, limitations, and the corrected truncation limit.

Review effort: Balanced

@graduta
graduta merged commit b6921bc into main Oct 26, 2026
25 checks passed
@graduta
graduta deleted the feature/O2B-1645/distinguish-type-of-API-clients branch October 26, 2026 15:42
@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.01%. Comparing base (947277a) to head (5abca78).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2298      +/-   ##
==========================================
+ Coverage   45.94%   46.01%   +0.06%     
==========================================
  Files        1067     1070       +3     
  Lines       17589    17609      +20     
  Branches     3252     3261       +9     
==========================================
+ Hits         8082     8102      +20     
  Misses       9507     9507              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants