Skip to content

Instantly share code, notes, and snippets.

View stympy's full-sized avatar

Benjamin Curtis stympy

View GitHub Profile
@stympy
stympy / server.cr
Created January 14, 2025 14:32
Reporting events to Honeybadger Insignts from Crystal
require "http/server"
require "honeybadger"
Honeybadger.configure do |config|
config.api_key = "replaceme"
config.environment = "production"
end
server = HTTP::Server.new do |context|
context.response.content_type = "text/plain"
@stympy
stympy / Caddyfile
Last active December 4, 2024 00:41
Serving secure customer domains with Caddy - the tech behind https://www.honeybadger.io/tour/status-pages/
{
# Caddy is running behind an application load balancer hosted at AWS, so this configures Caddy to trust the headers set by it
servers {
trusted_proxies static private_ranges
}
# Avoid DoS attacks by confirming with a backend app that a requested domain should have an on-demand certificate generated
on_demand_tls {
ask http://web.internal:5000/confirm_domain
interval 1m
@stympy
stympy / application_controller.rb
Created November 5, 2024 11:58
Add controller data to process_action.action_controller events sent to Insights
class ApplicationController < ActionController::Base
# ...
private
def append_info_to_payload(payload)
super
payload[:user_id] = current_user&.id
end
end
@stympy
stympy / honeybadger.yml
Created November 5, 2024 11:57
Ignore most Rails instrumentation in Insights
events:
ignore:
- !ruby/regexp '/(send_file|redirect_to|halted_callback|unpermitted_parameters)\.action_controller/'
- !ruby/regexp '/(write_fragment|read_fragment|expire_fragment|exist_fragment\?)\.action_controller/'
- !ruby/regexp '/cache_(read|generate|fetch_hit|write|increment|decrement|delete|cleanup|prune|exist\?)\.active_support/'
- !ruby/regexp '/cache_(read_multi|write_multi|delete_multi\?)\.active_support/'
- !ruby/regexp '/^render_(template|partial|collection)\.action_view/'
- !ruby/regexp '/sql.active_record/'
- !ruby/regexp '/process.action_mailer/'
- !ruby/regexp '/(service_upload|service_download)\.active_storage/'
@stympy
stympy / honeybadger.rb
Created August 28, 2024 20:42
Populate additional info for every event sent to Honeybadger Insights
# config/initializers/honeybadger.rb
Honeybadger.configure do |config|
config.before_event do |event|
if (environment = ENV["HONEYBADGER_ENV"].presence || ENV["RAILS_ENV"].presence)
event[:environment] = environment
end
event[:user] = { name: Current.user.name, email: Current.user.email } if Current.user
end
end
@stympy
stympy / honeybadger.rb
Created July 12, 2024 19:32
Filtering and truncating SQL before reporting to Insights
# config/initializers/honeybadger.rb
Honeybadger.configure do |config|
config.before_event do |event|
# DB-backed job backends can generate a lot of useless queries
if event.event_type == "sql.active_record" && event[:query]&.match?(/good_job|solid_queue/)
event.halt!
end
# Truncate long queries
if event.event_type == "sql.active_record" && event[:query].present?
@stympy
stympy / esbuild.js
Created July 1, 2024 16:32
Config for esbuild in a Rails app
const path = require("path");
const esbuild = require("esbuild");
esbuild
.build({
entryPoints: ["application.js"],
bundle: true,
outdir: path.join(process.cwd(), "app/assets/builds"),
absWorkingDir: path.join(process.cwd(), "app/assets/packs"),
minify: process.env.RAILS_ENV == "production",
@stympy
stympy / install_vector.sh
Last active April 8, 2025 17:40
Honeybadger Insights config for Hatchbox.io
#!/bin/bash
if [ "$UID" == "0" ]; then
sudo_cmd=''
else
sudo_cmd='sudo'
fi
bash -c "$(curl -sL https://setup.vector.dev)"
[api]
enabled = true
address = "0.0.0.0:8686"
[sources.fly_log_metrics]
type = "internal_metrics"
[sources.sandwich]
type = "nats"
url = "nats://[fdaa::3]:4223"
@stympy
stympy / metrics.rb
Last active April 3, 2023 13:54
Rack middleware to send request metrics to CloudWatch Metrics
require "aws-sdk-cloudwatch"
require "descriptive_statistics/safe"
class CloudWatchMetricsMiddleware
def initialize(app, opts = {})
@app = app
@client = Aws::CloudWatch::Client.new(region: opts[:region] || "us-east-1")
@counts = Queue.new
@timings = Queue.new
@mutex = Mutex.new