Skip to content

Commit

Permalink
feat: optionally allow APM using Sentry via env variable (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
gildesmarais authored Nov 2, 2024
1 parent 59aea14 commit 94477d5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ group :test do
gem 'vcr'
gem 'webmock'
end

group :sentry do
gem 'sentry-ruby'
gem 'stackprof'
end
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,17 @@ GEM
sanitize (6.1.3)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
sentry-ruby (5.21.0)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
ssrf_filter (1.1.2)
stackprof (0.2.26)
thor (1.3.2)
tilt (2.4.0)
tzinfo (2.0.6)
Expand Down Expand Up @@ -185,8 +189,10 @@ DEPENDENCIES
rubocop-rake
rubocop-rspec
rubocop-thread_safety
sentry-ruby
simplecov
ssrf_filter
stackprof
tilt
vcr
webmock
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ If you're going to host a public instance, _please, please, please_:
| `RACK_TIMEOUT_SERVICE_TIMEOUT` | default: 15 |
| `WEB_CONCURRENCY` | default: 2 |
| `WEB_MAX_THREADS` | default: 5 |
| | |
| `SENTRY_DSN` | no default. |

### Runtime monitoring via `GET /health_check.txt`

Expand All @@ -181,6 +183,10 @@ Create a monitor of type _Keyword_ with this information and make it aware of yo

![A screenshot showing the Keyword Monitor: a name, the instance's URL to /health_check.txt, and an interval.](docs/uptimerobot_monitor.jpg)

### Application Performance Monitoring using Sentry

When you specify `SENTRY_DSN` in your environment variables, the application will be setup to use Sentry.

## Setup for development

Check out the git repository and…
Expand Down
25 changes: 24 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,31 @@ require 'rubygems'
require 'bundler/setup'
require 'rack-timeout'

dev = ENV.fetch('RACK_ENV', nil) == 'development'
if ENV.key?('SENTRY_DSN')
Bundler.require(:sentry)
require 'sentry-ruby'

Sentry.init do |config|
config.dsn = ENV.fetch('SENTRY_DSN')

# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
# We recommend adjusting this value in production.
config.traces_sample_rate = 1.0
# or
# config.traces_sampler = lambda do |_context|
# true
# end
# Set profiles_sample_rate to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
config.profiles_sample_rate = 1.0
end

use Sentry::Rack::CaptureExceptions
end

dev = ENV.fetch('RACK_ENV', nil) == 'development'
requires = Dir['app/**/*.rb']

if dev
Expand Down

0 comments on commit 94477d5

Please sign in to comment.