Application Performance Monitoring (APM) agent for Node.js applications with transaction tracing, error tracking, custom metrics, and distributed tracing capabilities.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Miscellaneous utility functions for SQL obfuscation, performance tuning, and agent lifecycle management.
Obfuscate SQL queries for security purposes.
/**
* Obfuscate SQL queries for security
* @param {string} sql - SQL statement to obfuscate
* @param {string} dialect - Database dialect ('mysql', 'postgres', 'cassandra', 'oracle')
* @returns {string} Obfuscated SQL with parameters replaced
*/
function obfuscateSql(sql, dialect);Exclude current transaction from Apdex score calculations.
/**
* Ignore current transaction when calculating Apdex score.
* Useful for very short or very long transactions that skew metrics.
*/
function ignoreApdex();Set dispatcher environment information.
/**
* Set dispatcher name and version for environment reporting
* @param {string} name - Dispatcher name (e.g., 'nginx', 'apache')
* @param {string} [version] - Dispatcher version
*/
function setDispatcher(name, version);Gracefully shut down the New Relic agent.
/**
* Gracefully shut down the agent with optional data collection
* @param {object} [options] - Shutdown options
* @param {boolean} [options.collectPendingData] - Send pending data before shutdown
* @param {number} [options.timeout] - Timeout in milliseconds
* @param {boolean} [options.waitForIdle] - Wait for active transactions to complete
* @param {Function} [callback] - Callback executed after shutdown
*/
function shutdown(options, callback);Usage Examples:
const newrelic = require('newrelic');
// Obfuscate SQL for logging
const obfuscated = newrelic.obfuscateSql(
"SELECT * FROM users WHERE id = 123 AND name = 'John'",
'mysql'
);
console.log(obfuscated); // "SELECT * FROM users WHERE id = ? AND name = ?"
// Ignore Apdex for file downloads
app.get('/download/:file', (req, res) => {
newrelic.ignoreApdex(); // Don't include in Apdex calculations
res.download(path.join(__dirname, 'files', req.params.file));
});
// Set dispatcher information
newrelic.setDispatcher('nginx', '1.18.0');
// Graceful shutdown
process.on('SIGTERM', () => {
newrelic.shutdown({
collectPendingData: true,
timeout: 5000,
waitForIdle: true
}, (error) => {
if (error) {
console.error('Error during New Relic shutdown:', error);
} else {
console.log('New Relic agent shut down successfully');
}
process.exit(0);
});
});interface ShutdownOptions {
/** Send pending data to New Relic before shutdown */
collectPendingData?: boolean;
/** Maximum time to wait for shutdown in milliseconds */
timeout?: number;
/** Wait for active transactions to complete before shutdown */
waitForIdle?: boolean;
}