Skip to content

feat(lambda): write cloud.account.id symlink from extension#2127

Open
RaphaelManke wants to merge 1 commit intoopen-telemetry:mainfrom
RaphaelManke:feat/cloud-account-id-symlink
Open

feat(lambda): write cloud.account.id symlink from extension#2127
RaphaelManke wants to merge 1 commit intoopen-telemetry:mainfrom
RaphaelManke:feat/cloud-account-id-symlink

Conversation

@RaphaelManke
Copy link

Summary

  • After the Lambda Extensions API Register() call, the extension now creates a symlink at /tmp/.otel-account-id with the AWS account ID as the target
  • Requests the accountId feature via the Lambda-Extension-Accept-Feature: accountId header
  • Handles execution environment reuse by removing stale symlinks before creating new ones
  • Fails silently (debug log only) if symlink creation fails

This enables all OTel SDK Lambda resource detectors to read cloud.account.id via readlink() without needing IAM calls.

Changes

  • collector/internal/extensionapi/client.go — Parse accountId from Register response, send Accept-Feature header
  • collector/internal/lifecycle/manager.go — Create symlink after registration
  • Tests for both header/parsing and symlink creation/cleanup

Related PRs

SDK-side implementations that read this symlink (will be linked once created).

Test plan

  • Unit test: symlink created with correct target
  • Unit test: leading zeros preserved
  • Unit test: stale symlink replaced
  • Unit test: empty accountID skipped silently
  • Unit test: Accept-Feature header sent correctly
  • Unit test: accountId parsed from response JSON

Request the accountId feature from the Lambda Extensions API via the
Lambda-Extension-Accept-Feature header. After Register() returns, write
a symlink at /tmp/.otel-account-id whose target is the raw AWS account
ID string. This allows Lambda SDK resource detectors to read the account
ID without an additional API call.

The symlink is removed before creation to handle Lambda execution
environment reuse where /tmp persists. Failures are logged at debug
level and silently skipped.
"github.com/open-telemetry/opentelemetry-lambda/collector/lambdacomponents"
)

const accountIDSymlinkPath = "/tmp/.otel-account-id"
Copy link
Contributor

Choose a reason for hiding this comment

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

Small nit:

Suggested change
const accountIDSymlinkPath = "/tmp/.otel-account-id"
const accountIDSymlinkPath = "/tmp/.otel-aws-account-id"

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you've already made the PRs for all the contrib repos, so to save the effort of changing the name everywhere, .otel-account-id is probably fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree since all the other PRs have already been created, we can leave it as is.

// Remove any stale symlink from a previous execution environment reuse.
os.Remove(accountIDSymlinkPath)
if err := os.Symlink(accountID, accountIDSymlinkPath); err != nil {
logger.Debug("Failed to create account ID symlink", zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should make this a Warning log instead of debug?

Copy link
Contributor

@wpessers wpessers left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution. Will merge as soon as the open remarks have been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants