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

Failed to instrument module @redis/client #2012

Closed
MartinKolarik opened this issue Feb 12, 2024 · 7 comments · Fixed by #2014
Closed

Failed to instrument module @redis/client #2012

MartinKolarik opened this issue Feb 12, 2024 · 7 comments · Fixed by #2014
Assignees
Labels

Comments

@MartinKolarik
Copy link

Description

When starting the app, I get the following warning:

{
"msg": "Failed to instrument module client using [...]\\node_modules\\newrelic\\lib\\instrumentation\\@redis\\client.js",
"component": "shimmer",
"stack": "TypeError: Cannot read properties of null (reading 'default')\n
    at initialize ([...]\\node_modules\\newrelic\\lib\\instrumentation\\@node-redis\\client.js:12:75)
    at _firstPartyInstrumentation ([...]\\node_modules\\newrelic\\lib\\shimmer.js:698:29)
    at loadInstrumentation ([...]\\node_modules\\newrelic\\lib\\shimmer.js:662:25)
    at [...]\\node_modules\\newrelic\\lib\\shimmer.js:573:14
    at Array.forEach (<anonymous>)
    at instrumentPostLoad ([...]\\node_modules\\newrelic\\lib\\shimmer.js:538:20)
    at _postLoad ([...]\\node_modules\\newrelic\\lib\\shimmer.js:722
:12)
    at onHook ([...]\\node_modules\\newrelic\\lib\\shimmer.js:366:14)
    at Hook._require.Module.require ([...]\\node_modules\\require-in-the-middle\\index.js:262:28)
    at require (node:internal/modules/helpers:130:18)",
"message": "Cannot read properties of null (reading 'default')"
}

Expected Behavior

The module is instrumented without errors.

Troubleshooting or NR Diag results

After a quick look at the relevant code, I see there's an attempt to load dist/lib/client/commands.js from @redis/client, but the shim object that does the loading has _moduleRoot set to node_modules/@redis (without /client) for some reason, so this fails:

image

I tried changing the require call from shim.require('dist/lib/client/commands.js') to shim.require('client/dist/lib/client/commands.js')
and that fixes the issue - but not sure, it seems the real issue is the wrong shimmer root.

Steps to Reproduce

Your Environment

  • Redis: 4.6.13
  • Newrelic: 11.10.3
  • Node version: v20.8.1
  • Operating System and version: Windows 11

Additional context

@workato-integration
Copy link

@newrelic-node-agent-team newrelic-node-agent-team added this to Triage Needed: Unprioritized Features in Node.js Engineering Board Feb 12, 2024
@jsumners-nr
Copy link
Contributor

👋 thank you for the report. Please provide a minimal reproducible example. Doing so will help us diagnose the issue. It should be the bare minimum code needed to trigger the issue, and easily runnable without any changes or extra code.

You may use a GitHub repository to host the code if it is too much to fit into a code block (or two).

@MartinKolarik
Copy link
Author

@jsumners-nr using the packages specified above:

// app.js
import { createClient } from 'redis';
node --experimental-loader newrelic/esm-loader.mjs -r newrelic app.js

@bizob2828
Copy link
Member

@MartinKolarik thanks! I can reproduce your issue on windows. We will investigate a fix and get back to you, sorry for your troubles.

@bizob2828 bizob2828 self-assigned this Feb 12, 2024
@bizob2828 bizob2828 moved this from Triage Needed: Unprioritized Features to In progress: Issues being worked on in Node.js Engineering Board Feb 12, 2024
@bizob2828
Copy link
Member

Triage notes:

It looks like our logic to determine the _moduleRoot for a shim instance is flawed on windows.

On unix:

{"v":0,"level":20,"name":"newrelic","hostname":"TK46XHNX04","pid":96221,"time":"2024-02-12T17:14:55.183Z","msg":"BOB DEBUG /Users/revans/code/redis-app/node_modules/@redis/client, dist/lib/client/commands.js","component":"Shim"}

On windows:

{"v":0,"level":20,"name":"newrelic","hostname":"node-test-vm","pid":7192,"time":"2024-02-12T17:12:50.899Z","msg":"BOB-DEBUG C:\\Users\\node_admin\\test\\node_modules\\@redis dist/lib/client/commands.js","component":"Shim"}

@bizob2828 bizob2828 moved this from In progress: Issues being worked on to Needs PR Review in Node.js Engineering Board Feb 12, 2024
Node.js Engineering Board automation moved this from Needs PR Review to Done: Issues recently completed Feb 13, 2024
@bizob2828
Copy link
Member

@MartinKolarik this was released yesterday in 11.10.4, can you verify this fixes your issue?

@MartinKolarik
Copy link
Author

@bizob2828 yes, fixed, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Node.js Engineering Board
  
Done: Issues recently completed
3 participants