Skip to content

Conversation

@jaipaljadeja
Copy link
Member

No description provided.

@jaipaljadeja jaipaljadeja requested a review from fracek March 17, 2025 14:26
@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2025

📝 Walkthrough

Walkthrough

This pull request introduces instrumentation support into the apibara package. A new JSON release configuration file marks the change as a prerelease patch with instrumentation side effects. New functions for instrumentation—register and logger—are added in a CLI utility file. An instrumentation plugin is implemented and integrated into the Rolldown configuration. Additionally, runtime modifications allow the custom instrumentation logger to override the default reporter, and relevant type definitions have been updated accordingly.

Changes

File(s) Change Summary
change/...apibara-d61e7e81-39c1-43c0-99cd-cfac39828cbe.json New JSON config specifying a prerelease patch and instrumentation comment for the "apibara" package.
examples/cli/instrumentation.ts Added CLI file exporting async register() and logger() functions for side-effect instrumentation and logger creation.
packages/cli/src/rolldown/config.ts
packages/cli/src/rolldown/plugins/instrumentation.ts
Integrated an instrumentation plugin by importing and pushing it into the Rolldown plugins array; the plugin conditionally loads an instrumentation file and exports its functions.
packages/cli/src/runtime/internal/app.ts
packages/cli/src/runtime/start.ts
Updated runtime: converted reporter variable to mutable, imported and integrated instrumentationLogger in app initialization, and conditionally executed register() during startup.
packages/cli/src/types/config.ts
packages/cli/src/types/virtual/instrumentation.d.ts
Revised type declarations: introduced new RegisterFn type, removed LoggerFactory and associated properties, and declared virtual instrumentation exports.

Possibly related PRs

Suggested reviewers

  • fracek

Poem

I’m a rabbit, hopping through code with glee,
Instrumentation added, as neat as can be.
Logs now dance in a custom display,
Registering side effects along the way.
With each clever line, my heart does skip,
A hoppy celebration on every trip!
🐇🎉

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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)
examples/cli/instrumentation.ts (1)

8-16: Logger factory implementation demonstrates good customization

The logger implementation correctly demonstrates how to customize the default logger. The example of prefixing the indexer name with "cli-" shows a simple but effective customization pattern.

However, consider adding more documentation about the parameters received by the LoggerFactoryFn (indexer, indexers, preset) to help users understand what values they can expect.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5453149 and 473c6d9.

📒 Files selected for processing (8)
  • change/apibara-d61e7e81-39c1-43c0-99cd-cfac39828cbe.json (1 hunks)
  • examples/cli/instrumentation.ts (1 hunks)
  • packages/cli/src/rolldown/config.ts (2 hunks)
  • packages/cli/src/rolldown/plugins/instrumentation.ts (1 hunks)
  • packages/cli/src/runtime/internal/app.ts (2 hunks)
  • packages/cli/src/runtime/start.ts (2 hunks)
  • packages/cli/src/types/config.ts (1 hunks)
  • packages/cli/src/types/virtual/instrumentation.d.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (16)
packages/cli/src/types/virtual/instrumentation.d.ts (1)

1-4: Type declarations established correctly for instrumentation module

This is a well-structured declaration file for a virtual module that will provide instrumentation capabilities. The types are correctly imported from "apibara/types" and the exports are properly typed with appropriate fallbacks to undefined.

change/apibara-d61e7e81-39c1-43c0-99cd-cfac39828cbe.json (1)

1-7: Change file correctly configured for prerelease

The change file is properly formatted and includes all required fields. The feature is accurately described as adding instrumentation for side effects, and the change type is appropriately set as a prerelease with a patch-level dependent change.

packages/cli/src/rolldown/config.ts (2)

15-15: Import statement correctly added

The instrumentation plugin is properly imported from the relative path.


91-91: Instrumentation plugin correctly integrated

The instrumentation plugin is properly added to the Rolldown configuration. The placement before other plugins is appropriate since instrumentation should typically be set up early in the build process.

examples/cli/instrumentation.ts (1)

1-7: Register function implementation provides good extensibility

The register function is correctly typed as RegisterFn and implemented as an async function, which is appropriate for potentially asynchronous instrumentation setup tasks. The comment about registering side effects like OpenTelemetry or Sentry provides good guidance for users.

packages/cli/src/runtime/start.ts (2)

5-5: Added instrumentation import

This import brings in the instrumentation registration function which will be used during startup.


38-42: Good implementation of instrumentation registration

The code correctly checks if the register function exists before attempting to use it, making this implementation optional and preventing potential runtime errors. The logging statements provide good visibility into the registration process.

packages/cli/src/runtime/internal/app.ts (3)

14-14: Added instrumentation logger import

This import brings in the custom logger from the instrumentation module.


60-60: Changed reporter declaration from const to let

This change allows the reporter to be reassigned if a custom logger is provided through instrumentation.


66-79: Well-implemented custom logger integration

The implementation correctly:

  1. Checks if a custom logger is provided
  2. Creates a reporter using the custom logger with appropriate parameters
  3. Validates that the reporter has a log method before using it
  4. Falls back to the default logger if needed

This ensures that custom logging can be injected while maintaining backward compatibility.

packages/cli/src/types/config.ts (2)

14-15: Added RegisterFn type definition

This type properly defines the instrumentation registration function as returning a Promise, ensuring it can handle asynchronous operations.


16-19: Updated logger type definition

The new LoggerFactoryFn type properly defines the function signature for creating custom loggers with the expected parameters.

packages/cli/src/rolldown/plugins/instrumentation.ts (4)

1-12: Well-structured plugin imports and instrumentation path resolution

The implementation correctly:

  1. Imports necessary modules
  2. Determines the instrumentation file path based on the current working directory
  3. Handles both TypeScript and JavaScript file extensions

This ensures the instrumentation file can be found regardless of the project's language choice.


13-22: Good handling of missing instrumentation file

The code gracefully handles the case when no instrumentation file exists by providing undefined values for register and logger functions. This ensures the application works correctly even without custom instrumentation.


24-45: Well-documented approach to avoid rolldown warnings

The comments thoroughly explain the reasoning behind using require instead of import, providing examples of the warnings that would otherwise occur. This helps maintainers understand the implementation decision.


46-68: Robust implementation of instrumentation module loading

The implementation:

  1. Creates a virtual module with proper exports
  2. Uses a try/catch block to handle potential errors during require
  3. Validates that the imported functions are actually functions before using them
  4. Silently handles errors to prevent application crashes

This ensures that the instrumentation functionality is robust and fault-tolerant.

Copy link
Contributor

@fracek fracek left a comment

Choose a reason for hiding this comment

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

Looks good and I'm surprised it was so little code! Only one tiny detail and it's ready.

Copy link

@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

🔭 Outside diff range comments (1)
packages/cli/src/types/config.ts (1)

28-104: 💡 Verification agent

🧩 Analysis chain

Verify the logger property removal impact.

The removal of the logger property from both ApibaraConfig and ApibaraOptions interfaces suggests a restructuring of the logging functionality. Please ensure that existing code using these interfaces is updated appropriately.


🏁 Script executed:

#!/bin/bash
# Search for any usage of the removed logger property in the codebase
echo "Searching for usages of the 'logger' property in configurations..."
rg -t ts "(ApibaraConfig|ApibaraOptions).*\{[^}]*logger[^}]*\}" --glob "!**/node_modules/**" --glob "!**/dist/**"

echo "Searching for direct access to the logger property..."
rg -t ts "\.(logger)\b" --glob "!**/node_modules/**" --glob "!**/dist/**"

Length of output: 2957


Action Required: Update Logger Usage Across the Codebase

The removal of the logger property from the ApibaraConfig and ApibaraOptions interfaces now leaves several files still invoking methods on apibara.logger. Please update these references to align with the new logging architecture. Notable files with remaining logger usages include:

  • packages/cli/src/cli/commands/start.ts

    • Calls to apibara.logger.start and apibara.logger.error.
  • packages/rolldown/plugins/instrumentation.ts

    • Checks and assignments involving instrumentation.logger.
  • packages/cli/src/core/scan.ts

    • apibara.logger.debug invocations.
  • packages/cli/src/core/build/prod.ts

    • Multiple calls: apibara.logger.start, apibara.logger.success, apibara.logger.info, and apibara.logger.error.
  • packages/cli/src/cli/commands/dev.ts

    • Various diagnostics using apibara.logger.
  • Additional references in files such as

    • packages/cli/src/core/config/update.ts
    • packages/cli/src/core/build/dev.ts
    • packages/cli/src/core/build/build.ts
    • packages/indexer/src/plugins/logger.ts
    • packages/cli/src/core/build/prepare.ts

Please review and refactor these areas to either remove direct logger calls, use an updated logging mechanism, or ensure the new logger is injected appropriately.

🧹 Nitpick comments (1)
packages/cli/src/types/config.ts (1)

14-26: Consider adding JSDoc comments for the new types.

The newly added types would benefit from JSDoc comments explaining their purpose and usage, especially since they're part of a new instrumentation feature.

+/**
+ * Function type for registering instrumentation side effects
+ */
 export type RegisterFn = () => Promise<void>;

+/**
+ * Function type for creating a custom console reporter based on indexer configuration
+ */
 export type LoggerFactoryFn = ({
   indexer,
   indexers,
   preset,
 }: LoggerFactoryArgs) => ConsolaReporter;

+/**
+ * Arguments passed to the logger factory function
+ */
 export type LoggerFactoryArgs = {
   indexer: string;
   indexers: string[];
   preset?: string;
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 473c6d9 and d7249b9.

📒 Files selected for processing (1)
  • packages/cli/src/types/config.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (3)
packages/cli/src/types/config.ts (3)

14-15: New type for instrumentation registration looks good.

The added RegisterFn type properly defines a function signature for registering side effects as mentioned in the PR objectives, returning a Promise.


16-20: Type renaming and structure improvement looks good.

The rename from LoggerFactory to LoggerFactoryFn better indicates its purpose as a function. The type now properly references the new LoggerFactoryArgs type, improving the code organization.


22-26: Properly implemented the suggested type for logger factory arguments.

You've addressed fracek's feedback by creating a dedicated LoggerFactoryArgs type for the parameters, making the code more maintainable and easier to extend in the future.

@fracek fracek merged commit 84b5952 into apibara:main Mar 17, 2025
2 checks passed
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