[PR #1870] [MERGED] feat: add more api logs #1899

Closed
opened 2026-02-26 20:31:34 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/documenso/documenso/pull/1870
Author: @dguyen
Created: 6/29/2025
Status: Merged
Merged: 6/30/2025
Merged by: @Mythie

Base: mainHead: feat/more-api-logs


📝 Commits (3)

  • 78a6dd1 feat: add more api logs
  • 3dece4b fix: remove test error
  • 732d944 fix: default to pretty logs for dev

📊 Changes

74 files changed (+1388 additions, -537 deletions)

View changed files

📝 .env.example (+3 -1)
📝 .gitignore (+3 -0)
📝 package-lock.json (+0 -137)
📝 packages/api/v1/implementation.ts (+265 -166)
📝 packages/api/v1/middleware/authenticated.ts (+29 -15)
📝 packages/lib/package.json (+0 -1)
packages/lib/types/api-logs.ts (+29 -0)
📝 packages/lib/universal/extract-request-metadata.ts (+9 -5)
packages/lib/utils/logger-legacy.ts (+0 -112)
📝 packages/lib/utils/logger.ts (+27 -19)
📝 packages/trpc/server/admin-router/create-admin-organisation.ts (+7 -1)
📝 packages/trpc/server/admin-router/create-stripe-customer.ts (+7 -1)
📝 packages/trpc/server/admin-router/create-subscription-claim.ts (+5 -1)
📝 packages/trpc/server/admin-router/delete-subscription-claim.ts (+7 -1)
📝 packages/trpc/server/admin-router/get-admin-organisation.ts (+7 -1)
📝 packages/trpc/server/admin-router/router.ts (+82 -26)
📝 packages/trpc/server/admin-router/update-admin-organisation.ts (+7 -1)
📝 packages/trpc/server/admin-router/update-subscription-claim.ts (+5 -1)
📝 packages/trpc/server/api-token-router/router.ts (+13 -0)
📝 packages/trpc/server/auth-router/router.ts (+12 -0)

...and 54 more files

📄 Description

Description

Added more detailed API logging

Changes:

  • Log partial API request inputs
  • Add trpc error logging
  • Use new IP extractor for metadata

Main files to review:

  • packages/trpc/server/trpc.ts
  • packages/trpc/server/context.ts
  • packages/api/v1/middleware/authenticated.ts
  • packages/trpc/utils/trpc-error-handler.ts
  • packages/lib/universal/extract-request-metadata.ts

Notes: Below logs will be missing IP since it's local (probably)

Example TRPC request from application

  1. Request log
  2. Input log
[
  {
    "level": 30,
    "time": 1751172288922,
    "pid": 64247,
    "hostname": "Some hostname",
    "userAgent": "Mozilla/5.0 (Macintosh) Firefox/139.0",
    "requestId": "0m94noqa1vlgvvligaf76",
    "nonBatchedRequestId": "kdamp7f893gvolax6yd6i",
    "path": "document.findDocumentAuditLogs",
    "auth": null,
    "source": "app",
    "trpcMiddleware": "authenticated",
    "unverifiedTeamId": 3,
    "userId": 3,
    "apiTokenId": null
  },
  {
    "level": 30,
    "time": 1751172288922,
    "pid": 64247,
    "hostname": "Some hostname",
    "userAgent": "Mozilla/5.0 (Macintosh) Firefox/139.0",
    "requestId": "0m94noqa1vlgvvligaf76",
    "nonBatchedRequestId": "kdamp7f893gvolax6yd6i",
    "input": {
      "documentId": 9
    }
  }
]

Example API V2 Request

  1. Request log
  2. Input log
  3. Error log
[
  {
    "level": 30,
    "time": 1751172028804,
    "pid": 64247,
    "hostname": "Some hostname",
    "requestId": "0g6xgfedqkdu9esh84fwn",
    "path": "document.getDocumentWithDetailsById",
    "auth": null,
    "source": "apiV2",
    "trpcMiddleware": "authenticated",
    "userId": 3,
    "apiTokenId": 2
  },
  {
    "level": 30,
    "time": 1751172028804,
    "pid": 64247,
    "hostname": "Some hostname",
    "requestId": "0g6xgfedqkdu9esh84fwn",
    "input": {
      "documentId": 1
    }
  },
  {
    "level": 30,
    "time": 1751172028804,
    "pid": 64247,
    "hostname": "Some hostname",
    "requestId": "0g6xgfedqkdu9esh84fwn",
    "status": "error",
    "appError": {
      "code": "NOT_FOUND",
      "message": "This is a test error"
    },
    "msg": "TRPC_ERROR_HANDLER"
  }
]

Example API V1 Request

[
  {
    "level": 30,
    "time": 1751172440438,
    "pid": 64247,
    "hostname": "Some hostname",
    "requestId": "9To5fh_kPcC-A3tefgDba",
    "auth": "api",
    "source": "apiV1",
    "path": "http://localhost:3000/api/v1/documents/1",
    "userId": 3,
    "apiTokenId": 2
  },
  {
    "level": 30,
    "time": 1751172440439,
    "pid": 64247,
    "hostname": "Some hostname",
    "requestId": "9To5fh_kPcC-A3tefgDba",
    "input": {
      "id": "1"
    }
  }
]

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/documenso/documenso/pull/1870 **Author:** [@dguyen](https://github.com/dguyen) **Created:** 6/29/2025 **Status:** ✅ Merged **Merged:** 6/30/2025 **Merged by:** [@Mythie](https://github.com/Mythie) **Base:** `main` ← **Head:** `feat/more-api-logs` --- ### 📝 Commits (3) - [`78a6dd1`](https://github.com/documenso/documenso/commit/78a6dd19ade2400b294809dc2d832b09d22a8472) feat: add more api logs - [`3dece4b`](https://github.com/documenso/documenso/commit/3dece4b0fd88b3c7307694708d5b771e11ed80e1) fix: remove test error - [`732d944`](https://github.com/documenso/documenso/commit/732d944ee89612f1b606c6e8f923a46b669cb362) fix: default to pretty logs for dev ### 📊 Changes **74 files changed** (+1388 additions, -537 deletions) <details> <summary>View changed files</summary> 📝 `.env.example` (+3 -1) 📝 `.gitignore` (+3 -0) 📝 `package-lock.json` (+0 -137) 📝 `packages/api/v1/implementation.ts` (+265 -166) 📝 `packages/api/v1/middleware/authenticated.ts` (+29 -15) 📝 `packages/lib/package.json` (+0 -1) ➕ `packages/lib/types/api-logs.ts` (+29 -0) 📝 `packages/lib/universal/extract-request-metadata.ts` (+9 -5) ➖ `packages/lib/utils/logger-legacy.ts` (+0 -112) 📝 `packages/lib/utils/logger.ts` (+27 -19) 📝 `packages/trpc/server/admin-router/create-admin-organisation.ts` (+7 -1) 📝 `packages/trpc/server/admin-router/create-stripe-customer.ts` (+7 -1) 📝 `packages/trpc/server/admin-router/create-subscription-claim.ts` (+5 -1) 📝 `packages/trpc/server/admin-router/delete-subscription-claim.ts` (+7 -1) 📝 `packages/trpc/server/admin-router/get-admin-organisation.ts` (+7 -1) 📝 `packages/trpc/server/admin-router/router.ts` (+82 -26) 📝 `packages/trpc/server/admin-router/update-admin-organisation.ts` (+7 -1) 📝 `packages/trpc/server/admin-router/update-subscription-claim.ts` (+5 -1) 📝 `packages/trpc/server/api-token-router/router.ts` (+13 -0) 📝 `packages/trpc/server/auth-router/router.ts` (+12 -0) _...and 54 more files_ </details> ### 📄 Description ## Description Added more detailed API logging Changes: - Log partial API request inputs - Add trpc error logging - Use new IP extractor for metadata Main files to review: - packages/trpc/server/trpc.ts - packages/trpc/server/context.ts - packages/api/v1/middleware/authenticated.ts - packages/trpc/utils/trpc-error-handler.ts - packages/lib/universal/extract-request-metadata.ts Notes: Below logs will be missing IP since it's local (probably) ## Example TRPC request from application 1. Request log 2. Input log ```json [ { "level": 30, "time": 1751172288922, "pid": 64247, "hostname": "Some hostname", "userAgent": "Mozilla/5.0 (Macintosh) Firefox/139.0", "requestId": "0m94noqa1vlgvvligaf76", "nonBatchedRequestId": "kdamp7f893gvolax6yd6i", "path": "document.findDocumentAuditLogs", "auth": null, "source": "app", "trpcMiddleware": "authenticated", "unverifiedTeamId": 3, "userId": 3, "apiTokenId": null }, { "level": 30, "time": 1751172288922, "pid": 64247, "hostname": "Some hostname", "userAgent": "Mozilla/5.0 (Macintosh) Firefox/139.0", "requestId": "0m94noqa1vlgvvligaf76", "nonBatchedRequestId": "kdamp7f893gvolax6yd6i", "input": { "documentId": 9 } } ] ``` ## Example API V2 Request 1. Request log 2. Input log 3. Error log ```json [ { "level": 30, "time": 1751172028804, "pid": 64247, "hostname": "Some hostname", "requestId": "0g6xgfedqkdu9esh84fwn", "path": "document.getDocumentWithDetailsById", "auth": null, "source": "apiV2", "trpcMiddleware": "authenticated", "userId": 3, "apiTokenId": 2 }, { "level": 30, "time": 1751172028804, "pid": 64247, "hostname": "Some hostname", "requestId": "0g6xgfedqkdu9esh84fwn", "input": { "documentId": 1 } }, { "level": 30, "time": 1751172028804, "pid": 64247, "hostname": "Some hostname", "requestId": "0g6xgfedqkdu9esh84fwn", "status": "error", "appError": { "code": "NOT_FOUND", "message": "This is a test error" }, "msg": "TRPC_ERROR_HANDLER" } ] ``` ## Example API V1 Request ```json [ { "level": 30, "time": 1751172440438, "pid": 64247, "hostname": "Some hostname", "requestId": "9To5fh_kPcC-A3tefgDba", "auth": "api", "source": "apiV1", "path": "http://localhost:3000/api/v1/documents/1", "userId": 3, "apiTokenId": 2 }, { "level": 30, "time": 1751172440439, "pid": 64247, "hostname": "Some hostname", "requestId": "9To5fh_kPcC-A3tefgDba", "input": { "id": "1" } } ] ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-26 20:31:34 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/documenso#1899
No description provided.