Skip to content

refactor(log): replace withLogNameSuffix with actor-based AsyncLocalStorage#19959

Merged
PhilWindle merged 1 commit intonextfrom
palla/refactor-logging-actor-asynclocalstorage
Jan 28, 2026
Merged

refactor(log): replace withLogNameSuffix with actor-based AsyncLocalStorage#19959
PhilWindle merged 1 commit intonextfrom
palla/refactor-logging-actor-asynclocalstorage

Conversation

@spalladino
Copy link
Contributor

@spalladino spalladino commented Jan 27, 2026

Summary

  • Introduces logger bindings using AsyncLocalStorage for cleaner log output
  • Components created within a withLoggerBindings() callback automatically inherit the labels
  • Bindings include actor (eg node-0, prover-1), only set in tests, and instanceId (eg epoch-1)
  • Both are displayed as a separate field in logs rather than appended to module name
  • Browser-safe: AsyncLocalStorage code is isolated in a separate file not exported to browser bundles
  • Module, actor, and instance are colored in pretty-printed logs so logs from the same actor have the same color
image

Expected log format: validator-1 checkpoint-builder checkpoint-5 Building block 1...
Old format: checkpoint-builder:validator-1 Building block 1...

API

// Server-side only (not in browser bundles)
import { withLoggerBindings } from '@aztec/foundation/log/server';

await withLoggerBindings({ actor: 'validator-1' }, async () => {
  // Components created here inherit the bindings
  const node = await AztecNodeService.createAndSync(...);
});

// Loggers expose getBindings() to pass context to child components
const childLogger = createLogger('child-module', parentLogger.getBindings());

🤖 Generated with Claude Code

@spalladino spalladino force-pushed the palla/refactor-logging-actor-asynclocalstorage branch 7 times, most recently from 03ba496 to d7c36dd Compare January 27, 2026 16:50
@AztecBot
Copy link
Collaborator

AztecBot commented Jan 27, 2026

Flakey Tests

🤖 says: This CI run detected 2 tests that failed, but were tolerated due to a .test_patterns.yml entry.

\033FLAKED\033 (8;;http://ci.aztec-labs.com/f03dcae20c056817�f03dcae20c0568178;;�): yarn-project/scripts/run_test.sh p2p/src/client/test/tx_proposal_collector/p2p_client.proposal_tx_collector_bench.test.ts (92s) (code: 1) group:e2e-p2p-epoch-flakes (\033PhilWindle\033: refactor(log): replace withLogNameSuffix with actor-based AsyncLocalStorage (#19959))
\033FLAKED\033 (8;;http://ci.aztec-labs.com/6e900b1b5bc8c7cb�6e900b1b5bc8c7cb8;;�):  yarn-project/end-to-end/scripts/run_test.sh simple src/e2e_p2p/valid_epoch_pruned_slash.test.ts (404s) (code: 1) group:e2e-p2p-epoch-flakes (\033PhilWindle\033: refactor(log): replace withLogNameSuffix with actor-based AsyncLocalStorage (#19959))

@spalladino spalladino force-pushed the palla/refactor-logging-actor-asynclocalstorage branch from d7c36dd to c81735f Compare January 28, 2026 02:10
@@ -33,7 +33,7 @@ export async function startAnvil(
const anvil = createAnvil({
anvilBinary,
host: '127.0.0.1',
port: opts.port ?? 8545,
port: opts.port ?? (process.env.ANVIL_PORT ? parseInt(process.env.ANVIL_PORT) : 8545),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated to this PR, but helps in running multiple e2e tests locally without docker isolation

Comment on lines +10 to +12
if (!parseBooleanEnv(process.env.LOG_JSON)) {
overwriteLoggingStream(pretty(pinoPrettyOpts));
}
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 there was no way to have jest log as structured JSON

…torage

Introduces a new actor system using AsyncLocalStorage for cleaner log output.
Components created within a withBindings() callback automatically inherit the
actor label in their logs, displayed as a separate field rather than appended
to the module name.

Key changes:
- Add LoggerBindings type with actor and instanceId fields
- Create pino-logger-server.ts with withBindings/getBindings using AsyncLocalStorage
- Export server utilities from @aztec/foundation/log/server (not main export)
- Keep pino-logger.ts browser-safe (no node:async_hooks import)
- Update createLogger() to accept optional bindings
- Update pretty print format to show: {actor} {module} {instanceId} {msg}
- Deprecate withLogNameSuffix() in favor of withBindings()
- Add actor option to PXECreationOptions (deprecate useLogSuffix)
- Move module-level loggers to class instances in checkpoint_builder.ts
- Add instanceId to epoch-proving-job logger using job UUID
- Wrap main node/PXE creation with withBindings({ actor: 'MAIN' }) in e2e setup

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@spalladino spalladino force-pushed the palla/refactor-logging-actor-asynclocalstorage branch from c81735f to 7f82caf Compare January 28, 2026 13:03
@PhilWindle PhilWindle added this pull request to the merge queue Jan 28, 2026
Merged via the queue into next with commit b9f7f37 Jan 28, 2026
18 checks passed
@PhilWindle PhilWindle deleted the palla/refactor-logging-actor-asynclocalstorage branch January 28, 2026 16:28
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.

3 participants