Skip to content

chore: Cold start with provisioned concurrency support #834

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

Conversation

hjgraca
Copy link
Contributor

@hjgraca hjgraca commented Apr 7, 2025

Please provide the issue number

Issue number: #833

Summary

Changes

Add LambdaLifecycleTracker to manage cold start

This pull request introduces several updates to the AWS Lambda Powertools library, focusing on tracking Lambda lifecycle states, particularly cold starts, and improving initialization type handling. The most important changes include adding a new LambdaLifecycleTracker class, updating interfaces and constants, and incorporating the tracker into various aspects of the library.

Lambda lifecycle tracking and initialization type handling:

  • New LambdaLifecycleTracker class:

    • Added to track Lambda lifecycle states, including cold starts. This class uses static flags and AsyncLocal to maintain state across invocations.
  • Updates to IPowertoolsConfigurations interface:

    • Added IsColdStart and AwsInitializationType properties to indicate cold start status and Lambda initialization type, respectively.
  • Constants update:

    • Added AWSInitializationTypeEnv constant for the AWS_LAMBDA_INITIALIZATION_TYPE environment variable to determine the Lambda function's initialization type.

Integration of LambdaLifecycleTracker:

  • LoggingAspect:

    • Replaced the _isColdStart flag with LambdaLifecycleTracker.IsColdStart for cold start tracking.
  • MetricsAspect:

    • Replaced the _isColdStart flag with LambdaLifecycleTracker.IsColdStart and updated the reset logic. [1] [2]
  • TracingAspect:

    • Replaced the _isColdStart flag with LambdaLifecycleTracker.IsColdStart and updated the reset logic. [1] [2]

Testing and version updates:

  • New tests for LambdaLifecycleTracker:

    • Added comprehensive unit tests to ensure correct behavior of the cold start tracking logic.
  • Version updates:

    • Updated version numbers for Logging, Metrics, and Tracing components in version.json.

User experience

Please share what the user experience looks like before and after this change

Checklist

Please leave checklist items unchecked if they do not apply to your change.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

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.

@boring-cyborg boring-cyborg bot added area/common Core Powertools utility area/logging Core logging utility area/metrics Core metrics utility area/tracing Core tracing utility tests labels Apr 7, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 7, 2025
@hjgraca hjgraca linked an issue Apr 7, 2025 that may be closed by this pull request
2 tasks
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 10 out of 11 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • version.json: Language not supported
Comments suppressed due to low confidence (1)

libraries/src/AWS.Lambda.Powertools.Common/Core/LambdaLifecycleTracker.cs:12

  • [nitpick] Consider renaming '_isFirstContainer' to '_isFirstInvocation' to better reflect that it tracks the first invocation in the container; this may improve clarity for future maintainers.
private static bool _isFirstContainer = true;

@github-actions github-actions bot added the internal Maintenance changes label Apr 7, 2025
Copy link

sonarqubecloud bot commented Apr 7, 2025

Copy link

codecov bot commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 93.75000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 74.18%. Comparing base (1a8c29c) to head (6eba427).
Report is 5 commits behind head on develop.

Files with missing lines Patch % Lines
...Powertools.Common/Core/PowertoolsConfigurations.cs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #834      +/-   ##
===========================================
+ Coverage    74.15%   74.18%   +0.03%     
===========================================
  Files          210      211       +1     
  Lines         8411     8430      +19     
  Branches       909      914       +5     
===========================================
+ Hits          6237     6254      +17     
- Misses        1881     1883       +2     
  Partials       293      293              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hjgraca hjgraca merged commit 6d5a12c into aws-powertools:develop Apr 8, 2025
10 checks passed
@hjgraca hjgraca deleted the feature/coldstart-provisioned-concurrency branch April 8, 2025 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/common Core Powertools utility area/logging Core logging utility area/metrics Core metrics utility area/tracing Core tracing utility internal Maintenance changes size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: make cold start aware of Provisioned Concurrency
2 participants