Skip to content

Conversation

@djwhitt
Copy link
Collaborator

@djwhitt djwhitt commented May 25, 2025

Summary

  • add new env helpers (string, stringOrUndefined, stringOrRandom, boolean, number, numberOrUndefined, csv, filter)
  • use new helpers throughout config, log and tracing
  • remove old helper names

Testing

  • yarn test (fails: command not found)

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 25, 2025

📝 Walkthrough

Walkthrough

The changes refactor environment variable access throughout the codebase by replacing generic accessor functions with new, type-specific functions for strings, numbers, booleans, CSV arrays, and filters. This standardizes and clarifies environment variable parsing, reduces manual type conversion, and updates all configuration and logging modules to use the new typed accessors.

Changes

File(s) Change Summary
src/config.ts Replaced all environment variable accessors with new typed functions (env.string, env.number, env.boolean, env.csv, etc.), updating all exported constants accordingly. Manual parsing and type coercion were removed in favor of direct typed access.
src/lib/env.ts Renamed existing accessor functions for clarity and added new functions for boolean, number, CSV, and filter environment variable parsing.
src/log.ts Updated logging configuration constants to use new typed environment variable accessors instead of generic string access and manual parsing.
src/tracing.ts Changed OpenTelemetry environment variable access to use new typed accessors for numbers and strings, removing manual type coercion.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant env
    participant Logger
    participant Filter

    App->>env: string("VAR_NAME", default)
    App->>env: number("VAR_NAME", default)
    App->>env: boolean("VAR_NAME", default)
    App->>env: csv("VAR_NAME", default)
    App->>env: filter("VAR_NAME", defaultJson, Logger)
    env->>Logger: (for filter only) log parsing
    env->>Filter: (for filter only) createFilter
    env-->>App: Typed value (string, number, boolean, array, or filter)
Loading

Possibly related PRs

Suggested reviewers

  • karlprieb

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
(node:25405) [DEP0169] DeprecationWarning: url.parse() behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for url.parse() vulnerabilities.
(Use node --trace-deprecation ... to show where the warning was created)
[2/4] Fetching packages...
error @permaweb/aoconnect@0.0.57: The engine "yarn" is incompatible with this module. Expected version "please-use-npm". Got "1.22.22"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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 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
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: 0

🧹 Nitpick comments (4)
src/lib/env.ts (3)

42-49: Consider more flexible boolean parsing.

The current implementation only accepts exactly 'true' as true. Consider supporting common boolean representations for better usability.

 export function boolean(
   envVarName: string,
   defaultValue = false,
 ): boolean {
   const value = process.env[envVarName];
   if (value === undefined || value.trim() === '') return defaultValue;
-  return value === 'true';
+  return ['true', '1', 'yes', 'on'].includes(value.toLowerCase());
 }

65-69: Consider trimming whitespace in CSV parsing.

The current implementation doesn't trim whitespace around comma-separated values, which could lead to unexpected behavior with spaces.

 export function csv(envVarName: string, defaultValue = ''): string[] {
   const value = process.env[envVarName];
   const str = value !== undefined && value.trim() !== '' ? value : defaultValue;
-  return str === '' ? [] : str.split(',');
+  return str === '' ? [] : str.split(',').map(s => s.trim());
 }

76-84: Optimize JSON parsing in filter function.

The function parses JSON twice (line 82 and 83), which is redundant and potentially inefficient.

 export function filter(
   envVarName: string,
   defaultJson: string,
   logger: Logger,
 ): ItemFilter {
   const raw = string(envVarName, defaultJson);
-  const canonical = canonicalize(JSON.parse(raw));
-  return createFilter(JSON.parse(canonical), logger);
+  const parsed = JSON.parse(raw);
+  const canonical = canonicalize(parsed);
+  return createFilter(parsed, logger);
 }
src/config.ts (1)

64-67: Use numeric default instead of string template.

The numeric environment variable is using a string template literal as the default, which requires unnecessary string-to-number conversion.

 export const REDIS_CACHE_TTL_SECONDS = env.number(
   'REDIS_CACHE_TTL_SECONDS',
-  `${60 * 60 * 8}`, // 8 hours by default
+  60 * 60 * 8, // 8 hours by default
 );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c2f8851 and 134f700.

📒 Files selected for processing (4)
  • src/config.ts (18 hunks)
  • src/lib/env.ts (2 hunks)
  • src/log.ts (1 hunks)
  • src/tracing.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/lib/env.ts (2)
src/types.d.ts (1)
  • ItemFilter (719-721)
src/filters.ts (1)
  • createFilter (278-380)
🔇 Additional comments (8)
src/lib/env.ts (3)

22-25: LGTM: Clean function rename with preserved logic.

The rename from varOrDefault to string improves clarity about the return type while maintaining the same logic.


27-30: LGTM: Clean function rename with preserved logic.

The rename from varOrUndefined to stringOrUndefined improves clarity about the return type while maintaining the same logic.


32-40: LGTM: Clean function rename with preserved logic.

The rename from varOrRandom to stringOrRandom improves clarity while maintaining the same random generation logic.

src/log.ts (1)

22-26: LGTM: Consistent adoption of typed environment accessors.

The conversion to typed environment variable functions improves code clarity and type safety while preserving existing behavior.

src/tracing.ts (1)

32-46: LGTM: Improved type safety with numeric environment variables.

The conversion from manual string-to-number coercion (+env.varOrDefault) to typed env.number calls improves clarity and eliminates potential parsing issues.

src/config.ts (3)

32-32: LGTM: Consistent adoption of typed environment accessors.

The conversion of configuration constants to use typed environment variable functions significantly improves code clarity and type safety throughout the configuration layer.

Also applies to: 56-59, 74-77, 80-80


130-130: LGTM: Effective use of CSV parsing helper.

The new env.csv function eliminates manual string splitting and provides consistent CSV parsing across the configuration.

Also applies to: 133-136, 143-143, 204-207, 210-213, 567-567


259-263: LGTM: Streamlined filter creation.

The new env.filter function effectively replaces manual JSON parsing and filter creation, reducing code duplication and improving consistency.

Also applies to: 272-276, 573-577, 583-587

@djwhitt
Copy link
Collaborator Author

djwhitt commented May 27, 2025

Closing this in favor of #401.

@djwhitt djwhitt closed this May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants