Skip to content

refactor: standardize logging format#20

Open
standujar wants to merge 4 commits into1.xfrom
feat/standardized-logging
Open

refactor: standardize logging format#20
standujar wants to merge 4 commits into1.xfrom
feat/standardized-logging

Conversation

@standujar
Copy link
Copy Markdown

@standujar standujar commented Nov 26, 2025

Prior merge of: elizaOS/eliza#6169

Summary

  • Standardize all logs to structured format as eliza monorepo
  • Add ESLint with @elizaos/structured-logging rule
  • Add lint:check script for CI

Test plan

  • Build passes

Summary by CodeRabbit

  • New Features

    • Added configuration options for image, image-generation, and embedding models: IMAGE_MODEL, IMAGE_GENERATION_MODEL, EMBEDDING_MODEL, EMBEDDING_DIMENSIONS.
  • Refactor

    • Standardized and enriched structured runtime logging across text, image, embedding, and object flows for improved diagnostics and observability.
    • Several internal helper and image-storage APIs now accept runtime context to enable contextual logging.
  • Chores

    • Version bumped to 1.5.16; added ESLint configuration and updated lint scripts.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 26, 2025

Walkthrough

Adds an ESLint config and lint devDependencies, exposes four new model-related config options, converts many logs to structured runtime.logger calls with contextual metadata, updates several helper and image-storage function signatures to accept a runtime context, and normalizes string quotes across the codebase.

Changes

Cohort / File(s) Summary
Build & Tooling
eslint.config.js, package.json
New eslint.config.js re-exports plugin config. package.json bumped to 1.5.16; added ESLint/TypeScript devDependencies and updated lint / lint:check scripts.
Public API / Config
src/index.ts
Added config options IMAGE_MODEL, IMAGE_GENERATION_MODEL, EMBEDDING_MODEL, EMBEDDING_DIMENSIONS; standardized import/quote formatting.
Initialization
src/init.ts
Switched plain logs to structured runtime.logger calls (includes src, agentId, status); adjusted messages for missing/invalid API key and init flow.
Models
src/models/embedding.ts, src/models/image.ts, src/models/object.ts, src/models/text.ts, src/models/index.ts
Converted to structured, contextual logging (debug/error) with metadata; normalized quotes; updated calls to helpers/storage to pass runtime. Signature changes propagated where required.
Types & Config Utilities
src/types/index.ts, src/utils/config.ts
Quote normalization and minor formatting; literal "tool-call" used; getters and key lookups preserved behavior.
Helpers, Events & Storage
src/utils/events.ts, src/utils/helpers.ts, src/utils/image-storage.ts
Introduced runtime: IAgentRuntime to many helper/storage functions and replaced global logs with runtime.logger structured logs. New/updated signatures include getJsonRepairFunction(runtime), logResponseStructure(runtime, ...), handleEmptyToolResponse(runtime, ...), parseImageDescriptionResponse(runtime, ...), handleObjectGenerationError(runtime, ...), decodeBase64Fields(runtime, ...), saveBase64Image(runtime, ...), and deleteImage(runtime, ...). events.ts only formatting changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Areas needing extra attention:
    • src/utils/helpers.ts — many new runtime parameters, JSON repair logic, and logging changes.
    • src/utils/image-storage.ts — signature changes for save/delete and updated import (IAgentRuntime).
    • src/models/image.ts, src/models/object.ts, src/models/text.ts — verify all helper/storage call sites pass the new runtime arg and handle errors.
    • src/models/embedding.ts — verify embedding dimension checks and logging consistency.
    • package.json & eslint.config.js — ensure lint scripts and new ESLint config align with project constraints.

Poem

🐇 I hopped through logs both neat and new,

I added runtime whispers to each view,
Images, vectors, configs in a row,
ESLint watches as my tidy footprints show,
A rabbit smiles — the code can go.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the changeset: refactoring and standardizing logging format across the codebase with structured logging patterns.
Docstring Coverage ✅ Passed Docstring coverage is 96.15% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/standardized-logging

Tip

✨ Issue Enrichment is now available for GitHub issues!

CodeRabbit can now help you manage issues more effectively:

  • Duplicate Detection — Identify similar or duplicate issues
  • Related Issues & PRs — Find relevant issues and PR's from your repository
  • Suggested Assignees — Find the best person to work on the issue
  • Implementation Planning — Generate detailed coding plans for engineers and agents
