Warning Please note that using a custom interceptor is unnecessary when instrumenting with the latest versions of the New Relic Node agent. In fact, using a custom interceptor may cause conflicts and lead to unexpected behavior (starting with 10.1.0 released May 4th, 2023). Please see instead this example on how to enable New Relic instrumentation for Nest.js. That said, you can still use this repository to experiment with NestJs and the New Relic agent, and easily send data to the New Relic platform.
The above diagram shows the (dockerized) architecture of the example app with the following components:
nest network
- where all the microservices resideparent
container - the outer leftchild
container - in the middle- booth
parent
andchild
have New Relic NodeJs Agent installed (and required by each of the microservices)
- New Relic Account (sign up here)
- New Relic License Key (find instructions here)
- Docker` is installed on your machine.
Find two newrelic.ts
config file in /src
directory inside both parent
and child
Change two config variables in each file
app_name: ['YOUR_APP_NAME'],
license_key: 'YOUR_LICENSE_KEY'
to a desired app_name
and paste your New Relic License Key acquired in previous steps to license_key
variable.
Run docker-compose up
and wait for all images to install and start the app.
The parent
service has the following endpoints:
- GET
localhost:3000/
- just to confirm the app works
- POST
localhost:3000/cats/create
- to create a cat
- with a json body payload containing 3 properties
name
,age
&breed
// for example { "name": "Tom", "age": 3, "breed": "Persian" }
- GET
localhost:3000/cats/getAll
- to get all cats
Call any of these endpoints and you'll see a message (similar to the one below) in the console:
This particular example is a console log showing the flow of the GET localhost:3000/cats/create
request. It's visible that parent
calls child
and gets a response back
intercepting child
's response carrying a mongodb
record being created by child
's interaction with mongodb
service.
Once you make a few calls, go to you New Relic account where the app data is being send and navigate to Explorer
and find the app (by the name you gave it to during the setup)
Go to Distributed Tracing
and click on one of Root Entry Spans
You should be able to see Distributed Tracing
spans captureg by New Relic Agents installed in both parent
and child
We encourage your contributions to improve New Relic NestJs Integration Example! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at [email protected].
A note about vulnerabilities
As noted in our security policy, New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.
If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through HackerOne.
New Relic NestJs Integration Example is licensed under the Apache 2.0 License.