Sha256: dadb58c6fa675d265cafa1f85fb040edad0c043222e0cb7dc02d94cb39d1cd6a

Contents?: true

Size: 563 Bytes

Versions: 1

Compression:

Stored size: 563 Bytes

Contents

module Salestation
  class Web < Module
    class StatsdMiddleware

      def initialize(app, statsd, metric:)
        @app = app
        @statsd = statsd
        @metric = metric
      end

      def call(env)
        start = Time.now

        status, header, body = @app.call env

        method, path = env['sinatra.route'].split

        @statsd.timing(@metric, (Time.now - start) * 1000, tags: [
          "path:#{ path }",
          "method:#{ method }",
          "status:#{ status }"
        ])

        [status, header, body]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
salestation-0.1.1 lib/salestation/web/statsd_middleware.rb