Disable automatic issue enrichment

To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

issue_enrichment:
  auto_enrich:
    enabled: false

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
package.json (1)

3-3: Lint tooling and config metadata look solid; consider CI integration

The version bump, new devDependencies, and lint/lint:check scripts are consistent with the new shared ESLint config. The additional IMAGE/EMBEDDING-related agentConfig entries are coherent and well documented. As a follow‑up, it’d be good to wire lint:check into CI if it isn’t already, so structured-logging rules are enforced automatically.

Also applies to: 35-45, 49-50, 116-178

src/init.ts (1)

32-45: Consistent structured logging for validation and error paths

The validation success/failure, fetch error, and outer configuration error branches now all emit structured logs with src, agentId, and relevant details (status, statusText, error). This should make diagnosing OpenRouter configuration issues much easier. If you touch this again, you might consider factoring a small helper for the repeated { src: "plugin:openrouter", agentId: runtime.agentId } context, but it’s not required.

Also applies to: 51-57, 66-68

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between c94bb7e and 2f1acd6.

📒 Files selected for processing (14)
  • eslint.config.js (1 hunks)
  • package.json (2 hunks)
  • src/index.ts (3 hunks)
  • src/init.ts (3 hunks)
  • src/models/embedding.ts (4 hunks)
  • src/models/image.ts (6 hunks)
  • src/models/index.ts (1 hunks)
  • src/models/object.ts (1 hunks)
  • src/models/text.ts (4 hunks)
  • src/types/index.ts (1 hunks)
  • src/utils/config.ts (11 hunks)
  • src/utils/events.ts (1 hunks)
  • src/utils/helpers.ts (6 hunks)
  • src/utils/image-storage.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/models/text.ts (1)
src/utils/helpers.ts (1)
  • decodeBase64Fields (180-210)
src/index.ts (3)
src/models/text.ts (1)
  • handleTextLarge (170-178)
src/models/object.ts (2)
  • handleObjectSmall (65-70)
  • handleObjectLarge (75-80)
src/models/image.ts (2)
  • handleImageDescription (23-88)
  • handleImageGeneration (93-220)
src/models/embedding.ts (2)
src/models/index.ts (1)
  • handleTextEmbedding (4-4)
src/utils/config.ts (4)
  • getEmbeddingModel (117-123)
  • getSetting (10-16)
  • getApiKey (47-49)
  • getBaseURL (23-39)
🔇 Additional comments (13)
src/utils/events.ts (1)

25-30: Numeric coercion remains safe and clear

Token coercion still handles missing values and defaults cleanly; this is a no-op refactor with consistent style.

eslint.config.js (1)

1-3: ESLint config wiring looks correct

Re-exporting the shared pluginConfig keeps linting consistent with the monorepo and is idiomatic for flat configs.

src/types/index.ts (1)

28-28: Type literal change is purely stylistic

Switching to double quotes for "tool-call" keeps the literal identical at the type level; no behavior or typing impact.

src/init.ts (1)

20-23: Missing-key log now structured and clear

The warning for absent OPENROUTER_API_KEY cleanly adds src and agentId context while keeping the message concise; no behavior change.

src/models/object.ts (1)

32-40: Structured model-selection log is a nice improvement

Logging { src: "plugin:openrouter:model:object", agentId, modelType, model } at debug level before generation gives clear, structured insight into which model is used without changing behavior. This fits well with the standardized logging approach.

src/models/index.ts (1)

1-4: Exports remain unchanged; style is consistent

Re-exports for the model handlers are intact; only quote style is adjusted for consistency.

src/utils/image-storage.ts (1)

104-105: Image storage logs now structured and consistent

The success and failure logs for saving and deleting images now include src and filepath (and error where relevant) as structured fields, with debug for normal operations and warn for failures. This aligns nicely with the standardized logging pattern across the plugin.

Also applies to: 122-134

src/models/image.ts (1)

30-37: LGTM! Consistent structured logging implementation.

The structured logging changes are well-implemented with consistent metadata fields (src, agentId) and relevant context for each log event. The messages are concise and descriptive.

Also applies to: 75-82, 98-105, 157-164, 174-181, 199-206, 210-217

src/models/text.ts (1)

43-51: LGTM! Well-structured logging for text generation.

The structured logging changes provide good context for debugging text generation and tool execution. The metadata fields are consistent with the project-wide pattern.

Also applies to: 71-78

src/models/embedding.ts (1)

