Skip to content

fix(metrics): skip ColdStart under provisioned concurrency in Metrics.AspNetCore - #1365

Merged
hjgraca merged 2 commits into
developfrom
fix/metrics-aspnetcore-provisioned-concurrency
Nov 25, 2026
Merged

hjgraca merged 2 commits into
developfrom
fix/metrics-aspnetcore-provisioned-concurrency

Conversation

@hjgraca

@hjgraca hjgraca commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Issue number: closes #1364

Summary

Changes

Metrics.AspNetCore (UseMetrics() and .WithMetrics()) no longer emits a ColdStart metric when the execution environment was initialized for provisioned concurrency. That matches the [Metrics] attribute, which already skips it through LambdaLifecycleTracker.IsColdStart.

  • ColdStartTracker.TrackColdStart still marks the cold start as consumed on the first request. It then returns without capturing when the AWS_LAMBDA_INITIALIZATION_TYPE environment variable is provisioned-concurrency. It reads the variable directly instead of using PowertoolsConfigurations: in Release, Common is compiled into each package, so the type is ambiguous when both are referenced (CS0433).
  • LambdaLifecycleTracker.IsColdStart isn't reused, because under ASP.NET Core hosting the first read anywhere uses up the cold start (see fix(metrics): emit ColdStart once in Metrics.AspNetCore and stop mutating default dimensions #1363).
  • Docs: one sentence in Capturing cold start metric (docs/core/metrics.md) saying provisioned-concurrency environments aren't counted, for both the attribute and ASP.NET Core.

User experience

  • Before: an ASP.NET Core Lambda on provisioned concurrency emits ColdStart on the first request in every pre-initialized environment, so the metric over-reports compared with a [Metrics] handler.
  • After: no ColdStart for provisioned-concurrency environments. On-demand behaviour is unchanged.

Testing

New theory tests in MetricsMiddlewareExtensionsTests and MetricsEndpointExtensionsTests. They send two requests with AWS_LAMBDA_INITIALIZATION_TYPE set to provisioned-concurrency (expect 0), on-demand (expect 1) and unset (expect 1), and restore the variable afterwards.

  • Before the fix: the provisioned-concurrency cases failed on net8.0 and net10.0 (received 1 ColdStart), and the other cases passed.
  • After: dotnet test libraries/tests/AWS.Lambda.Powertools.Metrics.AspNetCore.Tests passes 17/17 on net8.0 and 17/17 on net10.0.
  • dotnet build libraries --configuration Release (the full solution, as in CI) succeeded with 0 errors, and the tests pass in both Debug and Release.

Merge danger: two-way door. Blast radius: ColdStart metric emission in Metrics.AspNetCore for provisioned-concurrency functions only.

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.

@hjgraca hjgraca added bug Unexpected, reproducible and unintended software behaviour area/metrics-aspnetcore labels Nov 25, 2026
@boring-cyborg boring-cyborg Bot added documentation Improvements or additions to documentation tests labels Nov 25, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 25, 2026
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.16%. Comparing base (1cea20a) to head (0a8a22a).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1365   +/-   ##
========================================
  Coverage    80.16%   80.16%           
========================================
  Files          303      303           
  Lines        12849    12850    +1     
  Branches      1529     1530    +1     
========================================
+ Hits         10300    10301    +1     
  Misses        2094     2094           
  Partials       455      455           

☔ View full report in Codecov by Harness.
📢 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 e2c6166 into develop Nov 25, 2026
12 of 13 checks passed
@hjgraca
hjgraca deleted the fix/metrics-aspnetcore-provisioned-concurrency branch November 25, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/metrics-aspnetcore bug Unexpected, reproducible and unintended software behaviour documentation Improvements or additions to documentation 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.

Bug: Metrics.AspNetCore emits ColdStart under provisioned concurrency

1 participant