-
Notifications
You must be signed in to change notification settings - Fork 1
Sam/ws transport #12
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
Open
samholmes
wants to merge
5
commits into
main
Choose a base branch
from
sam/ws-transport
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Sam/ws transport #12
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c517099
refactor(logger): replace console with Pino for logging
samholmes a4043d8
Disable some chains
samholmes 31d5321
feat: Add flexible service key matching with URL templating
samholmes c54808e
refactor: use service key URL matching for nownodes
samholmes d9c897f
feat: add websocket RPC transport support for evmRpc plugin
samholmes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,75 @@ | ||
| # Change Server Logging | ||
|
|
||
| ## Implementation | ||
|
|
||
| Uses Pino with a base logger and child loggers for scoping. Located in `src/util/logger.ts`. | ||
|
|
||
| ### API | ||
|
|
||
| ```typescript | ||
| import { logger, makeLogger } from './util/logger' | ||
|
|
||
| // Direct use of base logger for simple cases: | ||
| logger.info({ port: 3000 }, 'server started') | ||
|
|
||
| // For code plugins (blockbook, evmRpc): | ||
| const pluginLogger = makeLogger('blockbook', 'ethereum') // scope, chainPluginId | ||
|
|
||
| // For non-plugin code: | ||
| const socketLogger = makeLogger('socket') // scope only | ||
|
|
||
| // Returns a pino.Logger - use standard Pino API: | ||
| pluginLogger.info('message') | ||
| pluginLogger.warn('message') | ||
| pluginLogger.error('message') | ||
|
|
||
| // Pass an object with extra fields: | ||
| pluginLogger.info({ ip: '1.2.3.4' }, 'connected') | ||
| pluginLogger.info({ blockNum: '12345' }, 'block') | ||
| ``` | ||
|
|
||
| ### Output Format | ||
|
|
||
| JSON with these fields: | ||
|
|
||
| - `level` - numeric level (30=info, 40=warn, 50=error) | ||
| - `time` - numeric epoch milliseconds | ||
| - `scope` - scope identifier (code plugin name: "blockbook", "evmRpc", "socket", "server") | ||
| - `chainPluginId` - chain plugin ID (optional, e.g., "ethereum", "arbitrum") | ||
| - `pid` - process ID (for socket events) | ||
| - `sid` - socket ID (for socket events, identifies the connection) | ||
| - `msg` - text message (Pino default key) | ||
| - Additional fields from passed objects | ||
|
|
||
| Example: | ||
|
|
||
| ```json | ||
| {"level":30,"time":1735654281000,"scope":"blockbook","chainPluginId":"bitcoin","blockNum":"876543","msg":"block"} | ||
| {"level":30,"time":1735654281000,"scope":"socket","pid":20812,"sid":396,"ip":"192.168.1.1","msg":"connected"} | ||
| {"level":50,"time":1735654281000,"scope":"evmRpc","chainPluginId":"ethereum","msg":"watchBlocks error: connection timeout"} | ||
| ``` | ||
|
|
||
| ### pino-pretty Support | ||
|
|
||
| Logs are compatible with pino-pretty for human-readable output during development: | ||
|
|
||
| ```bash | ||
| node src/index.js | pino-pretty --translateTime | ||
| # Or use -t shorthand: | ||
| node src/index.js | pino-pretty -t | ||
| ``` | ||
|
|
||
| ## Logged Events | ||
|
|
||
| 1. **WebSocket connection established** - scope: `socket`, includes pid, sid, IP | ||
| 2. **Addresses subscribed** - scope: `socket`, includes pid, sid, IP, first 6 chars of addresses, pluginId, checkpoint | ||
| 3. **Block found** - scope: code plugin, includes `chainPluginId`, block number | ||
| 4. **Transaction detected** - scope: code plugin, includes `chainPluginId`, first 6 chars of address and txid | ||
| 5. **Update sent** - scope: `socket`, includes pid, sid, IP, pluginId, address (6 chars), checkpoint | ||
|
|
||
| ## Notes | ||
|
|
||
| - All output goes to stdout for logrotate compatibility | ||
| - Uses Pino's `.child()` pattern for efficient scoped logging | ||
| - Logging is disabled when `NODE_ENV=test` | ||
| - Reserved fields (`time`, `scope`) passed in log objects are automatically renamed with a `_` suffix to avoid conflicts (e.g., `time` becomes `time_`) | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You pass an object with a
msgfield in a ton of places, but your own docs suggest that this is the wrong approach. Should you be passing themsgfield as a second string parameter? If so, that applies to a bunch of places.