26-40: LGTM! Comprehensive structured logging for embedding workflow.

The structured logging changes provide excellent diagnostic coverage for all embedding workflow paths, including error cases, edge cases, and success scenarios. The metadata fields consistently include src and agentId, with relevant additional context for each situation.

Also applies to: 42-54, 62-65, 71-79, 82-88, 107-120, 127-133, 137-150, 162-170, 172-182

src/index.ts (1)

39-42: LGTM! New configuration options properly integrated.

The new config options (IMAGE_MODEL, IMAGE_GENERATION_MODEL, EMBEDDING_MODEL, EMBEDDING_DIMENSIONS) are correctly added and properly used as fallback values in the config utility functions.

src/utils/config.ts (1)

1-157: LGTM! Consistent quote style formatting.

All changes are purely cosmetic, standardizing string literals to use double quotes throughout the file. No functional changes.

src/utils/helpers.ts (1)

23-26: LGTM! Comprehensive structured logging for helper utilities.

The structured logging changes provide excellent diagnostic coverage across all helper functions, including JSON repair, response structure analysis, tool execution fallbacks, and base64 decoding. The metadata and messages are well-chosen for debugging.

Also applies to: 52-64, 71-75, 92-95, 115-118, 128-131, 138-141, 146-146, 151-154, 192-195, 197-200

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 2f1acd6 and c293816.

📒 Files selected for processing (1)
  • eslint.config.js (1 hunks)
🔇 Additional comments (2)
eslint.config.js (2)

10-10: LGTM!

The re-export pattern is clean and aligns with the PR objective of adopting standardized ElizaOS configuration.


1-1: The import path is valid and correctly references the @elizaos/config package.

The import statement import pluginConfig from "@elizaos/config/eslint/eslint.config.plugin.js"; matches the documented export from the @elizaos/config package (version ^1.6.5). This is the standard way to import the ESLint plugin configuration from this package, as confirmed by package documentation.

Comment thread eslint.config.js
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/utils/helpers.ts (1)

184-214: Critical: Missing runtime parameter in recursive calls.

The decodeBase64Fields signature was updated to accept runtime as the first parameter, but the recursive calls on lines 189 and 208 don't pass the runtime parameter. This will cause runtime errors.

Apply this diff:

   if (Array.isArray(obj))
