-
Notifications
You must be signed in to change notification settings - Fork 635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sdk: Implement basic os resource detector #3992
Conversation
Based on OS resource semantics: https://opentelemetry.io/docs/specs/semconv/resource/os/ Currently implements `os.type` and `os.version`, attempting to be in line with what's reported by other runtimes (like java and node).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give than os.type is required
we should probably make the resource detector mandatory in https://github.com/open-telemetry/opentelemetry-python/pull/3992/files#diff-d2c46fd8da8afdf67c6ad3dd42b0a243c5049f3c720d9bb3351f1d5522338b06R182-R187
and in order to give it a name you need to add an entry in the sdk pyproject.toml inside project.entry-points.opentelemetry_resource_detector
3aded04
to
8680918
Compare
Great points, thank you! I've completely missed the entrypoint. Regarding making it a default, I've done the following simple diff: @@ -180,11 +180,13 @@ class Resource:
resource = _DEFAULT_RESOURCE
otel_experimental_resource_detectors = environ.get(
- OTEL_EXPERIMENTAL_RESOURCE_DETECTORS, "otel"
+ OTEL_EXPERIMENTAL_RESOURCE_DETECTORS, "otel,os"
).split(",")
if "otel" not in otel_experimental_resource_detectors:
otel_experimental_resource_detectors.append("otel")
+ if "os" not in otel_experimental_resource_detectors:
+ otel_experimental_resource_detectors.append("os")
for resource_detector in otel_experimental_resource_detectors:
resource_detectors.append( Running locally it looks good (yay!), but I'm having trouble with testing. A lot of things expect @@ -61,12 +62,26 @@ except ImportError:
psutil = None
+@patch("platform.uname", lambda: platform.uname_result(
+ system="Linux",
+ node="node",
+ release="1.2.3",
+ version="4.5.6",
+ machine="x86_64",
+ processor="x86_64"
+ ))
class TestResources(unittest.TestCase):
def setUp(self) -> None:
environ[OTEL_RESOURCE_ATTRIBUTES] = ""
+ self.mock_platform = {
+ OS_TYPE: "linux",
+ OS_VERSION: "1.2.3",
+ }
+ self.default_resource = _DEFAULT_RESOURCE.merge(Resource(self.mock_platform))
@@ -86,6 +101,7 @@ class TestResources(unittest.TestCase):
TELEMETRY_SDK_VERSION: _OPENTELEMETRY_SDK_VERSION,
SERVICE_NAME: "unknown_service",
}
+ expected_attributes.update(self.mock_platform)
@@ -431,7 +447,7 @@ class TestResources(unittest.TestCase):
resource_detector.raise_on_error = False
self.assertEqual(
get_aggregated_resources([resource_detector]),
- _DEFAULT_RESOURCE.merge(
+ self.default_resource.merge( It feels a bit icky. Am I missing a better, simpler way? |
See open-telemetry#3992 (comment) Co-Authored-By: Diego Hurtado <ocelotl@users.noreply.github.com>
@Zirak Please add an entry in the changelog |
Noticed the tests failing on python 3.8 - that's strange, will take a look |
@Zirak lint and docs are failing too |
The signature for `uname_result` changed between 3.8 and 3.9.
Apologies for the wait, life got in the way. I've pushed 4 commits:
|
I'm not sure if I agree with @xrmx 's comment regarding making the resource detector loaded by default. We have OtelResourceDetector loaded by default and it populates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment about defaulting logic.
Thanks @lzchen. How are discussions like this usually handled? Comments here, the CNCF slack, SIG topic, etc.? I'd be happy to present it at a SIG if necessary. |
I'm fine on not making it enabled by default |
Coolio, will revert it to not be a default |
6175458
to
12162ed
Compare
Description
Implement basic os resource detector.
Based on OS resource semantics: https://opentelemetry.io/docs/specs/semconv/resource/os/
Currently implements
os.type
andos.version
, attempting to be in line withwhat's reported by other runtimes (like java and node).
I have not yet tested on some more exotic OSs such as hp-ux, aix, or z/os.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
platform.system
andplatform.release
on a variety of operating systemsDoes This PR Require a Contrib Repo Change?
Answer the following question based on these examples of changes that would require a Contrib Repo Change:
The OTel specification has changed which prompted this PR to update the method interfaces of
opentelemetry-api/
oropentelemetry-sdk/
The method interfaces of
test/util
have changedScripts in
scripts/
that were copied over to the Contrib repo have changedConfiguration files that were copied over to the Contrib repo have changed (when consistency between repositories is applicable) such as in
pyproject.toml
isort.cfg
.flake8
When a new
.github/CODEOWNER
is addedMajor changes to project information, such as in:
README.md
CONTRIBUTING.md
Yes. - Link to PR:
No.
Checklist:
I'm unsure what the practice to do the two items above (changelog & documentation) would actually require. It seems like opening a PR is a prerequisite to generating a changelog. I haven't seen any special documentation around resource detectors. Is my understanding correct?
(Edit: Commits have since made sure to add the CHANGELOG entry and write proper pydocs around implementation)