Fix ECS resource detector populating container.name with the hostname - #4961
Open
rdbisme wants to merge 4 commits into
Open
Fix ECS resource detector populating container.name with the hostname#4961rdbisme wants to merge 4 commits into
rdbisme wants to merge 4 commits into
Conversation
Pull request dashboard statusWaiting on reviewers · refreshed 2026-08-21 01:51 UTC Review the latest changes. Status above doesn't look right?
|
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
AwsEcsResourceDetectorpopulates thecontainer.nameresource attribute withsocket.gethostname(). On ECS tasks using theawsvpcnetwork mode the container hostname is the IP-like private DNS name of the ENI (e.g.ip-10-0-2-100.us-west-2.compute.internal), socontainer.nameends up being an "IP name" instead of the actual container name.When the metadata endpoint v4 is available (which the detector already queries), the container-level response contains the container name as defined in the task definition (field
Name, e.g.curl). This PR uses that value forcontainer.namewhen the v4 endpoint is present, and keeps the hostname as a fallback (v3-only path, or a response without aNamefield).No existing issue was filed for this; the fix follows the metadata response documented at https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v4.html#task-metadata-endpoint-v4-response
Type of change
How Has This Been Tested?
python -m pytest sdk-extension/opentelemetry-sdk-extension-aws/tests/resource/test_ecs.py— 4 passed.The v4 EC2/Fargate tests now mock
socket.gethostname()to return the IP-like name while expectingcontainer.name: "curl"from the metadata fixtures, proving the metadata value overrides the hostname. The v3 test keeps covering the hostname fallback.ruff checkon the changed source and test files — clean.Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.