-
Notifications
You must be signed in to change notification settings - Fork 468
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
refactor: use package json auto generated export also for npm package name #2203
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2203 +/- ##
==========================================
- Coverage 90.97% 90.38% -0.60%
==========================================
Files 146 147 +1
Lines 7492 7506 +14
Branches 1502 1573 +71
==========================================
- Hits 6816 6784 -32
- Misses 676 722 +46
|
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.
This is another change I'm a fan of as it increases consistency and reduces errors. I've left a few suggestions, though some may fall slightly out of scope (package names used elsewhere in the instrumentation).
VERSION, | ||
config | ||
); | ||
super(PACKAGE_NAME, PACKAGE_VERSION, config); |
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.
As part of this change I think we could remove the MODULE_NAME
constant from the constants.ts
file. Then we can also rename in the init()
there is another constants.MODULE_NAME
.
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 totally agree, this pattern should be simplified and refactored to a common one across the repo 👍
the MODULE_NAME
export in constants.ts
currently looks like this:
export const MODULE_NAME = 'router';
And still being used in instrumentation here. We cannot utilize the new PACKAGE_NAME
to remove it altogether at the moment.
This PR touches on the topic of "Instrumentation Package" and the MODULE_NAME
we refer to is the "Instrumented Package". In order not to introduce too many things into one PR which can make it harder to review and merge in, I suggest we will target the instrumented package patterns in a follow-up PR, which might also include more cleanups and aligning across the codebase.
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.
Yeah makes sense to have a new PR for the additional cleanup 👍
VERSION, | ||
config | ||
); | ||
super(PACKAGE_NAME, PACKAGE_VERSION, config); |
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.
same as router - As part of this change I think we could remove the MODULE_NAME
constant from the constants.ts
file. Then we can also rename in the init()
there is another constants.MODULE_NAME
.
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.
agree. will handle as follow-up PR
@@ -50,7 +50,7 @@ function defaultShouldPreventSpanCreation() { | |||
* addEventListener of HTMLElement | |||
*/ | |||
export class UserInteractionInstrumentation extends InstrumentationBase { | |||
readonly version = VERSION; | |||
readonly version = PACKAGE_VERSION; |
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 think we should also update the moduleName
here on the next line to be PACKAGE_NAME
. It gets used in the enable()
and disable()
methods.
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.
This suggested change looks right to me, but it will introduce a change to the instrumentation (it's name
) which is probably ok but I don't want to bundle it into this PR, as it will change the scope from refactor
to fix
.
@@ -58,7 +58,7 @@ export class BaseOpenTelemetryComponent extends React.Component { | |||
static setTracer(name: string, version?: string): void { | |||
BaseOpenTelemetryComponent._tracer = api.trace.getTracer( | |||
name, | |||
version ? version : VERSION | |||
version ? version : PACKAGE_VERSION |
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 think we can also update the line higher up in the class for readonly component: string = 'react-load';
to instead be readonly component: string = PACKAGE_NAME;
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.
same comment as above - I support doing this as a dedicated fix
PR which only targets the name of the instrumentation (which is an end user public API content).
@@ -45,8 +45,8 @@ const DEFAULT_CONFIG: types.KnexInstrumentationConfig = { | |||
export class KnexInstrumentation extends InstrumentationBase { | |||
constructor(config: types.KnexInstrumentationConfig = {}) { | |||
super( | |||
`@opentelemetry/instrumentation-${constants.MODULE_NAME}`, | |||
VERSION, | |||
PACKAGE_NAME, |
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.
same as router - As part of this change I think we could remove the MODULE_NAME
constant from the constants.ts
file. Then we can also rename in the init()
there is another constants.MODULE_NAME
.
@JamieDanielson Thanks for another thorough review. You justifiably find many opportunities for further improvement, which I choose to keep out of the scope of this PR so it is very specific on one single change. |
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. As discussed in comments we can do further cleanup in a follow-up PR to minimize scope.
This PR is a suggestion to replace this instrumentation base constructor call:
With this one:
Where the auto generated file
version.ts
will also include the package name frompackage.json
.This PR also rename the cryptic
VERSION
symbol toNPM_PACKAGE_VERSION
which I think is more readable.I think the new format is better since:
package.json
, just like we currently use theVERSION
from package.json in instrumentation base constructor. no room for mistakes or misunderstandings.