Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Dec 22, 2025

Summary

Adds a lightweight logging system for API inference requests/responses across all providers, helping with debugging and understanding what data is being sent to/received from LLM providers.

Implementation

  • Created ApiInferenceLogger singleton class in src/api/logging/ApiInferenceLogger.ts
  • Added inferenceLogger property to BaseProvider
  • Updated all providers to use the logger
  • Logger is configured in extension.ts with output channel as sink

Features

  • Logs request payloads (model, maxTokens, temperature, messageCount, etc.)
  • Logs response payloads (text, reasoning, tool calls, usage)
  • Payload sanitization:
    • Truncates long strings (>10k chars)
    • Caps arrays/objects (>200 items/keys)
    • Replaces base64 images with placeholders
    • Redacts secrets (apiKey, authorization, password, etc.)
  • Enable via ROO_CODE_API_LOGGING=true environment variable

Output Example

[API][request]
{
  "provider": "Roo Code Cloud",
  "operation": "createMessage",
  "model": "anthropic/claude-opus-4.5",
  "taskId": "...",
  "requestId": "req_...",
  "timestamp": "...",
  "payload": { ... }
}
[API][response]
{
  "provider": "Roo Code Cloud",
  "durationMs": 5669,
  "payload": { "text": "...", "usage": { ... } }
}

Inspired by

#10176 - simplified the approach to use a logging class integrated into the base provider

Closes ROO-271


Important

Introduces ApiInferenceLogger for logging API inference requests/responses, integrated into all providers and configurable via environment variable.

  • Behavior:
    • Adds ApiInferenceLogger singleton in ApiInferenceLogger.ts for logging API inference requests/responses.
    • Integrates logger into BaseProvider and updates all providers to use it.
    • Configures logger in extension.ts with output channel as sink.
  • Features:
    • Logs request payloads (model, maxTokens, temperature, etc.) and response payloads (text, reasoning, tool calls, usage).
    • Sanitizes payloads by truncating long strings, capping arrays/objects, replacing base64 images, and redacting secrets.
    • Enabled via ROO_CODE_API_LOGGING=true environment variable.
  • Misc:
    • Adds tests for ApiInferenceLogger in ApiInferenceLogger.spec.ts.
    • Updates provider classes like OpenAiHandler, OpenRouterHandler, and RooHandler to use the logger.

This description was created by Ellipsis for 331dc80. You can customize this summary. It will automatically update as commits are pushed.

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. Enhancement New feature or request labels Dec 22, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 22, 2025

Rooviewer Clock   See task on Roo Cloud

All issues have been resolved. LGTM!

  • anthropic.ts:382 - Replace confusing if (logHandle!) with standard if (logHandle) check
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

- Add ApiInferenceLogger singleton class for logging API requests/responses
- Add inferenceLogger property to BaseProvider
- Update all providers to use the logger
- Configure logger in extension.ts with output channel sink
- Add payload sanitization (truncate strings, cap arrays, redact secrets)
- Enable via ROO_CODE_API_LOGGING=true environment variable

Closes ROO-271
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 22, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Dec 22, 2025
@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request PR - Needs Review size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Status: PR [Needs Review]

Development

Successfully merging this pull request may close these issues.

3 participants