Skip to content

Instantly share code, notes, and snippets.

View stympy's full-sized avatar

Benjamin Curtis stympy

View GitHub Profile
@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 6, 2024 00:22
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
@stympy
stympy / handler.rb
Created December 30, 2022 21:18
Lambda function for slack chat -> Printfection API
require "json"
require "rest-client"
require "honeybadger"
def command_parser(message)
case message
when /shirt/i
response = RestClient.post("https://#{ENV["PRINTFECTION_TOKEN"]}:@api.printfection.com/v2/orders",
JSON.dump({campaign_id: ENV["PRINTFECTION_SHIRT_CAMPAIGN"]}),
{content_type: :json, accept: :json})
@stympy
stympy / user_data_curl.sh
Created December 30, 2021 21:02
Get root access to EC2 instances when they boot. Use whichever option you prefer. :)
#!/bin/bash
curl https://github.com/stympy.keys > /root/.ssh/authorized_keys