How to use the newrelic.getTransaction function in newrelic

To help you get started, we’ve selected a few newrelic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sergeyksv / tinelic / modules / collect.js View on Github external
newrelic.startBackgroundTransaction('collect:clearCollections', function transactionHandler() {
						const transaction = newrelic.getTransaction();
						let dtlw = new Date(Date.now() - ctx.cfg.app.cleanRetention);
						let q = { _dt: { $lte: dtlw } };
						let collectionsToClear = ['page_errors', 'pages', 'page_reqs', 'actions', 'action_stats', 'action_errors', 'metrics'];
						safe.each(collectionsToClear, async ctc => {
							await collections[ctc].deleteMany(q);
							/* const { deletedCount } = */ await collections[ctc].deleteMany(q);
							/*
							if (deletedCount > 0)
								console.info('cleaned %d documents in collection %s at %s', deletedCount, ctc, new Date());
							*/
						}, err => {
							if (err)
								newrelic.noticeError(err);
							transaction.end();
						});
					});