UNPKG

830 Btext/coffeescriptView Raw
1
2debug = require('debug')('msgflo:newrelic')
3
4try
5 nr = require 'newrelic'
6catch e
7 debug 'New Relic not enabled', e.toString()
8
9class Transactions
10 constructor: (@definition) ->
11 @transactions = {}
12
13 open: (id, port) ->
14 return if not nr?
15 @transactions[id] =
16 id: id
17 start: Date.now()
18 inport: port
19
20 close: (id, port) ->
21 return if not nr?
22 transaction = @transactions[id]
23 if transaction
24 duration = Date.now()-transaction.start
25 event =
26 role: @definition.role
27 component: @definition.component
28 inport: transaction.inport
29 outport: port
30 duration: duration
31 name = 'MsgfloJobCompleted'
32 nr.recordCustomEvent name, event
33 debug 'recorded event', name, event
34 delete @transactions[id]
35
36exports.Transactions = Transactions