Created
January 28, 2017 20:43
-
-
Save sunnygleason/95eaef8b3dd4be3ec10f95868d29dd92 to your computer and use it in GitHub Desktop.
PubNub Monitoring BLOCK w/ New Relic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (request) => { | |
var xhr = require('xhr'); | |
var accountId = 'YOUR_ACCOUNT_ID'; | |
var insightsKey = 'YOUR_INSIGHTS_KEY'; | |
var url = 'https://insights-collector.newrelic.com/v1/accounts/' | |
+ accountId + '/events'; | |
var params = { | |
method: 'POST', | |
headers: { | |
'X-Insert-Key': insightsKey, | |
'Content-Type': 'application/json' | |
}, | |
body: request.message | |
}; | |
return xhr.fetch(url, params) | |
.then(function (resp) { | |
request.message.newrelic_result = { | |
headers: resp.headers, | |
result: JSON.parse(resp.body) | |
}; | |
return request.ok(); | |
}).catch((err) => { | |
console.log('error happened for XHR.fetch', err); | |
return request.ok(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment