-
Notifications
You must be signed in to change notification settings - Fork 3
Integrate rust logging #423
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
adespawn
wants to merge
5
commits into
scylladb:main
Choose a base branch
from
adespawn:logging-tracing
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b24ae5
Add log event forwarding infrastructure
adespawn d09baf6
Add logLevel client option for configurable log filtering
adespawn 0f981da
Add logging unit and integration tests
adespawn 65616e6
Add logLevels API tests for JS and TypeScript type definitions
adespawn 1589d55
Add documentation about logging
adespawn 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
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,119 @@ | ||
| # Logging | ||
|
|
||
| The driver uses [events](https://nodejs.org/api/events.html) to expose logging | ||
| information, keeping it decoupled from any specific logging framework. | ||
|
|
||
| The `Client` class inherits from | ||
| [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter) | ||
| and emits `'log'` events: | ||
|
|
||
| ```js | ||
| client.on('log', (level, target, message, furtherInfo) => { | ||
| console.log(`${level} - ${target}: ${message}`); | ||
| }); | ||
| ``` | ||
|
|
||
| ## Enabling logging | ||
|
|
||
| Logging is **disabled by default**. To enable it, set the `logLevel` client | ||
| option to the minimum severity you want to receive: | ||
|
|
||
| ```js | ||
| const { Client, types } = require('scylladb-driver-alpha'); | ||
|
|
||
| const client = new Client({ | ||
| contactPoints: ['127.0.0.1'], | ||
| logLevel: types.logLevels.info, | ||
| }); | ||
| ``` | ||
|
|
||
| The callback is registered when `connect()` is called and unregistered on | ||
| `shutdown()`. No log events are emitted before the client connects. | ||
|
|
||
| ## Log levels | ||
|
|
||
| Log levels are exposed through the `types.logLevels` enum: | ||
|
|
||
| | Enum variant | Raw value | Description | | ||
| | ------------------- | ----------- | ---------------------------------------------------- | | ||
| | `logLevels.trace` | `'trace'` | Finest-grained diagnostic information (TRACE events) | | ||
| | `logLevels.debug` | `'debug'` | Fine-grained diagnostic information (DEBUG events) | | ||
| | `logLevels.info` | `'info'` | High-level informational messages | | ||
| | `logLevels.warning` | `'warning'` | Potentially harmful situations | | ||
| | `logLevels.error` | `'error'` | Error conditions | | ||
| | `logLevels.off` | `'off'` | Disables logging entirely (default) | | ||
|
|
||
| The `logLevel` option acts as a **filter**: only events at or above the | ||
| configured severity are delivered to the listener. Filtering happens on the | ||
| native side, before crossing the FFI boundary, so suppressed events have | ||
| virtually zero overhead. | ||
|
|
||
| | `logLevel` value | Events delivered | | ||
| | ------------------- | -------------------------- | | ||
| | `logLevels.off` | None (default) | | ||
| | `logLevels.trace` | All (TRACE and above) | | ||
| | `logLevels.debug` | DEBUG and above | | ||
| | `logLevels.info` | INFO and above | | ||
| | `logLevels.warning` | WARN and above | | ||
| | `logLevels.error` | ERROR only | | ||
|
|
||
| The `trace` level is only suitable for debugging and is usually very | ||
| noisy. We recommend gathering events from `info` and above in production | ||
| environments. | ||
|
|
||
| ## Event arguments | ||
|
|
||
| Each `'log'` event delivers four arguments: | ||
|
|
||
| | Argument | Type | Description | | ||
| | ------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | `level` | `string` | One of the level strings from the table above. | | ||
| | `target` | `string` | Identifies the source of the event. Either a class name (e.g. `"Client"`) or an internal module path (e.g. `"scylla::network::connection"`). | | ||
| | `message` | `string` | Human-readable description of the event. | | ||
| | `furtherInfo` | `string` | Additional structured context. Some events include key=value pairs from tracing spans (e.g. `peer_addr=10.0.0.1:9042`). May be an empty string. | | ||
adespawn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ### Event sources | ||
|
|
||
| Log events originate from two layers: | ||
|
|
||
| - **Internal driver** — connection, query routing, and protocol events from | ||
| the driver internals. These carry module paths in `target` | ||
| (e.g. `"scylla::network::connection"`). | ||
| - **Client** — high-level lifecycle events emitted by the `Client` class | ||
| (e.g. *"Connecting to cluster"*). These carry `"Client"` as the `target`. | ||
|
|
||
| Both kinds arrive through the same `'log'` event, so a single listener | ||
| receives everything. | ||
|
|
||
| ## Multiple clients | ||
|
|
||
| Each `Client` registers its own logging callback independently. Multiple | ||
| clients can coexist, each with its own `logLevel`. | ||
|
|
||
| > **WARNING:** all clients share the same underlying Rust tracing subscriber. | ||
| > This means every client receives log events from the entire process — | ||
| > including events triggered by other `Client` instances. Keep this in mind | ||
| > when filtering or routing events. | ||
|
|
||
| ## Example | ||
|
|
||
| ```js | ||
| const { Client, types } = require('scylladb-driver-alpha'); | ||
|
|
||
| const client = new Client({ | ||
| contactPoints: ['10.0.1.101', '10.0.1.102'], | ||
| logLevel: types.logLevels.info, | ||
| }); | ||
|
|
||
| client.on('log', (level, target, message, furtherInfo) => { | ||
| const extra = furtherInfo ? ` (${furtherInfo})` : ''; | ||
| console.log(`[${level}] ${target}: ${message}${extra}`); | ||
| }); | ||
|
|
||
| await client.connect(); | ||
| // [info] Client: Connecting to cluster using 'ScyllaDB JavaScript Driver' version ... | ||
| // [info] scylla::cluster::worker: Node added to cluster: ... | ||
| // ... | ||
|
|
||
| await client.shutdown(); | ||
| ``` | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.