APMLens Ruby Gem

The official Ruby agent for APMLens.

This gem is designed with the Power Law in mind: It delivers 95% of the monitoring value (Error Tracking + P95 Latency) with < 200 lines of code and zero external dependencies.

Installation

Add this line to your application's Gemfile:

gem 'apmlens', '~> 1.0'

Usage

Rails

It works automatically. Just configure it in config/initializers/apmlens.rb:

Apmlens.configure do |c|
  c.ingestion_key = ENV['APMLENS_KEY']
  c.service = 'my-rails-app'
end

Manual Usage (Ruby Scripts)

require 'apmlens'

# 1. Config
Apmlens.configure do |c|
  c.ingestion_key = 'ik_...'
end

# 2. Track Errors
begin
  risk_method
rescue => e
  Apmlens.capture_error(e, user_id: current_user.id)
end

# 3. Track Metrics (Aggregated automatically)
Apmlens.capture_trace('job.duration', 500)

Architecture

  • In-Memory Buffer: Metrics are aggregated locally (P95, Avg, Max) and flushed once per minute. This solves the "N+1 Query" scalability problem.
  • Non-Blocking: All network calls happen in a background thread. Your app never waits for APMLens.