Skip to content

[Resources.Aws] Get ECS container ID on Windows#4028

Open
martincostello wants to merge 2 commits intoopen-telemetry:mainfrom
martincostello:gh-750
Open

[Resources.Aws] Get ECS container ID on Windows#4028
martincostello wants to merge 2 commits intoopen-telemetry:mainfrom
martincostello:gh-750

Conversation

@martincostello
Copy link
Copy Markdown
Member

Fixes #750

Changes

Detect container ID for Windows ECS containers.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

Detect container ID for Windows ECS containers.

Fixes open-telemetry#750.
@github-actions github-actions bot added the comp:resources.aws Things related to OpenTelemetry.Resources.AWS label Mar 27, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.08%. Comparing base (da86069) to head (898fd26).
⚠️ Report is 26 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4028      +/-   ##
==========================================
+ Coverage   71.94%   72.08%   +0.14%     
==========================================
  Files         458      448      -10     
  Lines       17872    17825      -47     
==========================================
- Hits        12858    12850       -8     
+ Misses       5014     4975      -39     
Flag Coverage Δ
unittests-Instrumentation.Cassandra ?
unittests-Resources.AWS 74.67% <100.00%> (+0.33%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/OpenTelemetry.Resources.AWS/AWSECSDetector.cs 88.88% <100.00%> (+0.46%) ⬆️

... and 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

// On Linux the container ID is obtained from a file which does not exist on Windows.
// The ECS Metadata V4 container endpoint always carries the same ID in the "DockerId" field.
// See https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v4-response.html.
if (OperatingSystem.IsWindows() &&
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.

I was intentionally conservative here to not change the existing behaviour for Linux.

@martincostello martincostello marked this pull request as ready for review March 27, 2026 16:39
@martincostello martincostello requested a review from a team as a code owner March 27, 2026 16:39
Copilot AI review requested due to automatic review settings March 27, 2026 16:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves AWS ECS resource detection on Windows by extracting the ECS container ID from the ECS Metadata V4 container response, addressing issue #750 where Windows ECS containers lacked container identification.

Changes:

  • Extract container.id from the ECS Metadata V4 DockerId field when running on Windows.
  • Update ECS detector unit tests to assert container.id on Windows for V4 metadata scenarios.
  • Add an entry to the Resources.AWS changelog documenting the behavior change.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/OpenTelemetry.Resources.AWS.Tests/AWSECSDetectorTests.cs Adds Windows-only assertions for container.id in Metadata V4 tests and minor test refactor.
src/OpenTelemetry.Resources.AWS/AWSECSDetector.cs Adds Windows path to populate container.id from Metadata V4 DockerId.
src/OpenTelemetry.Resources.AWS/CHANGELOG.md Documents the new Windows ECS container.id extraction behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +111 to +119
// On Linux the container ID is obtained from a file which does not exist on Windows.
// The ECS Metadata V4 container endpoint always carries the same ID in the "DockerId" field.
// See https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v4-response.html.
if (OperatingSystem.IsWindows() &&
containerResponse.RootElement.TryGetProperty("DockerId", out var dockerIdElement) &&
dockerIdElement.GetString() is string { Length: > 0 } dockerId)
{
resourceAttributes.AddAttributeContainerId(dockerId);
}
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

Detect() still attempts to read /proc/self/cgroup on all OSes (via GetECSContainerId(AWSECSMetadataPath)), which will throw on Windows and gets logged as an extraction exception. Now that Windows container ID is obtained from Metadata V4, consider skipping the cgroup file read when OperatingSystem.IsWindows() (or otherwise avoiding the exception path) to prevent noisy logs and exception overhead on every detection run.

Copilot uses AI. Check for mistakes.
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.

Open to changing this if wanted. I wanted to minimise the diff.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 4, 2026
@martincostello martincostello added keep-open Prevents issues and pull requests being closed as stale and removed Stale labels Apr 4, 2026
@Kielek Kielek requested a review from normj April 7, 2026 05:51
@Kielek
Copy link
Copy Markdown
Member

Kielek commented Apr 7, 2026

@normj, could you please check this PR?

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

Labels

comp:resources.aws Things related to OpenTelemetry.Resources.AWS keep-open Prevents issues and pull requests being closed as stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenTelemetry.Contrib.Extensions.AWSXRay: AWSECSResourceDetector doesn't detect container information from Windows Containers

3 participants