Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Add telemetry for Lambda Managed Instances#13466

Merged
joe4dev merged 3 commits into
mainfrom
lmi/add-telemetry
Dec 9, 2025
Merged

Add telemetry for Lambda Managed Instances#13466
joe4dev merged 3 commits into
mainfrom
lmi/add-telemetry

Conversation

@joe4dev

@joe4dev joe4dev commented Dec 4, 2025

Copy link
Copy Markdown
Member

Motivation

We're currently missing runtime telemetry for Lambda Managed Instances (LMI) to track errors and usage of the feature beyond the control plane API.

Changes

  • Add instrumentation for LMI through initialization_type. This maps to an AWS-defined property and is more extensible than a simple boolean flag uses_capacity_provider.
  • Fix a double-counting error for successful async-invokes
  • Refactor the event manager to reduce duplication around metadata

Limitations

  • provisioned-concurrency is currently not taken into account because it is not easily accessible in the context (might require enriching the invocation result)
  • The current telemetry instrumentation seems too complex, as I would prefer a single instrumentation in lambda.Invoke. However, this would require some refactorings and API enrichment (e.g., passing ESM metadata through lambda.Invoke via custom fields or headers)

Tests

The following tests can be used to validate that the metrics work as expected:

  • [localstack-pro] tests.aws.services.lambda_.test_lambda_managed_instances.TestLambdaManagedInstances.test_lifecycle should generate a create and invoke event with the new initialization_type=lambda-managed-instances.
  • [localstack] aws.services.lambda_.test_lambda.TestLambdaFeatures.test_invocation_type_event should generate a create and invoke event with the initialization_type=on-demand and the invocation_type=event for each execution (node & python). Validate that the invoke event is not recorded twice.

Related

Part of DRG-36

@joe4dev joe4dev added this to the 4.12 milestone Dec 4, 2025
@joe4dev joe4dev self-assigned this Dec 4, 2025
@joe4dev joe4dev added semver: patch Non-breaking changes which can be included in patch releases docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes labels Dec 4, 2025
try:
invocation_result = self.version_manager.invoke(invocation=invocation)
function_config = self.version_manager.function_version.config
function_counter.labels(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Given the counter in the finally clause, this counter seems to produce double counting 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great catch! I agree about your thoughts in the PR description - we should have a single point for the telemetry, instead of having it split up - this would have already prevented this double counting.

@github-actions

github-actions Bot commented Dec 4, 2025

Copy link
Copy Markdown

Test Results - Preflight, Unit

22 889 tests  ±0   21 075 ✅ ±0   6m 38s ⏱️ +15s
     1 suites ±0    1 814 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit 44105d8. ± Comparison against base commit b8e33ce.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Dec 4, 2025

Copy link
Copy Markdown

Test Results (amd64) - Acceptance

7 tests  ±0   5 ✅ ±0   2m 56s ⏱️ -6s
1 suites ±0   2 💤 ±0 
1 files   ±0   0 ❌ ±0 

Results for commit 44105d8. ± Comparison against base commit b8e33ce.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Dec 4, 2025

Copy link
Copy Markdown

Test Results (amd64) - Integration, Bootstrap

    5 files      5 suites   2h 32m 25s ⏱️
5 507 tests 4 952 ✅ 555 💤 0 ❌
5 513 runs  4 952 ✅ 561 💤 0 ❌

Results for commit 44105d8.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Dec 4, 2025

Copy link
Copy Markdown

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 54m 53s ⏱️ -33s
5 127 tests +6  4 732 ✅ +3  395 💤 +3  0 ❌ ±0 
5 129 runs  +6  4 732 ✅ +3  397 💤 +3  0 ❌ ±0 

Results for commit 44105d8. ± Comparison against base commit b8e33ce.

♻️ This comment has been updated with latest results.

@joe4dev joe4dev marked this pull request as ready for review December 5, 2025 13:30

@dfangl dfangl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM in principal, but I believe there are some errors in how we construct the telemetry labels now, which we should fix before merging!

try:
invocation_result = self.version_manager.invoke(invocation=invocation)
function_config = self.version_manager.function_version.config
function_counter.labels(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great catch! I agree about your thoughts in the PR description - we should have a single point for the telemetry, instead of having it split up - this would have already prevented this double counting.

Comment thread localstack-core/localstack/services/lambda_/invocation/event_manager.py Outdated
Comment thread localstack-core/localstack/services/lambda_/invocation/event_manager.py Outdated
@joe4dev joe4dev requested a review from dfangl December 5, 2025 16:16

@dfangl dfangl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for addressing those comments!

@vittoriopolverino vittoriopolverino left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

praise: thank you for taking the time to thoroughly consider the metric design and for suggesting initialization_type instead of the flag. It significantly improves clarity 🚀

note: the schema bump shouldn't cause any major difficulties when querying the raw data because we've only added a new attribute. For historical data (before version v4.12.0), you will simply see empty values for the initialization_type attribute.

note: the lambda.function metric counter has now hit its soft limit of 6 labels.

note: I have already updated the metrics dictionary ✅

@joe4dev joe4dev merged commit 1224e92 into main Dec 9, 2025
44 checks passed
@joe4dev joe4dev deleted the lmi/add-telemetry branch December 9, 2025 16:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes semver: patch Non-breaking changes which can be included in patch releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants