Skip to content

Add host.id resource detector#4843

Open
jaydeluca wants to merge 12 commits into
open-telemetry:mainfrom
jaydeluca:resource-detector-host
Open

Add host.id resource detector#4843
jaydeluca wants to merge 12 commits into
open-telemetry:mainfrom
jaydeluca:resource-detector-host

Conversation

@jaydeluca

@jaydeluca jaydeluca commented Jul 20, 2026

Copy link
Copy Markdown
Member

Description

This PR adds a host.id resource detector following the semconv spec, and using the java agent implementation as a reference.

Fixes #4830

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

I wrote a small test app, and added

...
from opentelemetry.resource.detector.host import HostIdResourceDetector
...

    resource = get_aggregated_resources(
        detectors=[HostIdResourceDetector()],
        initial_resource=Resource.create(
            {ResourceAttributes.SERVICE_NAME: "host-detector-manual-test"}
        ),
    )

Ran the app (on macOS) and observed the attribute

image

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

@jaydeluca
jaydeluca requested a review from a team as a code owner July 20, 2026 18:55
return SimpleNamespace(stdout=stdout, stderr="", returncode=return_code)


class HostIdResourceDetectorTest(TestBase):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we update these tests so that they test as much of the functionality end-to-end as possible? Almost everything is being patched here, which doesn't make these tests that useful. Our CI runs on both Linux and Windows so you should be able to at least test these systems end-to-end.

@github-project-automation github-project-automation Bot moved this to Reviewed PRs that need fixes in Python PR digest Jul 22, 2026
Comment thread .github/workflows/generate_workflows.py Outdated
self.assertIn(HOST_ID, resource.attributes)
host_id = resource.attributes[HOST_ID]
self.assertIsInstance(host_id, str)
self.assertTrue(host_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we make a stronger assertion here: that this is a 32 character lowercase hexadecimal string, or better yet read the contents of /etc/machine-id or /var/lib/dbus/machine-id

Comment thread docs/index.rst Outdated
pip install -e ./instrumentation-genai/opentelemetry-instrumentation-openai-v2
pip install -e ./sdk-extension/opentelemetry-sdk-extension-aws
pip install -e ./resource/opentelemetry-resource-detector-containerid
pip install -e ./resource/opentelemetry-resource-detector-host

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.

I think the package name like this can create confusion with the default HostResourceDetector in the SDK. Maybe rename it to hostid, host-id?

Maybe I'm being conservative here from the user perspective, but just sharing some thoughts.

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 agree, i'm going to update it, thanks

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

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

Add host.id resource attribute detector

4 participants