Skip to content
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

fix(host-metrics): macOS bundling fix #2071

Merged
merged 45 commits into from
Jun 3, 2024
Merged

fix(host-metrics): macOS bundling fix #2071

merged 45 commits into from
Jun 3, 2024

Conversation

Netail
Copy link
Contributor

@Netail Netail commented Mar 30, 2024

Which problem is this PR solving?

  • Fix bundling

Short description of the changes

  • Use specific file, instead of bundling all file of package

@Netail Netail requested a review from a team March 30, 2024 00:00
Copy link

linux-foundation-easycla bot commented Mar 30, 2024

@Netail
Copy link
Contributor Author

Netail commented Apr 2, 2024

CI/CD should be fixed now :) (btw; npm install fails with Node 20 due to grpc)

@Netail Netail requested a review from pichlermarc April 2, 2024 21:28
@david-luna
Copy link
Contributor

Hi @Netail

Thank you for contributing to OTEL :)

We can leverage this PR to help effort the group is doing to update the semantic conventions. Currently we're in a step we need to use the exported strings as you did in this PR and also document which version of the semantic conventions is using.

Would you please add a section in the README file with this info. Here is an example of what I'm referring to.
https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2039/files#diff-24b1cca18e57b052dc9ad991566c9e6cc4a10a47d8528e347ddda139d1ce705e

@Netail
Copy link
Contributor Author

Netail commented Apr 4, 2024

Hi @Netail

Thank you for contributing to OTEL :)

We can leverage this PR to help effort the group is doing to update the semantic conventions. Currently we're in a step we need to use the exported strings as you did in this PR and also document which version of the semantic conventions is using.

Would you please add a section in the README file with this info. Here is an example of what I'm referring to. https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2039/files#diff-24b1cca18e57b052dc9ad991566c9e6cc4a10a47d8528e347ddda139d1ce705e

Hi @david-luna
So if I understand correctly, I have to add all of https://github.com/Netail/opentelemetry-js-contrib/blob/fix/host-metrics-bundling/packages/opentelemetry-host-metrics/src/enum.ts to https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-semantic-conventions, use the package in host-metrics (replacing the package based ones) and adding the ones used from the semantic-conventions package in the README with the table template?

@Netail
Copy link
Contributor Author

Netail commented Apr 4, 2024

Just checked regarding opentelemetry-semantic-conventions package; it fetches the specifications from opentelemetry-specification, but the specifications folder got removed in v1.21.0, so the generator is broken... :(

@david-luna
Copy link
Contributor

Hi @david-luna So if I understand correctly, I have to add all of https://github.com/Netail/opentelemetry-js-contrib/blob/fix/host-metrics-bundling/packages/opentelemetry-host-metrics/src/enum.ts to https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-semantic-conventions, use the package in host-metrics (replacing the package based ones) and adding the ones used from the semantic-conventions package in the README with the table template?

Semantic conventions already has these enums but the package is not updated yet so no need to contribute to https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-semantic-conventions. Actually this package is generated from the models in https://github.com/open-telemetry/semantic-conventions

We need to inform which version of semantic conventions model (not package) host metrics is using and list them. In this case the package uses v1.24.0 of the model

You could add a section with this message

## Semantic Conventions

This package uses Semantic Conventions [Version 1.24.0](https://github.com/open-telemetry/semantic-conventions/tree/v1.24.0/docs/http). As for now the Semantic Conventions
are bundled in this package but eventually will be imported from `@opentelemetry/semantic-conventions` package when it is updated to latest version.
Ref: [opentelemetry-js/issues/4235](https://github.com/open-telemetry/opentelemetry-js/issues/4235)

Attributes collected:

| Attribute          | Short Description    | Notes                   |
| ------------------ | -------------------- | ----------------------- |
| `system.cpu.state` | The state of the CPU | Key: `SYSTEM_CPU_STATE` |
| ... other attributes  |

@Netail
Copy link
Contributor Author

Netail commented Apr 4, 2024

Hi @david-luna So if I understand correctly, I have to add all of https://github.com/Netail/opentelemetry-js-contrib/blob/fix/host-metrics-bundling/packages/opentelemetry-host-metrics/src/enum.ts to https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-semantic-conventions, use the package in host-metrics (replacing the package based ones) and adding the ones used from the semantic-conventions package in the README with the table template?

Semantic conventions already has these enums but the package is not updated yet so no need to contribute to https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-semantic-conventions. Actually this package is generated from the models in https://github.com/open-telemetry/semantic-conventions

We need to inform which version of semantic conventions model (not package) host metrics is using and list them. In this case the package uses v1.24.0 of the model

You could add a section with this message

## Semantic Conventions

This package uses Semantic Conventions [Version 1.24.0](https://github.com/open-telemetry/semantic-conventions/tree/v1.24.0/docs/http). As for now the Semantic Conventions
are bundled in this package but eventually will be imported from `@opentelemetry/semantic-conventions` package when it is updated to latest version.
Ref: [opentelemetry-js/issues/4235](https://github.com/open-telemetry/opentelemetry-js/issues/4235)

Attributes collected:

| Attribute          | Short Description    | Notes                   |
| ------------------ | -------------------- | ----------------------- |
| `system.cpu.state` | The state of the CPU | Key: `SYSTEM_CPU_STATE` |
| ... other attributes  |

Shall I pull up a PR which generates the semantic concentions from the new repo?

@Netail
Copy link
Contributor Author

Netail commented Apr 4, 2024

Updated the generator here: open-telemetry/opentelemetry-js#4606

@david-luna
Copy link
Contributor

Updated the generator here: open-telemetry/opentelemetry-js#4606

this is indeed one of the tasks to be done for updating semantic conventions but since it a big leap in versions we expect breaking changes. This was discussed in the JavaScript SIG and planned. The plan is summarised and tracked in open-telemetry/opentelemetry-js#4572

the PR looks good but 1st we need to prepare the packages in contrib to be ready for the change. You can help us with these preparation tasks :)

Also you can join the SIG to discuss this topic and others. Here is the doc with the MoMs and also with the info to join https://docs.google.com/document/d/1tCyoQK49WVcE-x8oryZOTTToFm7sIeUhxFPm9g-qL1k/edit

@Netail
Copy link
Contributor Author

Netail commented Apr 4, 2024

Updated the generator here: open-telemetry/opentelemetry-js#4606

this is indeed one of the tasks to be done for updating semantic conventions but since it a big leap in versions we expect breaking changes. This was discussed in the JavaScript SIG and planned. The plan is summarised and tracked in open-telemetry/opentelemetry-js#4572

the PR looks good but 1st we need to prepare the packages in contrib to be ready for the change. You can help us with these preparation tasks :)

Also you can join the SIG to discuss this topic and others. Here is the doc with the MoMs and also with the info to join https://docs.google.com/document/d/1tCyoQK49WVcE-x8oryZOTTToFm7sIeUhxFPm9g-qL1k/edit

What kind of preparation do all the packages need?

Updated open-telemetry/opentelemetry-js#4606 to include v1.25.0 Semantic Conventions. As all packages within the same repo have a different version specified, we can merge that PR, and create different PRs for the packages who use the semantic-conventions package

Added the semantic conventions table to the README

packages/opentelemetry-host-metrics/README.md Outdated Show resolved Hide resolved
packages/opentelemetry-host-metrics/src/BaseMetrics.ts Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess with the change suggested by @pichlermarc in ./src/stats/si.ts

- import { networkStats } from 'systeminformation/lib/network';
+ import { networkStats } from 'systeminformation';

this file is no needed. I see the .d.ts file from systeminformation exporting networkStats function already

Copy link
Contributor Author

@Netail Netail Apr 5, 2024

Choose a reason for hiding this comment

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

When I use import { networkStats } from 'systeminformation';, it still tries to import the underlying cpu.js file, thus throwing an error on macOS. :( By targeting the file directly it won't.

The systeminformation/lib/cpu.js file tries to import osx-temperature-sensor for macOS, which you additionally have to install for macOS temperatures as it's not included in the dependencies, however osx-temp-sensor package breaks something else. But the cpu.js file isn't even used for host-metrics, so installing this package besides systeminformation is unecessary

@david-luna
Copy link
Contributor

What kind of preparation do all the packages need?

@Netail please check open-telemetry/opentelemetry-js#4572 for more info on the update plan, thanks :)

@Netail Netail requested a review from david-luna April 8, 2024 13:53
@Netail
Copy link
Contributor Author

Netail commented May 22, 2024

on every page render

Every page render is re-resolving every dependency? Or is that when running in next dev Dev-mode that might be re-compiling each time to get recent changes?

Not completely sure, I believe it runs the instrumentation.ts on every initial page render in development (local) mode.

@legendecas
Copy link
Member

legendecas commented May 24, 2024

systeminformation doesn't want to solve this issue at their side: sebhildebrandt/systeminformation#230, and the module 'osx-temperature-sensor' can be externalized to avoid being bundled without any plugin configurations.

// webpack.config.js
module.exports = {
  externals: ['osx-temperature-sensor'],
};

I'd avoid using subpath imports which are not considered as public interface.

Additionally, I would suggest splitting the PR for distinct purposes.

@Netail Netail changed the title fix(host-metrics): semcov alignment & macOS fix fix(host-metrics): semcov alignment May 24, 2024
@trentm
Copy link
Contributor

trentm commented May 24, 2024

We discussed in the SIG a couple days ago (https://docs.google.com/document/d/1tCyoQK49WVcE-x8oryZOTTToFm7sIeUhxFPm9g-qL1k/edit#heading=h.bxgyx12a4wsc) and decided that if we pinned the systeminformation dep, we'd be okay using the deep import.

From memory, my summary of the justification is:

  • A macOS user of @opentelemetry/host-metrics and Webpack may not be able to easily understand the impact of the error/warning message and know how to cope with it.
  • We could document the work-around in the host-metrics README or perhaps more visible "Troubleshooting" docs on opentelemetry.io, I suppose.
  • The use of host-metrics could possibly be indirect from the user's p.o.v. if, for example, the package is included in a custom vendor SDK.
  • The use of webpack could be indirect from the user's point of view. E.g. for Next.js users.
  • Certainly attributing the error message about osx-temperature-sensor to something used by host-metrics is indirect.
  • The structure of systeminformation looks like a top-level index that re-exports a number of independent functional sub-packages. I'm guessing (this is my opinion here) that it is unlikely that a future version would break the deep import we are proposing to use. At a guess, the most likely thing that would break this is if systeminformation/package.json added an "exports" section for unrelated reasons.
  • Pinning and using a deep import kind of sucks, yes.
  • If was mentioned that considering pulling in just the functionality we want from systeminformation into this repo was undesired. Having an effective fork means we lose the connection for possible fixes. There could be licensing issues/pain.

Aside: I'm not sure if bundlers other than Webpack result in a similar error/warning.

TODO:

  • Pin the systeminformation version in package.json.
  • Document some of the above concerns in the code where the deep import is being made to help future maintenance.
  • Splitting into two PRs, as legendecas suggested, would really help clarify for future maintenance, I agree.

(@Netail I see you recently commited removing the deep import. Sorry for back and forth on this. I should have posted notes from the SIG a couple days ago.)

@Netail Netail changed the title fix(host-metrics): semcov alignment fix(host-metrics): bundling fix May 24, 2024
@Netail
Copy link
Contributor Author

Netail commented May 24, 2024

Alright! Thanks, sounds good, will pick it up :) I've created a seperate PR for the semconv alignment & documentation; #2240

@Netail Netail changed the title fix(host-metrics): bundling fix fix(host-metrics): macOS bundling fix May 24, 2024
Copy link

codecov bot commented May 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.40%. Comparing base (dfb2dff) to head (79555fc).
Report is 148 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2071      +/-   ##
==========================================
- Coverage   90.97%   90.40%   -0.58%     
==========================================
  Files         146      149       +3     
  Lines        7492     7514      +22     
  Branches     1502     1573      +71     
==========================================
- Hits         6816     6793      -23     
- Misses        676      721      +45     
Files Coverage Δ
...ages/opentelemetry-host-metrics/src/BaseMetrics.ts 100.00% <100.00%> (ø)
packages/opentelemetry-host-metrics/src/metric.ts 100.00% <100.00%> (ø)
...ges/opentelemetry-host-metrics/src/stats/common.ts 97.91% <100.00%> (ø)
...ackages/opentelemetry-host-metrics/src/stats/si.ts 66.66% <100.00%> (ø)

... and 52 files with indirect coverage changes

@Netail
Copy link
Contributor Author

Netail commented May 30, 2024

Alright, I've put the deep import back & the semconv alignment PR has been merged in a seperate PR. :)

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

LGTM % nits.

packages/opentelemetry-host-metrics/package.json Outdated Show resolved Hide resolved
packages/opentelemetry-host-metrics/tsconfig.json Outdated Show resolved Hide resolved
@@ -25,7 +26,7 @@ import {
MetricReader,
} from '@opentelemetry/sdk-metrics';
import * as assert from 'assert';
import * as os from 'os';
import * as os from 'node:os';
Copy link
Member

Choose a reason for hiding this comment

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

I'd avoid mixing the style of with and without the prefix node:. Could you remove unrelated changes?

Copy link
Contributor Author

@Netail Netail May 30, 2024

Choose a reason for hiding this comment

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

I will remove them (noticed I forgot to prefix assert), but we do need to add them for the future though incase people use different js runtimes e.g. bun or deno.

And to bypass require cache.

import-js/eslint-plugin-import#2717 (comment)

https://stateful.com/blog/node-18-prefix-only-modules

Copy link
Contributor

Choose a reason for hiding this comment

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

If, for example, we needed to use node:test -- which is only available with the node:-prefix -- then yes we'd need to use the prefix.

However, currently we support "engines": { "node": ">=14" } in most package.json files. That is relatively loose on defining which Node.js v14 versions we support, but at least v14.0.0 didn't support node: prefixes:

Welcome to Node.js v14.0.0.
Type ".help" for more information.
> require('node:os')
Uncaught Error: Cannot find module 'node:os'
Require stack:
- <repl>
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1014:15)
    at Function.Module._load (internal/modules/cjs/loader.js:884:27)
    at Module.require (internal/modules/cjs/loader.js:1074:19)
    at require (internal/modules/cjs/helpers.js:72:18) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '<repl>' ]
}
>

Also, there is no rush on the usage with different runtimes. My guess (granted a guess), is that there is a ton of other work that would be required to get many of the OTel packages working reasonably with bun, deno, etc. We'd want to coordinate that in separate PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh that's true, do note that 14 and 16 hit their eol. So should we still support it tho?

Copy link
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

Thanks for persisting.

@Netail
Copy link
Contributor Author

Netail commented Jun 3, 2024

fyi; I am not allowed to merge, so when you guys are ready. feel free to merge :)

@legendecas legendecas merged commit 7d6ddea into open-telemetry:main Jun 3, 2024
19 checks passed
@legendecas
Copy link
Member

Thank you for working on this!

@dyladan dyladan mentioned this pull request Jun 3, 2024
@Netail Netail deleted the fix/host-metrics-bundling branch June 3, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants