feat: Add opentelemetry-resource-detector-os - #2443
Conversation
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
| 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) |
There was a problem hiding this comment.
We need to be checking the value.
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
| name = lookup_plist(plist, 'ProductName') | ||
| attrs[SEMCONV::OS_NAME] = name if name | ||
|
|
||
| attrs[SEMCONV::OS_DESCRIPTION] = "#{name} #{ver} (#{buildver})" if name && ver && buildver |
|
Examples of actual values: Windows (x64-mingw-ucrt) Mac Linux (Ubuntu on Amazon EC2) Linux (Ubuntu on WSL2) |
| begin | ||
| # (Windows only) | ||
| require 'win32/registry' | ||
| rescue LoadError | ||
| end |
There was a problem hiding this comment.
This doesn't work on jruby. Can u find a solution which also satisfies rubocop
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
This should fix the CI error with jruby on Ubuntu. Also fixes a rubocop warning
| 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 |
There was a problem hiding this comment.
Can we verify the presence of an attribute sourced from the system so we are confirming that the source provides the info.
There was a problem hiding this comment.
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.
RUBY_PLATFORM is "java" on JRuby
This is needed on Windows + Ruby4
|
@thompson-tomo Hi, what do we need to get this merged? Is there anything you are concerned about? (testing side or the implementation side) |
Remove conditional check for JRuby tests on Ubuntu.
kaylareopelle
left a comment
There was a problem hiding this comment.
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:
opentelemetry-ruby-contrib/.github/component_owners.yml
Lines 42 to 43 in 293ef1f
| yard: true | ||
| build: true | ||
| - name: "Test JRuby" | ||
| if: startsWith(matrix.os, 'ubuntu') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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 |
| # eg. "Ubuntu" | ||
| name = lookup_os_release(os_release, 'NAME') |
There was a problem hiding this comment.
These examples are helpful! Thanks!
|
|
||
| ## 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. |
There was a problem hiding this comment.
A suggestion for easier access to context. You can disregard or reword if you prefer it another way.
| 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. |
|
|
||
| ## v0.1.0 / 2026-xx-xx | ||
|
|
||
| - Initial release. |
There was a problem hiding this comment.
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.
| ## v0.1.0 / 2026-xx-xx | |
| - Initial release. |
Hello. I understood that #2303 is a task to create an
opentelemetry-resource-detector-osgem underresources/os/, so I've started working on it. Please let me know if there are any issues. @thompson-tomoTODOs
get_*(at least for linux; maybe split PRs for other OS)OpenTelemetry::SemanticConventions::Resource::*. Should I skip this or add the constant toSemanticConventions?