forked from signalfx/signalfx-ruby-tracing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfx-rb-trace-bootstrap
executable file
·70 lines (61 loc) · 2.42 KB
/
sfx-rb-trace-bootstrap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby -rrubygems
require 'optparse'
require 'ostruct'
require 'pp'
instrumentations = {
"activerecord" => ["signalfx-activerecord-opentracing", "~> 0.1.0"],
"elasticsearch" => ["signalfx-elasticsearch-instrumentation", "~> 0.2.0"],
"faraday" => ["signalfx-faraday-instrumentation", "~> 0.2.1"],
"grape" => ["signalfx-grape-instrumentation", "~> 0.1.0"],
"mongodb" => ["signalfx-mongodb-instrumentation", "~> 0.1.1"],
"mysql2" => ["signalfx-mysql2-instrumentation", "~> 0.1.1"],
"nethttp" => ["signalfx-nethttp-instrumentation", "~> 0.2.0"],
"pg" => ["signalfx-pg-instrumentation", "~> 0.1.0"],
"rack" => ["signalfx-rack-tracer", "~> 0.1.0"],
"rails" => ["signalfx-rails-instrumentation", "~> 0.2.0"],
"redis" => ["signalfx-redis-instrumentation", "~> 0.1.0"],
"restclient" => ["signalfx-restclient-instrumentation", "~> 0.1.0"],
"sequel" => ["signalfx-sequel-instrumentation", "~> 0.1.0"],
"sidekiq" => ["signalfx-sidekiq-opentracing", "~> 0.1.0"],
"sinatra" => ["signalfx-sinatra-instrumentation", "~> 0.1.0"]
}
options = OpenStruct.new
options.target_libraries = []
parser = OptionParser.new do |opts|
opts.banner = 'Usage: sfx-rb-trace-bootstrap --install-deps [deps]'
opts.on('-l', '--list', 'List available library instrumentations.') do |l|
puts 'Available target libraries:'
pp(instrumentations)
end
opts.on('-i lib1,lib2', '--install-deps lib1,lib2', Array, 'Install instrumentations for target libraries (comma-separated).') do |list|
options.target_libraries = list
end
end
def install_instrumentors(instrumentors, libs)
libs.each do |lib|
if instrumentors.has_key?(lib)
target = instrumentors[lib]
puts %Q{Installing instrumentation for target library "#{lib}": #{target[0]} "#{target[1]}".}
if target[1].respond_to?(:has_key?) && target[1].has_key?(:git)
install_from_git(*target)
else
Gem.install(*target)
end
else
puts %Q{signalfx-tracing has no target library "#{lib}".}
end
end
end
def install_from_git(target, options)
require 'rubygems/package'
rack = Gem::Source::Git.new(target, options[:git], options[:branch] || 'master', true)
rack.checkout
Dir.chdir rack.install_dir do
gs_file = Dir['*.gemspec'][0]
gemspec = Gem::Specification.load(gs_file)
gem = Gem::Package.build gemspec
Gem.install(gem)
end
end
parser.parse(ARGV)
install_instrumentors(instrumentations, options.target_libraries)