Sha256: cf2ef51cebc992be0baba83d14b6f8cc6d16139f5814d37cdf2d9b3ad1bdbe8a
Contents?: true
Size: 880 Bytes
Versions: 1
Compression:
Stored size: 880 Bytes
Contents
# frozen_string_literal: true require 'uri' require 'net/http' require 'json' module Analytics class Middleware def initialize(app, api_key) @app = app @api_key = api_key end def call(env) start = Time.now status, headers, response = @app.call(env) data = { api_key: @api_key, hostname: env['HTTP_HOST'], path: env['REQUEST_PATH'], user_agent: env['HTTP_USER_AGENT'], method: env['REQUEST_METHOD'], status: status, framework: "Rails", response_time: (Time.now - start).to_f.round, } Thread.new { log_request(data) } [status, headers, response] end private def log_request(data) uri = URI('https://api-analytics-server.vercel.app/api/log-request') res = Net::HTTP.post(uri, data.to_json) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
api_analytics-1.0.3 | lib/api_analytics.rb |