Skip to content

feat: add structured logging with request tracing#70

Open
rollroyces wants to merge 1 commit into
OpenBMB:mainfrom
rollroyces:feat/structured-logging
Open

feat: add structured logging with request tracing#70
rollroyces wants to merge 1 commit into
OpenBMB:mainfrom
rollroyces:feat/structured-logging

Conversation

@rollroyces
Copy link
Copy Markdown

Summary

Adds structured logging infrastructure to PilotDeck, replacing ad-hoc console.log/warn/error calls with a proper logger.

New Module: src/pilot/logger.ts

  • Log levels: DEBUG, INFO, WARN, ERROR with global level control
  • Module-scoped loggers: createLogger('module-name') for provenance
  • Structured entries: timestamp, level, module, message, optional data/error fields
  • Request ID tracing: AsyncLocalStorage-based withRequestId() for correlating log entries across async boundaries

Files Modified (8 critical paths)

File Change
src/router/RouterRuntime.ts Decision logs, model gate override, zeroUsageRetry
src/cli/pilotdeck.ts Always-on and cron subsystem logging
src/router/tokenSaver/classifyAndRoute.ts Tier routing and judge failures
src/model/providers/openai/stream.ts Provider errors and body parsing failures
src/model/providers/anthropic/stream.ts Provider errors and body parsing failures
src/model/streaming/assembleModelMessage.ts Tool call fallback extraction
src/model/streaming/streamModel.ts Request dump debugging
src/adapters/channel/loadEnabledChannels.ts Channel loading errors

Usage

import { createLogger, withRequestId } from '../pilot/logger.js';

const log = createLogger('my-module');
log.info('Processing request', { userId, action });
log.warn('Rate limit approaching', { current, limit });
log.error('Operation failed', error, { context });

// Request tracing
withRequestId(requestId, () => {
  // All log entries in this scope include requestId
  log.info('Handling request');
});

Impact

  • Production-grade observability for debugging distributed agent interactions
  • Request ID tracing enables log correlation across async boundaries
  • Backward compatible — existing console output format preserved

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.

1 participant