Skip to content

feat: Add opentelemetry-resource-detector-os - #2443

Open
yhara wants to merge 25 commits into
open-telemetry:mainfrom
yhara:os-resource-detector
Open

feat: Add opentelemetry-resource-detector-os#2443
yhara wants to merge 25 commits into
open-telemetry:mainfrom
yhara:os-resource-detector

Conversation

@yhara

@yhara yhara commented Jul 9, 2026

Copy link
Copy Markdown

Hello. I understood that #2303 is a task to create an opentelemetry-resource-detector-os gem under resources/os/, so I've started working on it. Please let me know if there are any issues. @thompson-tomo

TODOs

  • implement get_* (at least for linux; maybe split PRs for other OS)
  • os.build_id is not in OpenTelemetry::SemanticConventions::Resource::*. Should I skip this or add the constant to SemanticConventions?

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 9, 2026

Copy link
Copy Markdown

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

  • ✅ login: thompson-tomo / name: James Thompson (b5264dd)
  • ✅ login: yhara / name: Yutaka HARA (b5264dd)
  • ✅ login: yhara / name: Yutaka Hara (22d78eb)

Comment thread resources/os/lib/opentelemetry/resource/detector/os.rb Outdated
Comment thread resources/os/lib/opentelemetry/resource/detector/os.rb Outdated
Comment thread resources/os/lib/opentelemetry/resource/detector/os/version.rb Outdated
let(:detected_resource_attributes) { detected_resource.attribute_enumerator.to_h }

it 'returns a resource with os_type string' do
_(detected_resource_attributes['os.type']).must_be_instance_of(String)

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.

We need to be checking the value.

@github-actions github-actions Bot added the ci label Jul 11, 2026
Comment thread resources/os/Gemfile Outdated
Comment thread resources/os/test/opentelemetry/resource/detector/os_test.rb
Comment thread resources/os/test/opentelemetry/resource/detector/os_test.rb Outdated
Comment thread resources/os/test/opentelemetry/resource/detector/os_test.rb Outdated
Comment thread resources/os/test/opentelemetry/resource/detector/os_test.rb Outdated
Comment thread resources/os/test/opentelemetry/resource/detector/os_test.rb
Comment thread resources/os/test/opentelemetry/resource/detector/os_test.rb Outdated
name = lookup_plist(plist, 'ProductName')
attrs[SEMCONV::OS_NAME] = name if name

attrs[SEMCONV::OS_DESCRIPTION] = "#{name} #{ver} (#{buildver})" if name && ver && buildver

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The same way as opentelemetry-go.

@yhara

yhara commented Jul 21, 2026

Copy link
Copy Markdown
Author

Examples of actual values:

Windows (x64-mingw-ucrt)

#<OpenTelemetry::SDK::Resources::Resource:0x0000018423bccf48 @attributes={
  "os.type"=>"windows", 
  "os.name"=>"Windows", 
  "os.version"=>"10.0.26200.8037", 
  "os.description"=>"Microsoft Windows [Version 10.0.26200.8037]", 
  "os.build_id"=>"26200"}>

Mac

#<OpenTelemetry::SDK::Resources::Resource:0x0000000100da7388 @attributes={
  "os.type" => "darwin", 
  "os.version" => "15.7.7", 
  "os.build_id" => "24G720", 
  "os.name" => "macOS", 
  "os.description" => "macOS 15.7.7 (24G720)"}>

Linux (Ubuntu on Amazon EC2)

#<OpenTelemetry::SDK::Resources::Resource:0x000079025886e830 @attributes={
  "os.type" => "linux", 
  "os.name" => "Ubuntu", 
  "os.version" => "26.04", 
  "os.description" => "Ubuntu 26.04 LTS", 
  "os.build_id" => "7.0.0-1008-aws"}>

Linux (Ubuntu on WSL2)

#<OpenTelemetry::SDK::Resources::Resource:0x00007f1792715038 @attributes={
  "os.type" => "linux", 
  "os.name" => "Ubuntu", 
  "os.version" => "22.04", 
  "os.description" => "Ubuntu 22.04.5 LTS", 
  "os.build_id" => "5.15.146.1-microsoft-standard-WSL2+"}>

