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: Defining agent api methods for ts types #613

Merged
merged 6 commits into from
Jul 17, 2023

Conversation

patrickhousley
Copy link
Contributor

@patrickhousley patrickhousley commented Jul 12, 2023

Updating the type interface of the Agent and MicroAgent classes to properly expose the agent API methods in the generated typescript types.

Overview

Added a new base agent class that contains stubbed methods for all the agent API methods with proper documentation. The Agent and MicroAgent classes now extend this base class. While this does add code to the bundle and a new inheritance, I could find no other way to expose the API methods on the classes in the generated typescript types and retain the code in javascript.

Related Issue(s)

https://issues.newrelic.com/browse/NR-139951
Closes #608

Testing

Run npm run build:all and start the test server npm run test-server. Once the server is up, access http://bam-test-1.nr-local.net:3333/tests/assets/test-builds/vite-react-wrapper/index.html and verify the interaction name has been updated.

To test other API methods, update tools/test-builds/vite-react-wrapper/src/newrelic.ts and re-run the build.

@patrickhousley patrickhousley added bug Something isn't working small Small Engineering Effort safe to test labels Jul 12, 2023
src/loaders/micro-agent.js Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Jul 12, 2023

Static Badge

Last ran on July 12, 2023 11:02:18 CDT
Checking merge of (dbe93f5) into main (8a6f319)

@github-actions
Copy link

github-actions bot commented Jul 12, 2023

Asset Size Report

Merging this pull request will result in the following CDN asset size changes:

Asset Name Previous Size New Size Diff
nr-loader-spa.min 49.67 kB / 16.93 kB (gzip) 51.01 kB / 17.12 kB (gzip) +2.7% / +1.09% (gzip)
nr-loader-full.min 43.24 kB / 14.97 kB (gzip) 44.58 kB / 15.17 kB (gzip) +3.1% / +1.38% (gzip)
nr-loader-rum.min 26.51 kB / 9.73 kB (gzip) 27.84 kB / 9.92 kB (gzip) +5.05% / +1.98% (gzip)
nr-loader-spa-polyfills.min 122.54 kB / 39.09 kB (gzip) 124.41 kB / 39.44 kB (gzip) +1.53% / +0.9% (gzip)
nr-loader-full-polyfills.min 114.53 kB / 36.99 kB (gzip) 116.41 kB / 37.33 kB (gzip) +1.64% / +0.91% (gzip)
nr-loader-rum-polyfills.min 94.6 kB / 31.25 kB (gzip) 96.45 kB / 31.58 kB (gzip) +1.96% / +1.07% (gzip)
nr-loader-worker.min 39.8 kB / 13.69 kB (gzip) 41.14 kB / 13.9 kB (gzip) +3.36% / +1.54% (gzip)

Merging this pull request will result in the following NPM package consumer size changes:

Asset Name Previous Size New Size Diff
Browser Agent 49.8 kB / 16.8 kB (gzip) 51.14 kB / 17.02 kB (gzip) +2.69% / +1.28% (gzip)
Custom Lite Agent 26.65 kB / 9.64 kB (gzip) 27.99 kB / 9.85 kB (gzip) +5.02% / +2.23% (gzip)
Custom Pro Agent 43.29 kB / 14.78 kB (gzip) 44.63 kB / 15 kB (gzip) +3.1% / +1.48% (gzip)
Custom SPA Agent 49.69 kB / 16.77 kB (gzip) 51.03 kB / 16.98 kB (gzip) +2.7% / +1.24% (gzip)
Worker Agent 303.35 kB / 93.91 kB (gzip) 304.66 kB / 94.11 kB (gzip) +0.43% / +0.21% (gzip)
Other Standard CDN Assets

Released Assets

