1 |
|
2 | debug = require('debug')('msgflo:newrelic')
|
3 |
|
4 | try
|
5 | nr = require 'newrelic'
|
6 | catch e
|
7 | debug 'New Relic not enabled', e.toString()
|
8 |
|
9 | class 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 |
|
36 | exports.Transactions = Transactions
|