# All files / src/middleware retrieveTCPTransaction.coffee

64.29% Statements 9/14
100% Branches 0/0
0% Functions 0/1
64.29% Lines 9/14

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    221x

    1x
    1x
    1x
    1x
    1x

    1x
    1x

    1x

     tcpAdapter = require '../tcpAdapter'

    config = require '../config/config'
    statsdServer = config.get 'statsd'
    application = config.get 'application'
    SDC = require 'statsd-client'
    os = require 'os'

    domain = "#{os.hostname()}.#{application.name}.appMetrics"
    sdc = new SDC statsdServer

    exports.koaMiddleware = (next) ->
      startTime = new Date() if statsdServer.enabled
      # the body contains the key
      transaction = tcpAdapter.popTransaction this.body

      this.body = transaction.data
      this.authorisedChannel = transaction.channel

      sdc.timing "#{domain}.retrieveTCPTransactionMiddleware", startTime if statsdServer.enabled
      yield next