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: Updated instrumentation registration to allow for instrumenting of a local file that does not exist within node_modules. You must pass in absolutePath with the absolute path to the file that is being instrumented along with the moduleName which in this case is just the file name without the extension #1974

Merged
merged 1 commit into from Jan 25, 2024

Conversation

bizob2828
Copy link
Member

Description

We tried to add instrumentation for local files. This was done in [messaging-app] but was using v9.x of the agent. In v11.0.0 we now use require-in-the-middle for instrumenting CJS, which requires additional work to instrument files that are not within a 3rd party module. This PR fixes that by providing a new absolutePath key:

'use strict'

const newrelic = require('newrelic')
const niftyPath = require.resolve('./nifty-messages')

newrelic.instrumentMessages({ absolutePath: niftyPath, moduleName: 'nifty-messages', onRequireHandler)

How to Test

node test/integration/module-loading/module-loading.tap.js adds a new test for this.

Related Issues

Closes #1973

Copy link

codecov bot commented Jan 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5d0ebcd) 97.04% compared to head (a54b6c7) 97.04%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1974   +/-   ##
=======================================
  Coverage   97.04%   97.04%           
=======================================
  Files         218      218           
  Lines       40451    40457    +6     
=======================================
+ Hits        39255    39261    +6     
  Misses       1196     1196           
Flag Coverage Δ
integration-tests-16.x 78.91% <100.00%> (+0.01%) ⬆️
integration-tests-18.x 79.16% <100.00%> (+<0.01%) ⬆️
integration-tests-20.x 79.18% <100.00%> (+<0.01%) ⬆️
unit-tests-16.x 91.14% <100.00%> (+<0.01%) ⬆️
unit-tests-18.x 91.13% <100.00%> (+<0.01%) ⬆️
unit-tests-20.x 91.13% <100.00%> (+<0.01%) ⬆️
versioned-tests-16.x 74.07% <100.00%> (-0.02%) ⬇️
versioned-tests-18.x 74.09% <100.00%> (-0.02%) ⬇️
versioned-tests-20.x 74.10% <100.00%> (-0.02%) ⬇️

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.

…of a local file that does not exist within node_modules. You must pass in `absolutePath` with the absolute path to the file that is being instrumented along with the moduleName which in this case is just the file name without the extension
@svetlanabrennan svetlanabrennan merged commit f545b4e into newrelic:main Jan 25, 2024
22 checks passed
Node.js Engineering Board automation moved this from Needs PR Review to Done: Issues recently completed Jan 25, 2024
svetlanabrennan pushed a commit to svetlanabrennan/node-newrelic that referenced this pull request Feb 15, 2024
…of a local file that does not exist within node_modules. You must pass in `absolutePath` with the absolute path to the file that is being instrumented along with the moduleName which in this case is just the file name without the extension (newrelic#1974)
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.

Unable to instrument files that are not an npm package
2 participants