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

chore: Refactor specs into classes for easier code navigation #2004

Merged
merged 20 commits into from Feb 13, 2024

Conversation

jsumners-nr
Copy link
Contributor

@jsumners-nr jsumners-nr commented Feb 7, 2024

Instrumentations utilize a "spec" object to provide a sort of DSL to the shimming library. There are several specific types of specs, which are documented at shim.js:275. There is also a set of utility functions for generating specs defined at specs/index.js. However, the utility methods are rarely used. The most prevalent pattern throughout the codebase is to create spec with object literals, utilizing hard gained knowledge about what a spec looks like and which one would be appropriate for the situation.

My purpose here has been to research the how specs are utilized to determine which parts are actually used and codify them in easier to understand, and document, explicit objects.

This PR resolves issue #2006.

@jsumners-nr jsumners-nr marked this pull request as ready for review February 7, 2024 18:54
Copy link

codecov bot commented Feb 8, 2024

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (a89def8) 97.03% compared to head (0038778) 97.10%.
Report is 4 commits behind head on main.

Files Patch % Lines
lib/instrumentation/express.js 86.56% 9 Missing ⚠️
lib/shim/specs/transaction.js 96.15% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2004      +/-   ##
==========================================
+ Coverage   97.03%   97.10%   +0.07%     
==========================================
  Files         224      239      +15     
  Lines       40864    41020     +156     
==========================================
+ Hits        39652    39834     +182     
+ Misses       1212     1186      -26     
Flag Coverage Δ
integration-tests-16.x 78.77% <84.34%> (-0.08%) ⬇️
integration-tests-18.x 78.76% <75.17%> (?)
integration-tests-20.x 78.75% <75.17%> (?)
unit-tests-16.x 91.07% <92.81%> (-0.05%) ⬇️
unit-tests-18.x 90.97% <89.84%> (?)
unit-tests-20.x 90.97% <89.84%> (?)
versioned-tests-16.x 74.94% <97.54%> (+0.77%) ⬆️
versioned-tests-18.x 74.96% <97.54%> (?)
versioned-tests-20.x 74.97% <97.54%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bizob2828 bizob2828 self-assigned this Feb 8, 2024
Copy link
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

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

great work. hopefully this provides clarity for devs. also might be good to cut other tickets in a feature to update all instrumentation to make sure it uses a spec instead of returning a plain object that aligns with some spec. lastly, we talked in zoom but lib/shim/shim.js needs some cleanup on some of these redundant interface defintions.

.eslintrc.js Show resolved Hide resolved
.eslintrc.js Show resolved Hide resolved
lib/shim/shim.js Outdated Show resolved Hide resolved
lib/shim/specs/message.js Outdated Show resolved Hide resolved

/**
* A callback invoked after an instrumented function has completed its work.
* The instrumented function must have been invoked synchronously.
Copy link
Member

Choose a reason for hiding this comment

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

This applies to any type of instrumented function. It's just that the after function must be sync. it could have async operations in it but it won't do the right thing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have some alternative text in mind? The current text is almost a verbatim copy of what existed in the original jsdoc.

lib/shim/specs/recorder.js Outdated Show resolved Hide resolved
lib/shim/specs/middleware.js Outdated Show resolved Hide resolved
lib/shim/specs/middleware.js Outdated Show resolved Hide resolved
lib/shim/specs/middleware.js Outdated Show resolved Hide resolved
lib/shim/specs/recorder.js Show resolved Hide resolved
@jsumners-nr jsumners-nr marked this pull request as draft February 9, 2024 15:20
@jsumners-nr jsumners-nr marked this pull request as ready for review February 9, 2024 15:35
@jsumners-nr jsumners-nr force-pushed the spec-constructor branch 2 times, most recently from b298b52 to b04a1f6 Compare February 9, 2024 16:45
Copy link
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

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

this is a great start. i linked 2 places where you couldn't find data types. we're close to landing this one

* Extra parameters which may be added to an operation or query segment. All of
* these properties are optional.
*
* @typedef {object} DatastoreParameters
Copy link
Member

Choose a reason for hiding this comment

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

this is great. we may want to file a follow up as there are other parameters types for message queues, and webframework

lib/shim/specs/message.js Outdated Show resolved Hide resolved
lib/shim/specs/middleware.js Outdated Show resolved Hide resolved
Copy link
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

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

I know this was a lot of work but should help clarify a lot for engineers and using shim to instrument with our specs. very nice 👏🏻

@jsumners-nr jsumners-nr merged commit 4daedc0 into newrelic:main Feb 13, 2024
22 checks passed
Node.js Engineering Board automation moved this from Needs PR Review to Done: Issues recently completed Feb 13, 2024
@jsumners-nr jsumners-nr deleted the spec-constructor branch February 13, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Node.js Engineering Board
  
Done: Issues recently completed
Development

Successfully merging this pull request may close these issues.

None yet

2 participants