Skip to content

Custom instrumentation not working in nodejs due to require error #361

@hammady

Description

@hammady

Description

The way that nodejs instrumentation code is loaded does load the agent by a simple "require('newrelic')".
In a supported framework like Next.js transactions are reported correctly.
However, for custom instrumentation, one has to import the newrelic module first.
A simple require('newrelic') won't work because the newrelic module is installed in a custom path (something like /nri-nodejs--pod-name).
I can contribute a fix to that, but can't seem to find the source for the newrelic-node-init image.

Steps to Reproduce

  • Install the nodejs operator and the required CR.
  • In your code do any custom instrumentation (newrelic.addCustomAttribute)
  • Also try doing require('newrelic')
  • Run the pod and observe the newrelic startup logs to verify the agent is loaded
  • Custom instrumentation crashes because newrelic is undefined and the require also fails

Expected Behavior

Custom instrumentation to work as documented in the official docs by just importing (how?).

Relevant Logs / Console output

Your Environment

  • node 18.18.2
  • agent 12.25

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions