-
Notifications
You must be signed in to change notification settings - Fork 171
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
refactor(metrics): replace EnvironmentVariablesService with cached #envConfig #4188
Conversation
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
@svozza you are right. It's not actually needed as inferred type of the whole expression is string | undefined which is compatible with the type of namespace. |
Hi @uttam282005 thank you for your contribution - please make sure to review the acknowledgment section here and paste it in the PR body as-is and without modifications if you agree with its text. We won't be able to merge the PR otherwise. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
A couple small changes to maintain full parsing of POWERTOOLS_METRICS_DISABLED
and remove non-null assertions from the #envConfig
.
…n-null assertions from #envConfig
|
@dreamorosi I’ve implemented the suggested changes. Please let me know if there’s anything else that needs to be addressed. |
Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience! |
@aws-powertools/lambda-typescript No related issues found. Please ensure 'pending-release' label is applied before releasing. |
EnvironmentVariablesService
class.#envConfig
object populated once duringsetOptions()
.Metrics.ts
to use#envConfig
for values likenamespace
,serviceName
,functionName
, etc.envVarsService
, includinggetEnvVarsService()
andsetEnvVarsService()
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 theMetrics
class. The object is populated once during initialization via thesetOptions()
method using functional utilities from@aws-lambda-powertools/commons/utils/env
.Why?
Benefits
#4136
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.