@yhara
yhara marked this pull request as ready for review July 21, 2026 08:17
@yhara
yhara requested review from a team, hannahramadan and xuan-cao-swi as code owners July 21, 2026 08:17
Comment thread resources/os/Gemfile Outdated
Comment on lines +8 to +12
begin
# (Windows only)
require 'win32/registry'
rescue LoadError
end

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.

This doesn't work on jruby. Can u find a solution which also satisfies rubocop

yhara and others added 2 commits July 23, 2026 13:36
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
This should fix the CI error with jruby on Ubuntu.
Also fixes a rubocop warning
Comment on lines +20 to +31
it 'returns an os resource (e2e test; no mocking)' do
case RUBY_PLATFORM
when /linux/
_(detected_resource_attributes['os.type']).must_equal('linux')
when /mswin|msys|mingw|cygwin/
_(detected_resource_attributes['os.type']).must_equal('windows')
when /darwin/
_(detected_resource_attributes['os.type']).must_equal('darwin')
else
_(detected_resource_attributes).must_equal([])
end
end

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 verify the presence of an attribute sourced from the system so we are confirming that the source provides the info.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

0c06f6d There aren't many attributes that can always be retrieved, but I made sure that if one is obtained, it is returned as a string.

@yhara

yhara commented Aug 3, 2026

Copy link
Copy Markdown
Author

@thompson-tomo Hi, what do we need to get this merged? Is there anything you are concerned about? (testing side or the implementation side)

@kaylareopelle kaylareopelle left a comment

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.

Thanks your this contribution, @yhara! I have a few questions/comments.

In addition, would you be willing to help maintain this resource detector going forward? If so, please add your GitHub username to the .github/.component_owners.yml file. Here's an example for the container resource detector:

resources/container:
- scbjans

yard: true
build: true
- name: "Test JRuby"
if: startsWith(matrix.os, 'ubuntu')

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.

What was the motivation for removing this line? Just curious because I think it may impact the way we test things outside of the resource-detector-os.

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.

We need to remove so that we can test the os resource detector on windows & jruby.

spec.required_ruby_version = '>= 3.3'

spec.add_dependency 'fiddle', '~> 1.1.8'
spec.add_dependency 'opentelemetry-sdk', '~> 1.10'

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.

The sdk has a very loose dependency on opentelemetry-semantic-conventions, with no version restrictions. Did you do any testing to see if you try to install a version of the semconv before the Incubating module was established what happened?

extend self

RESOURCE = OpenTelemetry::SDK::Resources::Resource
SEMCONV = OpenTelemetry::SemConv::Incubating::OS

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.

🌟

Comment on lines +43 to +44
# eg. "Ubuntu"
name = lookup_os_release(os_release, 'NAME')

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.

These examples are helpful! Thanks!

Comment thread resources/os/README.md

## How does this gem fit in?

The `opentelemetry-resource-detector-os` gem provides a means of retrieving a resource for supported environments following the resource semantic conventions. This detector automatically identifies and populates resource attributes with relevant metadata from the environment.

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.

A suggestion for easier access to context. You can disregard or reword if you prefer it another way.

Suggested change
The `opentelemetry-resource-detector-os` gem provides a means of retrieving a resource for supported environments following the resource semantic conventions. This detector automatically identifies and populates resource attributes with relevant metadata from the environment.
The `opentelemetry-resource-detector-os` gem provides a means of retrieving a resource for supported environments following [the operating system resource semantic conventions](https://opentelemetry.io/docs/specs/semconv/resource/os/). This detector automatically identifies and populates resource attributes with relevant metadata from the environment.

Comment thread resources/os/CHANGELOG.md
Comment on lines +2 to +5

## v0.1.0 / 2026-xx-xx

- Initial release.

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.

For our release automation, it's best to have just the top line for the first release. It'll add the version, date, and "Initial release." text.

Suggested change
## v0.1.0 / 2026-xx-xx
- Initial release.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants