-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new log system and record logs from LLD internal thread (#4709)
`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
- Loading branch information
1 parent
c2704dc
commit 9e2d32a
Showing
36 changed files
with
1,371 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
"ledger-live-desktop": patch | ||
--- | ||
|
||
feat: enable printing logs to stdout for debug and record logs from internal thread | ||
|
||
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@ledgerhq/logs": minor | ||
--- | ||
|
||
feat: new trace and LocalTracer definition | ||
|
||
Without breaking the behavior of the existing log function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"live-mobile": patch | ||
"@ledgerhq/live-env": patch | ||
--- | ||
|
||
feat: enable printing logs to stdout for debug | ||
|
||
- Setup simple tracing system on LLM with context | ||
- If `VERBOSE` env var is set, filtered logs can be stdout from the main thread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
"@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 | ||
--- | ||
|
||
feat: usage of new tracing system | ||
|
||
The tracing helps keeping a context (for ex a `job id`) that is propagated to other logs, | ||
creating a (simple) tracing span |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Log } from "@ledgerhq/logs"; | ||
|
||
/** | ||
* Simple logger sending recorded logs directly to the main process | ||
* | ||
* Usage: records logs coming from `@ledgerhq/logs` in the internal thread | ||
* | ||
* If performance issues are seen because of this direct send to the main process, several ideas could be implemented: | ||
* - a filtering on the `type` (or/and a level if it is implemented in `@ledgerhq/logs`) set from an env variable | ||
* - a `bulkLog` that records logs until a given threshold, and send them to the main process when reached | ||
*/ | ||
export class ForwardToMainLogger { | ||
private static instance: ForwardToMainLogger | undefined; | ||
|
||
// Simple singleton factory | ||
static getLogger() { | ||
if (!ForwardToMainLogger.instance) { | ||
ForwardToMainLogger.instance = new ForwardToMainLogger(); | ||
} | ||
return ForwardToMainLogger.instance; | ||
} | ||
|
||
// We could have a "log:bulk-log" | ||
log(log: Log) { | ||
process?.send?.({ | ||
type: "log:log", | ||
data: log, | ||
requestId: "log", // Not used | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
9e2d32a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
live-common-tools – ./apps/web-tools
live-common-tools-ledgerhq.vercel.app
live.ledger.tools
ledger-live.vercel.app
live-common-tools-git-develop-ledgerhq.vercel.app
ledger-live-tools.vercel.app