Logging With New Relic for Mulesoft APIs
In this article, you will learn what New Relic is and how to easily send logs to New Relic from MuleSoft by using the HTTP Appender.
Join the DZone community and get the full member experience.
Join For FreeWhat Is New Relic?
New Relic is a web application performance service designed to figure in real-time together with your live web app. New Relic Infrastructure provides flexible, dynamic server monitoring. You can see the important performance data of your app in New Relic, like browser reaction time by geography and browser type, web transactions in real-time, etc.
Steps to Registering With New Relic
- Go to https://newrelic.com/
- Click on Sign Up if you do not have an account already.
Login to New Relic
- Go to https://newrelic.com/
- Click on Login.
- Provide your credentials.
- Go to More -> Insights -> Manage data --> Click on the “+” icon in front of Insert Keys.
- Get the accountId and insert the key on your screen.
- Save your Key and Account ID.
Steps to Enable Logging into the Mulesoft Application
In Anypoint Studio, go to Project.
Add these details in logger: (Logger, Custom Apisero Logger).
The logger should contain the eventType field.
xxxxxxxxxx
{
"severity": "LOW",
"eventType": "InsightsLogs",
"env": "DEV",
"messageId": "7238-8580565-84859-4858",
"muleAppName": "new-relic-insights",
"CreationDate": "2021-01-17T10:22:33",
"payload": "payload",
"result": "Success",
"endpoint": "/api/first"
}
Open: src/main/resources/log4j2.xml and add the below XML tag in Configuration/Appenders
xxxxxxxxxx
<Http name="NEWRELIC" url="https://insights-collector.newrelic.com/v1/accounts/<accountId>/events">
<Property name="X-insert-Key" value="<apiKey>" />
<Property name="Content-Type" value="application/json" />
<PatternLayout pattern="%m%n"></PatternLayout>
</Http>
The URL should follow the below format:
<AppenderRef ref="NEWRELIC" />
Now, Run Application.
See the Console Log.
View the Logs in New Relic
- Go to https://newrelic.com/
- Go to the Data Explorer.
- Type the NRQL Query: Select * from Insightslogs.
- Go to the right next tab to the open window and you can see the logs.
Opinions expressed by DZone contributors are their own.
Comments