Skip to content

Commit

Permalink
Integrate otel/jaeger tracing and display
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS committed Jun 4, 2021
1 parent f2847cf commit 74764da
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ gem 'lograge'

gem 'bootsnap', '>= 1.1.0', require: false

gem 'opentelemetry-api'
gem 'opentelemetry-exporter-jaeger'
gem 'opentelemetry-instrumentation-pg'
gem 'opentelemetry-instrumentation-rails'
gem 'opentelemetry-instrumentation-sidekiq'
gem 'opentelemetry-sdk'

group :production do
gem 'pg'
end
Expand Down
35 changes: 35 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,34 @@ GEM
omniauth-oauth2 (1.7.0)
oauth2 (~> 1.4)
omniauth (~> 1.9)
opentelemetry-api (0.17.0)
opentelemetry-common (0.17.0)
opentelemetry-api (~> 0.17.0)
opentelemetry-exporter-jaeger (0.17.0)
opentelemetry-api (~> 0.17.0)
opentelemetry-common (~> 0.17.0)
opentelemetry-sdk (~> 0.17.0)
thrift
opentelemetry-instrumentation-base (0.17.0)
opentelemetry-api (~> 0.17.0)
opentelemetry-instrumentation-pg (0.17.1)
opentelemetry-api (~> 0.17.0)
opentelemetry-instrumentation-base (~> 0.17.0)
opentelemetry-instrumentation-rack (0.17.0)
opentelemetry-api (~> 0.17.0)
opentelemetry-instrumentation-base (~> 0.17.0)
opentelemetry-instrumentation-rails (0.17.0)
opentelemetry-api (~> 0.17.0)
opentelemetry-instrumentation-base (~> 0.17.0)
opentelemetry-instrumentation-rack (~> 0.17.0)
opentelemetry-instrumentation-sidekiq (0.17.0)
opentelemetry-api (~> 0.17.0)
opentelemetry-common (~> 0.17.0)
opentelemetry-instrumentation-base (~> 0.17.0)
opentelemetry-sdk (0.17.0)
opentelemetry-api (~> 0.17.0)
opentelemetry-common (~> 0.17.0)
opentelemetry-instrumentation-base (~> 0.17.0)
parallel (1.19.2)
parser (2.7.1.5)
ast (~> 2.4.1)
Expand Down Expand Up @@ -403,6 +431,7 @@ GEM
text (1.3.1)
thor (1.0.1)
thread_safe (0.3.6)
thrift (0.14.1)
thwait (0.2.0)
e2mmap
tilt (2.0.10)
Expand Down Expand Up @@ -457,6 +486,12 @@ DEPENDENCIES
octokit
oj
omniauth-github
opentelemetry-api
opentelemetry-exporter-jaeger
opentelemetry-instrumentation-pg
opentelemetry-instrumentation-rails
opentelemetry-instrumentation-sidekiq
opentelemetry-sdk
pg
pry-rails
puma (~> 3.12)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ bundle exec rails assets:precompile
rm config/credentials.yml.enc
bundle exec rails credentials:edit
docker-compose up -d postgres
# only required for local debugging
docker-compose up -d jaeger
# db:create will fail if the database already exists, go to the next step if that is the case
RAILS_ENV=development bundle exec rails db:create
RAILS_ENV=development bundle exec rails db:migrate
Expand Down Expand Up @@ -233,6 +235,8 @@ redis:
[Foreman](https://rubygems.org/gems/foreman) will take care of the actual rails
application, but it will also start [sidekiq](https://github.com/mperham/sidekiq#sidekiq).
Connect to the [local jaeger instance](http://localhost:16686) to see traces of what's going on.
## Production Setup
The production setup is a homage to microservices:
Expand Down
15 changes: 15 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

OpenTelemetry::SDK.configure do |c|
require 'pg'
c.use 'OpenTelemetry::Instrumentation::PG'
c.use 'OpenTelemetry::Instrumentation::Rails'
c.use 'OpenTelemetry::Instrumentation::Sidekiq'

c.add_span_processor(
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
OpenTelemetry::Exporter::Jaeger::AgentExporter.new(host: '127.0.0.1', port: 6831)
# Alternatively, for the collector exporter:
# exporter: OpenTelemetry::Exporter::Jaeger::CollectorExporter.new(endpoint: 'http://192.168.0.1:14268/api/traces')
)
)
end

module VoxPupuliTasks
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
Expand Down
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,17 @@ services:
- ./postgres-data:/var/lib/postgresql/data
ports:
- 127.0.0.1:5432:5432
jaeger:
image: jaegertracing/all-in-one:1.22
container_name: jaeger
ports:
- "5775:5775/udp"
- "5778:5778"
- "6831:6831/udp"
- "6832:6832/udp"
- "9411:9411"
- "14268:14268"
- "14250:14250"
- "16686:16686"
environment:
COLLECTOR_ZIPKIN_HOST_PORT: ":9411"

0 comments on commit 74764da

Please sign in to comment.