Logging directly to New Relic instead of local log

I want to log some specific events and data to New Relic instead of using the locally hosted log.

How can I acheive this easily and also send JSON payload data?

I have been able to setup the based “MessagingEvent” but I wanted to something a little more advanced.

Or enable the logging via the installed NodeJS agent. But after running the command provided within the APM->Logs.
curl -Ls https://raw.githubusercontent.com/newrelic/newrelic-cli/master/scripts/install.sh | bash && sudo NEW_RELIC_API_KEY=XXXXX-XXXXXXXXXXXXXXXXXXXXXXX NEW_RELIC_ACCOUNT_ID=XXXXXX /usr/local/bin/newrelic install

I get the following
“We encountered an error during the installation: we couldn’t install the Node Agent Installer. Make sure Node is installed and running on this host and rerun the newrelic-cli command. If this problem persists please visit the documentation and support page for additional help here: https://one.newrelic.com/-/06vjAeZLKjP

I find this odd, because I already have it an agent running. However, that API key is different to what is supplied as per the above example.

Please provide information on your environment, and any further information you believe is relevant, such as the below:

  • APM Agent Language - NodeJS
  • APM Agent Version - v6.12.0
  • Operating System - Ubuntu
  • Operating System Version - 16.04.6 LTS
  • Frameworks your app is using - NodeJS
  • A link to the application in the New Relic UI.

Hi, @paul.wilson3: You may call the Log API from your application to send log data directly to New Relic.

Hi Phil,
As per one of these screenshots, I can’t see the log section as it won’t let me install. However, the NodeJS agent is already running. I’m just trying to figure out what is wrong with the setup.

Any ideas on how to overcome this?

Unless you are suggesting that I just push through using the API rather than the agent?


Yes, I am suggesting that you push logs using the API. The only alternative is to write your logs to a file and use a log forwarding plugin to send the logs to New Relic. It is not possible to use APM agents to send logs directly to New Relic.

Hi Phil,

Is there a way to turn on trace to write to log and then forward to New Relic, but ensure that the log file doesn’t become too large?
And I guess regarding the API, would that be under the “Logs” tab and using the “Headerless Log API”?

As per my previous response, when I tried installing the New Relic Infrastructure Agent, it failed. It advised me to look at the log but it has written into an area of the server that even the admin account isn’t allowed access.

Thanks

I think I misunderstood your question. I thought you want to send your application logs to New Relic, but it sounds like you want to send the agent logs to New Relic, is that correct? In that case, using the API is not an option; you will have to let the agent write its logs to disk, then use a log forwarding plugin to send them to New Relic.

I am not aware of a method to limit the size of the agent log file. Perhaps someone else will have a suggestion.

Regarding your difficulty installing the Infrastructure agent, I recommend that you start a separate topic to address that.

I guess I’m looking for the best solution possible to keep all the information together, with the least amount of implementation steps if possible.

We have the NodeJS agent already sending through some default information. But I wanted to send through some additional information which would include outgoing POSTs to a thrid party system.

So I was thinking about potentially utilising one of the inbuilt new agent api hooks.
https://docs.newrelic.com/docs/agents/nodejs-agent/api-guides/nodejs-agent-api/
I have been able to run low level “recordCustomEvent” which has worked but I wanted to explore what additional information/attributes I can set.
image

But I’m not sure if this hook will allow attributes to be set like this.

"attributes": {   
 "action": "login",    
 "user": {        
          "id": 123,        
          "name": "alice"    }
}

Plus this is only available via “Data Query”.

In relation the other issue regarding the installation, I submitted an API requests via POSTMAN and once that was received successfully then the installation screens within the log area disappeared. I guess it is default to include those screens until either the agent is configured or until logs start being sent.

So the API does appear that it will work but will require a number of changes to us rather than using a pre-built hook from the agent. The other issue if I use the API is that within th NewRelic One dashboard it appears in a different section to the APM.