Asset Name Asset Size
recorder.1b18459f.min.js 166.07 kB / 52.32 kB (gzip)
spa-aggregate.68f643e9.min.js 20.93 kB / 7.42 kB (gzip)
page_view_timing-aggregate.d7fbc4fb.min.js 14.97 kB / 5.43 kB (gzip)
860.e349dcb2.min.js 14.09 kB / 5.27 kB (gzip)
session_trace-aggregate.973a2a56.min.js 12.24 kB / 4.53 kB (gzip)
page_view_event-aggregate.c8b08262.min.js 11.1 kB / 4.19 kB (gzip)
jserrors-aggregate.15addcc3.min.js 9.55 kB / 3.65 kB (gzip)
metrics-aggregate.8f3b1670.min.js 8.56 kB / 2.93 kB (gzip)
646.fd5f577f.min.js 8.04 kB / 3.32 kB (gzip)
session_replay-aggregate.d2c35ed3.min.js 7.97 kB / 2.93 kB (gzip)
ajax-aggregate.449a907c.min.js 7.13 kB / 3.06 kB (gzip)
compressor.ae9f91a8.min.js 7.09 kB / 3.57 kB (gzip)
page_action-aggregate.da8a4bbf.min.js 4.73 kB / 1.92 kB (gzip)
async-api.30bd804e.min.js 2.92 kB / 1.46 kB (gzip)
session-manager.2a64278a.min.js 1.47 kB / 740 B (gzip)
lazy-feature-loader.94d9d1a8.min.js 1.17 kB / 498 B (gzip)

Built Assets

Asset Name Asset Size
recorder.1b18459f.min.js 166.07 kB / 52.32 kB (gzip)
spa-aggregate.68f643e9.min.js 20.93 kB / 7.42 kB (gzip)
page_view_timing-aggregate.d7fbc4fb.min.js 14.97 kB / 5.43 kB (gzip)
860.e349dcb2.min.js 14.09 kB / 5.27 kB (gzip)
session_trace-aggregate.973a2a56.min.js 12.24 kB / 4.53 kB (gzip)
page_view_event-aggregate.c8b08262.min.js 11.1 kB / 4.19 kB (gzip)
jserrors-aggregate.15addcc3.min.js 9.55 kB / 3.65 kB (gzip)
metrics-aggregate.8f3b1670.min.js 8.56 kB / 2.93 kB (gzip)
646.fd5f577f.min.js 8.04 kB / 3.32 kB (gzip)
session_replay-aggregate.29998cae.min.js 7.94 kB / 2.91 kB (gzip)
ajax-aggregate.449a907c.min.js 7.13 kB / 3.06 kB (gzip)
compressor.ae9f91a8.min.js 7.09 kB / 3.57 kB (gzip)
page_action-aggregate.da8a4bbf.min.js 4.73 kB / 1.92 kB (gzip)
async-api.30bd804e.min.js 2.92 kB / 1.46 kB (gzip)
session-manager.2a64278a.min.js 1.47 kB / 740 B (gzip)
lazy-feature-loader.94d9d1a8.min.js 1.17 kB / 498 B (gzip)
Other Polyfill CDN Assets

Released Assets

Asset Name Asset Size
recorder.1b18459f-es5.min.js 166.76 kB / 52.35 kB (gzip)
nr-polyfills.min.js 52.15 kB / 17.95 kB (gzip)
session_trace-aggregate.c6e2d80e-es5.min.js 32.26 kB / 8.5 kB (gzip)
compressor.79fb47d9-es5.min.js 30.02 kB / 11.29 kB (gzip)
spa-aggregate.cf7614a6-es5.min.js 24.02 kB / 8.11 kB (gzip)
session_replay-aggregate.a08aab5e-es5.min.js 19.27 kB / 6.54 kB (gzip)
page_view_timing-aggregate.4cf1986a-es5.min.js 18.67 kB / 6.17 kB (gzip)
173.71bbedb0-es5.min.js 17.41 kB / 6.14 kB (gzip)
page_view_event-aggregate.7a2d4522-es5.min.js 12.64 kB / 4.8 kB (gzip)
jserrors-aggregate.d1e7ac8a-es5.min.js 12.33 kB / 4.4 kB (gzip)
385.1f3686e5-es5.min.js 10.62 kB / 4.16 kB (gzip)
ajax-aggregate.34fb41fa-es5.min.js 10.58 kB / 3.78 kB (gzip)
metrics-aggregate.9be0ba0b-es5.min.js 9.91 kB / 3.35 kB (gzip)
page_action-aggregate.710c9b26-es5.min.js 7.33 kB / 2.64 kB (gzip)
async-api.2b4763c8-es5.min.js 4.16 kB / 1.99 kB (gzip)
session-manager.ae4f9cf3-es5.min.js 1.7 kB / 785 B (gzip)
lazy-feature-loader.60c98be9-es5.min.js 1.2 kB / 509 B (gzip)

Built Assets

Asset Name Asset Size
recorder.1b18459f-es5.min.js 166.76 kB / 52.35 kB (gzip)
nr-polyfills.min.js 52.15 kB / 17.95 kB (gzip)
session_trace-aggregate.c6e2d80e-es5.min.js 32.26 kB / 8.5 kB (gzip)
compressor.79fb47d9-es5.min.js 30.02 kB / 11.29 kB (gzip)
spa-aggregate.cf7614a6-es5.min.js 24.02 kB / 8.11 kB (gzip)
session_replay-aggregate.307e7ec3-es5.min.js 19.24 kB / 6.52 kB (gzip)
page_view_timing-aggregate.4cf1986a-es5.min.js 18.67 kB / 6.17 kB (gzip)
173.71bbedb0-es5.min.js 17.41 kB / 6.14 kB (gzip)
page_view_event-aggregate.7a2d4522-es5.min.js 12.64 kB / 4.8 kB (gzip)
jserrors-aggregate.d1e7ac8a-es5.min.js 12.33 kB / 4.4 kB (gzip)
385.1f3686e5-es5.min.js 10.62 kB / 4.16 kB (gzip)
ajax-aggregate.34fb41fa-es5.min.js 10.58 kB / 3.78 kB (gzip)
metrics-aggregate.9be0ba0b-es5.min.js 9.91 kB / 3.35 kB (gzip)
page_action-aggregate.710c9b26-es5.min.js 7.33 kB / 2.64 kB (gzip)
async-api.2b4763c8-es5.min.js 4.16 kB / 1.99 kB (gzip)
session-manager.ae4f9cf3-es5.min.js 1.7 kB / 785 B (gzip)
lazy-feature-loader.60c98be9-es5.min.js 1.2 kB / 509 B (gzip)

@codecov
Copy link

codecov bot commented Jul 12, 2023

Codecov Report

Merging #613 (45c63ec) into main (656e5b6) will decrease coverage by 0.27%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #613      +/-   ##
==========================================
- Coverage   67.00%   66.73%   -0.27%     
==========================================
  Files         129      130       +1     
  Lines        5979     6003      +24     
  Branches     1137     1137              
==========================================
  Hits         4006     4006              
- Misses       1608     1632      +24     
  Partials      365      365              
Flag Coverage Δ
jest-component 21.17% <0.00%> (-0.12%) ⬇️
jest-unit 22.29% <0.00%> (-0.13%) ⬇️

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

Impacted Files Coverage Δ
src/loaders/agent-base.js 0.00% <0.00%> (ø)
src/loaders/agent.js 37.50% <0.00%> (-5.36%) ⬇️
src/loaders/micro-agent.js 0.00% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@patrickhousley patrickhousley merged commit 14d4294 into main Jul 17, 2023
@patrickhousley patrickhousley deleted the fix-agent-api-interface branch July 17, 2023 17:16
@jamesarosen
Copy link

I could find no other way to expose the API methods on the classes in the generated typescript types and retain the code in javascript.

This is a very elegant use of the abstract base class pattern. Well done 👏

Comment on lines +65 to +66
* @param {string} key Used as the attribute name on the BrowserInteraction event.
* @param {any} key Used as the attribute value on the BrowserInteraction event. This can be a string, number, boolean, or object. If it is an object, New Relic serializes it to a JSON string.

Choose a reason for hiding this comment

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

Screenshot 2023-08-03 at 13 14 52 Breaks TypeScript

* @property {createTracer} createTracer
* @property {end} end
* @property {getContext} getContext
* @property {ignore} ignore

Choose a reason for hiding this comment

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

Breaks TypeScript:
Screenshot 2023-08-03 at 13 16 23

@villelahdenvuo
Copy link

@patrickhousley I had some TS issues after updating...

@patrickhousley
Copy link
Contributor Author

Thanks @villelahdenvuo I guess I was half asleep when I wrote that 😥 I will get a fix put in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working small Small Engineering Effort
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Property 'noticeError' does not exist on type 'MicroAgent'
4 participants