Skip to content

Fix ECS resource detector populating container.name with the hostname - #4961

Open
rdbisme wants to merge 4 commits into
open-telemetry:mainfrom
rdbisme:fix/ecs-container-name
Open

Fix ECS resource detector populating container.name with the hostname#4961
rdbisme wants to merge 4 commits into
open-telemetry:mainfrom
rdbisme:fix/ecs-container-name

Conversation

@rdbisme

@rdbisme rdbisme commented Aug 15, 2026

Copy link
Copy Markdown

Description

The AwsEcsResourceDetector populates the container.name resource attribute with socket.gethostname(). On ECS tasks using the awsvpc network 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), so container.name ends 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 for container.name when the v4 endpoint is present, and keeps the hostname as a fallback (v3-only path, or a response without a Name field).

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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 expecting container.name: "curl" from the metadata fixtures, proving the metadata value overrides the hostname. The v3 test keeps covering the hostname fallback.
  • ruff check on the changed source and test files — clean.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@rdbisme
rdbisme requested a review from a team as a code owner August 15, 2026 09:29
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 15, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 15, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-08-21 01:51 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@rdbisme

rdbisme commented Aug 16, 2026

Copy link
Copy Markdown
Author

@srprash @jj22ee

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant