Skip to content

feat: setup new log system and record logs from LLD internal thread #4709

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

Merged
merged 18 commits into from
Sep 21, 2023

Conversation

alexandremgo
Copy link
Contributor

@alexandremgo alexandremgo commented Sep 15, 2023

📝 Description

ledgerjs/logs

  • new trace and LocalTracer definitions, without breaking the behavior of the existing log function

hw-transport, hw-transport-node-hid-noevents, hw-transport-node-hid-singleton, react-native-hw-transport-ble, ledger-live-common

  • Usage of new tracing system in some transports
  • The tracing helps keeping a context (for ex a job id) that is propagated to other logs, creating a (simple) tracing span

Note on the "tracing": for now added a simple "context" that is propagated from withDevice to called functions, mainly from Transport. This is a preview of what could be done to have a real tracing system in the DeviceSDK

Note: the optional openTimeoutMs on the different open function is necessary for legacy (used by one of the Transport), and will actually be used in another PR. Don't mind it during the code review. But it should only by passed to a couple of other functions, not directly used (in this PR).

LLD:

  • Logs from the internal thread are forwarded to the main thread
  • The main thread records them, and can export them
    • on export, recorded logs from the renderer thread are sent to the main thread, and the main thread expand (not a merge, just pushed at the end) them with the logs it recorded from the internal thread
  • If VERBOSE env var is set, filtered logs can be stdout from the main thread
    • Same from the renderer thread
  • Setup simple tracing system (context) on LLD

Usage with VERBOSE:

VERBOSE="apdu,hw,hid-verbose,usb-detection" pnpm dev:lld

LLM:

  • Setup simple tracing system on LLM with context
  • If VERBOSE env var is set, filtered logs can be stdout from the main thread

Usage with VERBOSE: in a .env file, add (for ex)

VERBOSE="apdu,hw,ble-verbose,ble-error,transport"

You will need to re-build fully the app so the new .env file is transfered.

❓ Context

  • Impacted projects: hw-transport, hw-transport-node-hid-noevents, hw-transport-node-hid-singleton, react-native-hw-transport-ble, ledger-live-common , ledgerjs/logs, LLM and LLD
  • Linked resource(s): LIVE-9405

✅ Checklist

  • Test coverage
  • Atomic delivery
  • No breaking changes

📸 Demo

LLD performance

Non-scientific manual measurements (on dev build): beginning of the fw update until the end of the fw transfer:

Measurements fw update transfer

With new log system (without VERBOSE):

  • 47.909 s
  • 48.228 s
  • 46.515 s
  • 47.181 s
  • 47.807 s

Without new log system:

  • 47.311 s
  • 48.783 s
  • 48.184 s
  • 47.092 s
  • 47.667 s

-> no obvious performance decline

Exported logs from LLD

Example separation `renderer` and `internal` thread LLD_export_logs_separation

Stdout debug logs on LLD with VERBOSE

LLD logs on terminal LLD_stdout_logs_VERBOSE

Stdout debug logs on LLM with VERBOSE

LLM logs on terminal LLM_stdout_ex

🚀 Expectations to reach

@alexandremgo alexandremgo requested a review from a team September 15, 2023 14:15
@changeset-bot
Copy link

changeset-bot bot commented Sep 15, 2023

🦋 Changeset detected

Latest commit: 5f0c8af

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

This PR includes changesets to release 49 packages
Name Type
ledger-live-desktop Patch
@ledgerhq/logs Minor
live-mobile Patch
@ledgerhq/live-env Patch
@ledgerhq/hw-transport-node-hid-singleton Minor
@ledgerhq/hw-transport-node-hid-noevents Minor
@ledgerhq/react-native-hw-transport-ble Minor
@ledgerhq/hw-transport Minor
@ledgerhq/live-common Patch
@ledgerhq/live-cli Patch
web-tools Patch
@ledgerhq/coin-evm Patch
@ledgerhq/coin-framework Patch
@ledgerhq/coin-polkadot Patch
@ledgerhq/domain-service Patch
@ledgerhq/live-network Patch
@ledgerhq/live-promise Patch
@ledgerhq/devices Patch
@ledgerhq/hw-app-btc Patch
@ledgerhq/hw-app-eth Patch
@ledgerhq/hw-app-helium Patch
@ledgerhq/hw-app-solana Patch
@ledgerhq/hw-transport-http Patch
@ledgerhq/hw-transport-mocker Patch
@ledgerhq/hw-transport-node-ble Patch
@ledgerhq/hw-transport-node-hid Patch
@ledgerhq/hw-transport-node-speculos-http Patch
@ledgerhq/hw-transport-node-speculos Patch
@ledgerhq/hw-transport-vault Patch
@ledgerhq/hw-transport-web-ble Patch
@ledgerhq/hw-transport-webhid Patch
@ledgerhq/hw-transport-webusb Patch
@ledgerhq/react-native-hid Patch
@ledgerhq/coin-algorand Patch
@ledgerhq/evm-tools Patch
dummy-wallet-app Patch
@ledgerhq/hw-app-algorand Patch
@ledgerhq/hw-app-cosmos Patch
@ledgerhq/hw-app-exchange Patch
@ledgerhq/hw-app-near Patch
@ledgerhq/hw-app-polkadot Patch
@ledgerhq/hw-app-str Patch
@ledgerhq/hw-app-tezos Patch
@ledgerhq/hw-app-trx Patch
@ledgerhq/hw-app-xrp Patch
@ledgerhq/swift-bridge-hw-transport-ble Patch
@ledgerhq/test-utils Patch
@ledgerhq/swift-bridge-hw-app-eth Patch
@ledgerhq/swift-bridge-hw-app-solana Patch

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

@vercel
Copy link

vercel bot commented Sep 15, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ledger-live-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2023 3:51pm
live-common-tools ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2023 3:51pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
ledger-live-github-bot ⬜️ Ignored (Inspect) Visit Preview Sep 20, 2023 3:51pm
native-ui-storybook ⬜️ Ignored (Inspect) Visit Preview Sep 20, 2023 3:51pm
react-ui-storybook ⬜️ Ignored (Inspect) Visit Preview Sep 20, 2023 3:51pm

Copy link
Contributor

@gre gre left a comment

Choose a reason for hiding this comment

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

great rework overall. some minor comments

@vercel
Copy link

vercel bot commented Sep 18, 2023

Deployment failed with the following error:

Too many requests - try again in 49 seconds (more than 60, code: "api-deployments-flood").

Without breaking the behavior of the existing log function
The tracing helps keeping a context (for ex a `job id`) that is
propagated to other logs, creating a tracing span
And enable filtering on logs displayed in the console for
better debugging sessions
- Logs from the internal thread are forward to the main thread
- The main thread records them, and can export them
- If `VERBOSE` env var is set, filtered logs can be stdout from the main thread
- Same from the renderer thread
- Setup simple tracing system (context) on LLD
Avoiding any crash with try/catch when formatting
- and usage in LLM and LLD
- also put LLM console logger mechanism in a class ConsoleLogger
Now manually JSON.stringify logs from the renderer thread
before sending them to the main thread
The equivalent to the withDevice from a 1st version
of the new device SDK
@sentry-io
Copy link

sentry-io bot commented Sep 21, 2023

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ Error: Error invoking remote method 'save-logs': Error: EROFS: read-only file system, open '/ledgerlive-... saveLogs(src/renderer/components/ExportLogsButton) View Issue
  • ‼️ TransportRaceCondition: An action was already pending on the Ledger device. Please deny or reconnect. Go.<anonymous>(libs/ledgerjs/packages/hw-transp... View Issue
  • ‼️ FirmwareOrAppUpdateRequired: Ledger device: Invalid parameter received (0x6b00) initialErrorRemapping(libs/ledger-live-common/s... View Issue
  • ‼️ DeviceHalted: Ledger device: Internal error, please report (0x6faa) initialErrorRemapping(libs/ledger-live-common/s... View Issue

Did you find this useful? React with a 👍 or 👎

lambertkevin pushed a commit that referenced this pull request Sep 22, 2023
`ledgerjs/logs`:
* new `trace` and `LocalTracer` definitions, without breaking the behavior of the existing `log` function

`hw-transport`, `hw-transport-node-hid-noevents`, `hw-transport-node-hid-singleton`, `react-native-hw-transport-ble`, `ledger-live-common` 
* Usage of new tracing system in some transports
* The tracing helps keeping a context (for ex a `job id`) that is propagated to other logs, creating a (simple) tracing span

Note on the "tracing": for now added a simple "context" that is propagated from `withDevice` to called functions, mainly from Transport. This is a preview of what could be done to have a real tracing system in the DeviceSDK

Note: the optional `openTimeoutMs` on the different `open` function is necessary for legacy (used by one of the Transport), and will actually be used in the future.

LLD:
* Logs from the `internal` thread are forwarded to the `main` thread
* The `main` thread records them, and can export them
  * on export, recorded logs from the `renderer` thread are sent to the `main` thread, and the `main` thread expand (not a merge, just pushed at the end) them with the logs it recorded from the `internal` thread
* If `VERBOSE` env var is set, filtered logs can be stdout from the main thread
  * Same from the `renderer` thread
* Setup simple tracing system (context) on LLD

LLM:
* Setup simple tracing system on LLM with context
* If `VERBOSE` env var is set, filtered logs can be stdout from the main thread
mcayuelas-ledger pushed a commit that referenced this pull request Sep 27, 2023
`ledgerjs/logs`:
* new `trace` and `LocalTracer` definitions, without breaking the behavior of the existing `log` function

`hw-transport`, `hw-transport-node-hid-noevents`, `hw-transport-node-hid-singleton`, `react-native-hw-transport-ble`, `ledger-live-common` 
* Usage of new tracing system in some transports
* The tracing helps keeping a context (for ex a `job id`) that is propagated to other logs, creating a (simple) tracing span

Note on the "tracing": for now added a simple "context" that is propagated from `withDevice` to called functions, mainly from Transport. This is a preview of what could be done to have a real tracing system in the DeviceSDK

Note: the optional `openTimeoutMs` on the different `open` function is necessary for legacy (used by one of the Transport), and will actually be used in the future.

LLD:
* Logs from the `internal` thread are forwarded to the `main` thread
* The `main` thread records them, and can export them
  * on export, recorded logs from the `renderer` thread are sent to the `main` thread, and the `main` thread expand (not a merge, just pushed at the end) them with the logs it recorded from the `internal` thread
* If `VERBOSE` env var is set, filtered logs can be stdout from the main thread
  * Same from the `renderer` thread
* Setup simple tracing system (context) on LLD

LLM:
* Setup simple tracing system on LLM with context
* If `VERBOSE` env var is set, filtered logs can be stdout from the main thread
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Has changes in live-common desktop Has changes in LLD ledgerjs Has changes in the ledgerjs open source libs mobile Has changes in LLM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants