Skip to content

Feat/logtail pino #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open

Feat/logtail pino #427

wants to merge 5 commits into from

Conversation

mani99brar
Copy link
Contributor

@mani99brar mani99brar commented Jun 18, 2025

PR-Codex overview

This PR introduces monitoring capabilities by adding heartbeat signals and logging enhancements. It updates environment variable management and includes new dependencies for logging.

Detailed summary

  • Added LOGTAIL_TOKEN and HEARTBEAT_URL to .env.dist files.
  • Introduced sendHeartbeat function in relayer-cli/src/watcher.ts and relayer-cli/src/relayer.ts.
  • Updated logging to use pino in logger.ts files.
  • Enhanced error handling for heartbeat requests.
  • Added @logtail/pino and pino-pretty dependencies in package.json files.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added support for sending heartbeat signals to a monitoring service, improving observability of relayer and validator operations.
    • Introduced optional environment variables for monitoring and logging integration (LOGTAIL_TOKEN, HEARTBEAT_URL).
  • Refactor

    • Replaced direct console logging with structured logging using the pino library, with optional Logtail integration for advanced log management.
    • Centralized environment variable handling for improved configuration management.
  • Chores

    • Updated dependencies to include logging and monitoring packages.

Copy link
Contributor

coderabbitai bot commented Jun 18, 2025

Walkthrough

The changes introduce structured logging and heartbeat monitoring to both the relayer and validator CLI tools. New environment variables (LOGTAIL_TOKEN, HEARTBEAT_URL) are added for external logging and monitoring integration. Logging is refactored to use the pino library, optionally with Logtail transport, and heartbeat signals are sent periodically via HTTPS requests.

Changes

File(s) Change Summary
relayer-cli/.env.dist, validator-cli/.env.dist Added LOGTAIL_TOKEN and HEARTBEAT_URL environment variables for monitoring/logging.
relayer-cli/package.json, validator-cli/package.json Added dependencies: @logtail/pino, pino, and devDependency pino-pretty.
relayer-cli/src/utils/env.ts, validator-cli/src/utils/env.ts Introduced env utility with require and optional methods for environment variable access.
relayer-cli/src/utils/logger.ts, validator-cli/src/utils/logger.ts Refactored logging to use pino logger, with Logtail integration if configured; replaced direct console logging.
relayer-cli/src/relayer.ts Added sendHeartbeat function; integrated heartbeat calls at startup, periodically, and on shutdown.
validator-cli/src/watcher.ts Added sendHeartbeat function; integrated heartbeat calls at startup, before each network process, and shutdown.

Sequence Diagram(s)

Heartbeat Integration (Relayer/Validator)

sequenceDiagram
    participant CLI
    participant Env
    participant Logger
    participant MonitoringService

    CLI->>Env: Load HEARTBEAT_URL
    CLI->>Logger: Initialize logger (with LOGTAIL_TOKEN if set)
    CLI->>MonitoringService: sendHeartbeat() at startup
    loop Main Loop
        CLI->>MonitoringService: sendHeartbeat() periodically
        CLI->>Logger: Log events
    end
    CLI->>MonitoringService: sendHeartbeat() at shutdown
Loading

Poem

Hopping through logs, a bunny does cheer,
With pino and Logtail, the messages are clear.
Heartbeats are sent, a thump in the night,
Monitoring and logging, both shining bright.
With every new hop, this code feels just right!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 68d799d and 6706826.

📒 Files selected for processing (2)
  • relayer-cli/src/relayer.ts (4 hunks)
  • validator-cli/src/watcher.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • validator-cli/src/watcher.ts
  • relayer-cli/src/relayer.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: dependency-review
  • GitHub Check: test
  • GitHub Check: Analyze (javascript)
✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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 or @coderabbitai title 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

netlify bot commented Jun 18, 2025

Deploy Preview for veascan ready!

Name Link
🔨 Latest commit 6706826
🔍 Latest deploy log https://app.netlify.com/projects/veascan/deploys/686bbf68d7a6070008de5277
😎 Deploy Preview https://deploy-preview-427--veascan.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

@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: 6

♻️ Duplicate comments (2)
validator-cli/src/utils/env.ts (1)

2-8: Keep logic consistent with relayer fix

If you accept the tightened value === undefined check in the relayer utility, mirror it here to prevent subtle behavioural differences between the two CLIs.

relayer-cli/src/utils/logger.ts (1)

17-36: Same dependency / env handling concerns

Replicate the fixes applied to the validator logger:

  • Move pino-pretty to runtime deps.
  • Fetch LOGTAIL_TOKEN via the env helper for consistency.
🧹 Nitpick comments (6)
relayer-cli/src/utils/env.ts (2)

2-8: Empty string is treated as “missing” – is that intentional?

if (!value) rejects an env var that is set but intentionally blank (e.g. VAR=""). If you only want to fail when the key is truly undefined, check value === undefined instead.

-    if (!value) {
+    if (value === undefined) {

1-13: Avoid copy-pasted utilities across packages

An identical env helper is introduced in two different packages. Duplicating code increases maintenance cost and the risk of divergence. Export a small shared package (e.g. @kleros/vea-env) or move the helper to the monorepo root and import it from both CLI tools.

validator-cli/.env.dist (1)

24-26: Order keys & keep sample files tidy

The linter warning is legit: place HEARTBEAT_URL before LOGTAIL_TOKEN to keep alphabetical order and minimise merge noise.

-LOGTAIL_TOKEN=
-HEARTBEAT_URL=
+HEARTBEAT_URL=
+LOGTAIL_TOKEN=
relayer-cli/.env.dist (1)

26-28: Alphabetical order & trailing newline

  1. Alphabetise: HEARTBEAT_URL should precede LOGTAIL_TOKEN.
  2. Add a trailing blank line to satisfy common linters and POSIX tools.
-LOGTAIL_TOKEN=
-HEARTBEAT_URL=
+HEARTBEAT_URL=
+LOGTAIL_TOKEN=
+
validator-cli/src/watcher.ts (1)

88-96: Tight loop may overload monitoring endpoint

sendHeartbeat() is called every loop iteration (≈ 10 s) per watched network.
If multiple networks are configured the frequency scales linearly and could breach rate-limits.
Consider extracting a single setInterval-based heartbeat or using a token-bucket.

validator-cli/src/utils/logger.ts (1)

19-40: Runtime dependency & env util consistency

  • pino-pretty is loaded via transport – ensure it’s under "dependencies" (see package.json comment).
  • Prefer env.optional("LOGTAIL_TOKEN") instead of reading process.env directly to keep all env look-ups centralised.
-const logtailToken = process.env.LOGTAIL_TOKEN;
+const logtailToken = env.optional("LOGTAIL_TOKEN");
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd7f009 and 68d799d.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (10)
  • relayer-cli/.env.dist (1 hunks)
  • relayer-cli/package.json (1 hunks)
  • relayer-cli/src/relayer.ts (4 hunks)
  • relayer-cli/src/utils/env.ts (1 hunks)
  • relayer-cli/src/utils/logger.ts (2 hunks)
  • validator-cli/.env.dist (1 hunks)
  • validator-cli/package.json (1 hunks)
  • validator-cli/src/utils/env.ts (1 hunks)
  • validator-cli/src/utils/logger.ts (3 hunks)
  • validator-cli/src/watcher.ts (3 hunks)
🧰 Additional context used
🪛 dotenv-linter (3.3.0)
relayer-cli/.env.dist

[warning] 24-24: [QuoteCharacter] The value has quote characters (', ")


[warning] 28-28: [EndingBlankLine] No blank line at the end of the file


[warning] 28-28: [UnorderedKey] The HEARTBEAT_URL key should go before the LOGTAIL_TOKEN key

validator-cli/.env.dist

[warning] 26-26: [UnorderedKey] The HEARTBEAT_URL key should go before the LOGTAIL_TOKEN key

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Redirect rules - veascan
  • GitHub Check: Header rules - veascan
  • GitHub Check: Pages changed - veascan
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Scorecard analysis
  • GitHub Check: test
  • GitHub Check: dependency-review

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 7, 2025
Copy link

sonarqubecloud bot commented Jul 7, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
55.4% Duplication on New Code (required ≤ 10%)

See analysis details on SonarQube Cloud

@mani99brar mani99brar marked this pull request as ready for review July 7, 2025 12:38
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