Skip to content

refactor(metrics): replace EnvironmentVariablesService with cached #envConfig #4188

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 1 commit into
base: main
Choose a base branch
from

Conversation

uttam282005
Copy link

@uttam282005 uttam282005 commented Jul 19, 2025

  • Removed EnvironmentVariablesService class.
  • Replaced repeated environment variable reads with a single #envConfig object populated once during setOptions().
  • Updated Metrics.ts to use #envConfig for values like namespace, serviceName, functionName, etc.
  • Removed all references to envVarsService, including getEnvVarsService() and setEnvVarsService() methods.

This refactor improves runtime performance by avoiding redundant environment variable reads and follows a cleaner, more functional approach. It also aligns with the setOptions() pattern for centralized config management and eliminates ~50 lines of unnecessary code.


Summary

What’s being changed?

This PR removes the verbose class-based EnvironmentVariablesService and replaces it with a private, cached #envConfig object in the Metrics class. The object is populated once during initialization via the setOptions() method using functional utilities from @aws-lambda-powertools/commons/utils/env.

Why?

  • Performance: Avoids repeated environment variable lookups at runtime.
  • Code quality: Cleaner, more maintainable, and aligns with existing config patterns.
  • Consistency: Follows the tenets of making things explicit, safe, and minimal.

Benefits

  • Improved runtime efficiency.
  • Simplified implementation.
  • Easier to reason about and maintain.

#4136


By submitting this pull request, I confirm that I can use, modify, copy, and redistribute this contribution under the terms of my choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Jul 19, 2025
@boring-cyborg boring-cyborg bot added the metrics This item relates to the Metrics Utility label Jul 19, 2025
Copy link

boring-cyborg bot commented Jul 19, 2025

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

Copy link

No acknowledgement section found. Please make sure you used the template to open a PR and didn't remove the acknowledgment section. Check the template at .github/PULL_REQUEST_TEMPLATE.md#acknowledgment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
metrics This item relates to the Metrics Utility size/L PRs between 100-499 LOC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant