fix: handle missing package.json file when checking for version#2450
fix: handle missing package.json file when checking for version#2450vmarchaud merged 8 commits intoopen-telemetry:mainfrom
Conversation
| const packageJsonPath = path.join(baseDir, 'package.json'); | ||
| // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
| const version = require(path.join(baseDir, 'package.json')).version; | ||
| const version = existsSync(packageJsonPath) ? require(packageJsonPath).version : undefined; |
There was a problem hiding this comment.
even if a file exists it may be not readable (e.g. access rights). What about using a try/catch block instead?
Codecov Report
@@ Coverage Diff @@
## main #2450 +/- ##
==========================================
+ Coverage 92.71% 93.20% +0.48%
==========================================
Files 137 137
Lines 4996 5002 +6
Branches 1057 1057
==========================================
+ Hits 4632 4662 +30
+ Misses 364 340 -24
|
rauno56
left a comment
There was a problem hiding this comment.
I guess it's quite obvious for most people, but I'd add a comment somewhere that we are dealing with packages here for which we haven't detected a version at all. The describe kinda point in that direction, but the setup doesn't make that clear.
Something like
describe('_onRequire - module version is not available', () => {
// For all of these cases, there is no indication of the actual module version,
// so we require there to be a wildcard supported version.|
@rauno56 👍 |
|
@nozik You'll need to rebase the PR (or give us access to your fork so we can do it for you) |
|
@vmarchaud done |
obecny
left a comment
There was a problem hiding this comment.
lgtm, just some suggestion for tests description
packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts
Outdated
Show resolved
Hide resolved
|
@obecny Done |
Which problem is this PR solving?
package.jsonfile may be missing at runtime for a certain module. Currently OTEL crashes in this case, unnecessarily.Short description of the changes
package.jsonfile), we patch the module/file if and only if the supported versions contain a wildcard (*). Until now, an exception was thrown, crashing the app.