-
Notifications
You must be signed in to change notification settings - Fork 821
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
feat(opentelemetry-resources): add runtime version information #2727
feat(opentelemetry-resources): add runtime version information #2727
Conversation
Signed-off-by: Cuichen Li <[email protected]>
Signed-off-by: Cuichen Li <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #2727 +/- ##
==========================================
+ Coverage 93.39% 93.41% +0.02%
==========================================
Files 159 160 +1
Lines 5450 5467 +17
Branches 1145 1149 +4
==========================================
+ Hits 5090 5107 +17
Misses 360 360
|
I believe we need the name in order for the version to be meaningful. The usecase would be many different languages/runtimes sending spans to the backend. How would you know which ones are node ( I believe we should have: {
"process.runtime.name": "nodejs",
"process.runtime.version": process.versions.node,
"process.runtime.description": "NodeJS"
} |
Signed-off-by: Cuichen Li <[email protected]>
@dyladan thanks, i have hardcoded the runtime name and description. |
packages/opentelemetry-resources/src/platform/node/detectors/ProcessDetector.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: Cuichen Li <[email protected]>
packages/opentelemetry-resources/src/platform/browser/detect-resources.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/src/platform/browser/detectors/BrowserDetector.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/src/platform/node/detectors/ProcessDetector.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: Cuichen Li <[email protected]>
Signed-off-by: Cuichen Li <[email protected]> Co-authored-by: legendecas <[email protected]>
Signed-off-by: Cuichen Li <[email protected]> Co-authored-by: legendecas <[email protected]>
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.
LGTM % nits.
|
||
describe('browserDetector()', () => { | ||
beforeEach(() => { | ||
global.window = { |
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.
sinon.stub
should be preferred to create mocks. Also global
is not a standard global alias in browser environment, please use globalThis
instead.
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.
updated.
tried to
sinon.stub(globalThis, 'window')
....
but got TypeError: Cannot stub non-existent property window
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.
packages/opentelemetry-resources/src/platform/browser/detect-resources.ts
Show resolved
Hide resolved
Signed-off-by: Cuichen Li <[email protected]>
Signed-off-by: Cuichen Li <[email protected]>
Signed-off-by: Cuichen Li <[email protected]>
@cuichenli After fixing the build & rebasing the PR should be good to merge ! |
Signed-off-by: Cuichen Li <[email protected]>
…-runtime-version Signed-off-by: Cuichen Li <[email protected]>
@vmarchaud I have fixed the issue, can you please re-trigger the build? thanks |
@legendecas is this PR blocked on your spec PR or no? |
@dyladan yeah, it will be great to see how open-telemetry/opentelemetry-specification#2290 goes after the review. Most likely there aren't many things to change since the spec PR just writes down what we are doing in this PR, except that the spec PR removed |
packages/opentelemetry-resources/src/platform/browser/detectors/BrowserDetector.ts
Outdated
Show resolved
Hide resolved
@cuichenli I'm so sorry for this to wait such a long time. I think open-telemetry/opentelemetry-specification#2290 is going to be merged unchanged. But it took a long time already and I'd believe we should get things rolling and this PR should not be blocked. Would you mind resolving the conflicts so that we can get this PR merged? Thank you very much. |
@legendecas thanks! i have updated the branch. |
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.
Thank you for your work! I think the PR is almost complete once we resolve these two issues.
@@ -0,0 +1,61 @@ | |||
/* |
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.
The detectors were moved to the src/detectors
folder so that we can have a consistent export on both Node.js and Web environments. And detector.detect
will do nothing if the environment is not the expected one, like https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-resources/src/detectors/ProcessDetector.ts#L30.
Could you move the BrowserDetector to src/detectors
too so that it can be exported unconditionally?
resources.forEach(resource => { | ||
// Print only populated resources | ||
if (Object.keys(resource.attributes).length > 0) { | ||
const resourceDebugString = util.inspect(resource.attributes, { |
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.
util.inspect
is not available on the Web, that's why it is located in the src/platform/node
so that it won't be bundled in the web applications. Moving this API out of src/platform/node
makes it unusable on Web environments. I think this change could be separated into another PR to make detectResource
Web compatible.
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.
i will file an issue for this and work on it in another pr. thanks!
packages/opentelemetry-resources/src/platform/browser/detectors/BrowserDetector.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/src/platform/browser/detectors/BrowserDetector.ts
Outdated
Show resolved
Hide resolved
Spec PR merged which means when this is ready it can be merged |
Signed-off-by: Cuichen Li <[email protected]>
Signed-off-by: Cuichen Li <[email protected]>
@legendecas have updated based on the comments. please take another look. thanks |
describe('browserDetector()', () => { | ||
beforeEach(() => { | ||
(globalThis.window as {}) = {}; | ||
sinon.stub(globalThis, 'window').value({ |
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.
The test is failing because globalThis.window
in the browser environment is not configurable or writable. You may need to stub the property you need instead of stub the whole "window" object.
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.
Test isn't failing...
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.
fixed. but it took me a while to realize we now have describeNode
and describeBrowser
🤦
|
||
describe('browserDetector()', () => { | ||
beforeEach(() => { | ||
(globalThis.window as {}) = {}; |
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.
Since this file will be tested in the Node.js environment only, we don't need to mock the globalThis.window
anymore.
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.
fixed
Signed-off-by: Cuichen Li <[email protected]>
Thank you for your work! |
Signed-off-by: Cuichen Li [email protected]
Which problem is this PR solving?
Add runtime version information for node resources detector.
In the original issue, it was proposed to also add
runtime.name
andruntime.description
. I feel it does not make much sense for node. But let me know if we want to add it. Following is one exampleversions
output I retrieved:Thinking maybe we can add the
v8
info toruntime.description
? Please kindly advice. ThanksFixes #2562
Short description of the changes
Retrieve version info from
process
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Tested locally it can successfully retrieve the runtime version. Also updated the unit test.
Checklist: