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

chore(open-payments): adding debug logs for client initialization & requests #485

Merged
merged 14 commits into from
Jul 4, 2024

Conversation

mkurapov
Copy link
Contributor

@mkurapov mkurapov commented Jul 3, 2024

Changes proposed in this pull request

  • Setting default log level to silent
  • Adding debug logs to client initialization
  • Adding debug logs when making requests & receiving responses

Example logs when GETting a wallet address, and making an incorrect grant request:

{
  "name": "Open Payments Client",
  "msg": "Loading key from file path: /Users/max/interledger/open-payments-test/private.key"
}
{
  "name": "Open Payments Client",
  "walletAddressUrl": "incorrect client",
  "keyId": "bde57813-19cb-437f-9e51-731aa9ebf333",
  "validateResponses": false,
  "useHttp": false,
  "requestTimeoutMs": 5000,
  "msg": "Created authenticated client"
}
{
  "name": "Open Payments Client",
  "method": "GET",
  "url": "https://ilp.rafiki.money/max_usd",
  "msg": "Sending request"
}
{
  "name": "Open Payments Client",
  "method": "GET",
  "url": "https://ilp.rafiki.money/max_usd",
  "body": {
    "id": "https://ilp.rafiki.money/max_usd",
    "publicName": "Max - Usd",
    "assetCode": "USD",
    "assetScale": 2,
    "authServer": "https://auth.rafiki.money",
    "resourceServer": "https://ilp.rafiki.money"
  },
  "status": 200,
  "msg": "Received response"
}
{
  "name": "Open Payments Client",
  "method": "POST",
  "url": "https://auth.rafiki.money/",
  "body": {
    "access_token": {
      "access": [
        {
          "type": "incoming-payment",
          "actions": [
            "read",
            "complete",
            "create"
          ]
        }
      ]
    },
    "client": "incorrect client"
  },
  "msg": "Sending request"
}
{
  "name": "Open Payments Client",
  "method": "POST",
  "url": "https://auth.rafiki.money/",
  "body": {
    "error": {
      "code": "invalid_client",
      "description": "could not determine client"
    }
  },
  "status": 400,
  "msg": "Received response"
}
{
  "name": "Open Payments Client",
  "method": "POST",
  "url": "https://auth.rafiki.money/",
  "status": 400,
  "description": "could not determine client",
  "code": "invalid_client",
  "msg": "Error making Open Payments POST request"
}

Context

Copy link

changeset-bot bot commented Jul 3, 2024

🦋 Changeset detected

Latest commit: 2a9b27f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@interledger/open-payments Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mkurapov mkurapov marked this pull request as ready for review July 3, 2024 10:59
@mkurapov mkurapov changed the title 482/mk/adding logging chore(open-payments): adding debug logs for client initialization & requests Jul 3, 2024
Base automatically changed from 482/mk/error-codes to main July 3, 2024 11:30
@mkurapov mkurapov requested a review from sidvishnoi July 3, 2024 11:37
@@ -56,7 +56,7 @@ const incomingPayment = await client.walletAddress.get({
| ------------------- | --------------------------------------------------------------------------------------------------------------- |
| `requestTimeoutMs` | (optional) The timeout in ms for each request by the client. Defaults to 5000. |
| `logger` | (optional) The custom logger to provide for the client. Defaults to pino logger. |
| `logLevel` | (optional) The log level for the client. Defaults to `info`. |
| `logLevel` | (optional) The log level for the client. Defaults to `silent`. |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think external libraries like ours should only log if explicitly specified

Copy link

netlify bot commented Jul 3, 2024

Deploy Preview for openpayments-preview canceled.

Name Link
🔨 Latest commit 2a9b27f
🔍 Latest deploy log https://app.netlify.com/sites/openpayments-preview/deploys/6686931179c4820008bcae66

Comment on lines +202 to +204
throw new OpenPaymentsClientError(errorMessage, {
description
})
Copy link
Member

Choose a reason for hiding this comment

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

Might be worthwhile to pass Error.cause for better debugging sometime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that would be a nice improvement to the errors. I think this is something to tackle when updating Typescript in the repo, as we currently don't have the updated types for Error class that includes cause. We can do it then such that we do it properly instead of using ts-ignore

Copy link
Member

@sidvishnoi sidvishnoi Jul 4, 2024

Choose a reason for hiding this comment

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

Aside: On updating TypeScript, I was updating @apidevtools/json-schema-ref-parser today (due to some node-fetch error it apparently causes on Windows), but then it required updating pretty much all dependencies, from openapi-typescript to TypeScript to eslint 😄.
Should do that sometime - nearly all dependencies pretty out of date

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should do that sometime - nearly all dependencies pretty out of date

Yes, maybe in a next sprint I can go through it 😅

Copy link
Member

@sidvishnoi sidvishnoi left a comment

Choose a reason for hiding this comment

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

PR looks fine to me, but I haven't tested it locally to feel it.

packages/open-payments/src/client/index.ts Outdated Show resolved Hide resolved
packages/open-payments/src/client/index.ts Outdated Show resolved Hide resolved
@mkurapov
Copy link
Contributor Author

mkurapov commented Jul 4, 2024

Actions failing, cause:

- uses: pnpm/action-setup@v2
with:
version: 8
- uses: pnpm/action-setup@v4
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines -8 to -9
with:
version: 8
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise:

Error: Multiple versions of pnpm specified:
    - version 8 in the GitHub Action config with the key "version"
    - version pnpm@8.[15](https://github.com/interledger/open-payments/actions/runs/9794096762/job/27043408325?pr=485#step:3:17).6 in the package.json with the key "packageManager"
  Remove one of these versions to avoid version mismatch errors like ERR_PNPM_BAD_PM_VERSION  

Copy link
Member

@sidvishnoi sidvishnoi left a comment

Choose a reason for hiding this comment

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

I'm inclined to do the pnpm update as a separate PR, but ok anyway.

@mkurapov mkurapov merged commit d7535db into main Jul 4, 2024
10 checks passed
@mkurapov mkurapov deleted the 482/mk/adding-logging branch July 4, 2024 13:19
@mkurapov mkurapov linked an issue Jul 4, 2024 that may be closed by this pull request
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.

Expose error code/response body to OpenPaymentsClientError
3 participants