-    return obj.map((item) => decodeBase64Fields(item, depth + 1));
+    return obj.map((item) => decodeBase64Fields(runtime, item, depth + 1));
     } else if (value && typeof value === "object") {
-      decoded[key] = decodeBase64Fields(value, depth + 1);
+      decoded[key] = decodeBase64Fields(runtime, value, depth + 1);
     } else {
🧹 Nitpick comments (3)
src/utils/image-storage.ts (1)

105-135: Inconsistent quote style for src field.

This file uses single quotes ('plugin:openrouter') while src/init.ts uses double quotes ("plugin:openrouter"). Consider standardizing to match the rest of the codebase.

Apply this diff to use double quotes consistently:

-  runtime.logger.debug({ src: 'plugin:openrouter', agentId: runtime.agentId, filepath }, "Saved generated image");
+  runtime.logger.debug({ src: "plugin:openrouter", agentId: runtime.agentId, filepath }, "Saved generated image");
-        runtime.logger.debug({ src: 'plugin:openrouter', agentId: runtime.agentId, filepath }, "Deleted image");
+        runtime.logger.debug({ src: "plugin:openrouter", agentId: runtime.agentId, filepath }, "Deleted image");
-      runtime.logger.warn(
-        { src: 'plugin:openrouter', agentId: runtime.agentId, filepath, error: String(error) },
-        "Failed to delete image",
-      );
+      runtime.logger.warn(
+        { src: "plugin:openrouter", agentId: runtime.agentId, filepath, error: String(error) },
+        "Failed to delete image",
+      );
-    runtime.logger.warn(
-      { src: 'plugin:openrouter', agentId: runtime.agentId, filepath, error: String(error) },
-      "Failed to delete image",
-    );
+    runtime.logger.warn(
+      { src: "plugin:openrouter", agentId: runtime.agentId, filepath, error: String(error) },
+      "Failed to delete image",
+    );
src/utils/helpers.ts (2)

146-146: Add braces for consistency.

ESLint is flagging the missing braces after the if condition. While this is valid JavaScript, adding braces improves consistency and prevents potential bugs if the code is modified later.

Apply this diff:

-        if (repairParseError instanceof Error) throw repairParseError;
+        if (repairParseError instanceof Error) {
+          throw repairParseError;
+        }

159-159: Add braces for consistency.

Same issue as line 146 - add braces after the if condition.

Apply this diff:

-    if (error instanceof Error) throw error;
+    if (error instanceof Error) {
+      throw error;
+    }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between c293816 and d66053e.

📒 Files selected for processing (7)
  • package.json (2 hunks)
  • src/init.ts (4 hunks)
  • src/models/image.ts (7 hunks)
  • src/models/object.ts (2 hunks)
  • src/models/text.ts (5 hunks)
  • src/utils/helpers.ts (9 hunks)
  • src/utils/image-storage.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • package.json
  • src/models/text.ts
  • src/models/image.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/models/object.ts (2)
src/utils/helpers.ts (3)
  • getJsonRepairFunction (8-30)
  • emitModelUsageEvent (33-33)
  • handleObjectGenerationError (114-162)
src/utils/events.ts (1)
  • emitModelUsageEvent (11-44)
🪛 ESLint
src/utils/helpers.ts

[error] 146-146: Expected { after 'if' condition.

(curly)

🔇 Additional comments (7)
src/init.ts (1)

20-68: LGTM! Structured logging implemented consistently.

All logging statements have been successfully converted to structured format with appropriate context (src, agentId) and additional fields where relevant. The log levels and messages are appropriate for each scenario.

src/utils/image-storage.ts (2)

51-56: Breaking change: Runtime parameter added to public API.

The function signature now requires runtime as the first parameter to enable structured logging. Ensure all callers have been updated accordingly.


114-114: Breaking change: Runtime parameter added.

Consistent with the broader refactor. Ensure callers have been updated.

src/models/object.ts (1)

50-58: LGTM! Helper function calls updated correctly.

Both getJsonRepairFunction and handleObjectGenerationError now correctly receive the runtime parameter, aligning with their updated signatures.

src/utils/helpers.ts (3)

8-30: LGTM! Function signature and logging updated correctly.

The runtime parameter enables structured logging. Note the single-quote style for 'plugin:openrouter' is inconsistent with src/init.ts (which uses double quotes), but this is a minor style issue.


38-67: LGTM! Response logging refactored to structured format.

The function now accepts runtime and uses structured logging with comprehensive context fields for debugging.


72-78: LGTM! Tool response handler updated.

Function signature and logging correctly updated to use structured format.

Comment thread src/models/object.ts Outdated
Comment thread src/models/object.ts Outdated
Comment thread eslint.config.js Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/models/object.ts (1)

3-3: Remove unused logger import.

The global logger import is no longer used since the code now uses runtime.logger for structured logging. This import should be removed to keep the code clean.

Apply this diff:

 import {
   ModelType,
-  logger,
   type IAgentRuntime,
   type ObjectGenerationParams,
 } from "@elizaos/core";
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between d66053e and f58acad.

📒 Files selected for processing (2)
  • eslint.config.js (1 hunks)
  • src/models/object.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/models/object.ts (2)
src/utils/helpers.ts (3)
  • getJsonRepairFunction (8-30)
  • emitModelUsageEvent (33-33)
  • handleObjectGenerationError (114-162)
src/utils/events.ts (1)
  • emitModelUsageEvent (11-44)
🔇 Additional comments (4)
eslint.config.js (1)

1-10: ESLint wrapper config looks correct and consistent with monorepo setup

Import/export wiring is straightforward, the header comment now correctly names plugin-openrouter, and delegating to the shared plugin config keeps rules centralized. No changes needed.

src/models/object.ts (3)

32-40: Well done! Structured logging correctly implemented.

The logging now uses runtime.logger.debug with appropriate structured metadata (src, agentId, modelType, model). This aligns perfectly with the PR objectives and addresses the previous review feedback.


50-50: Correct update to helper function signature.

The call to getJsonRepairFunction(runtime) correctly matches the updated signature in src/utils/helpers.ts, which now requires a runtime parameter for structured logging.


58-58: Correct update to error handler signature.

The call to handleObjectGenerationError(runtime, error) correctly matches the updated signature in src/utils/helpers.ts, which now requires runtime as the first parameter for structured error logging.

Copy link
Copy Markdown

@0xbbjoker 0xbbjoker left a comment

Choose a reason for hiding this comment

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

LGTM

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.

2 participants