splunk-tracer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f993c02bcf4f1f7390bf432557391ac09f411cb
4
+ data.tar.gz: 339e5a39c87a37e4595c00cdebbaa719fb21fc6c
5
+ SHA512:
6
+ metadata.gz: 3d40f3c5d9c7147a4cf6895fd796dcf2d8ee81b2b3d3ee7c26ac5b0f832350cfeafb7c940629a953c45c83792ae8b112bf7b5e4c6d37e2969e244cc69df4a282
7
+ data.tar.gz: 941dfe9957dd358106159270a18b770920a5d11663d8619dd8e27dca63c5269478484ea072e94cbe8db885745c604669a9136e276ef901c3b0c123daf8c1ae8c
@@ -0,0 +1,31 @@
1
+ version: 2
2
+
3
+ jobs:
4
+ test:
5
+ docker:
6
+ - image: circleci/ruby:2
7
+ steps:
8
+ - checkout
9
+ - restore_cache:
10
+ keys:
11
+ - gem-cache-v2-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
12
+ - gem-cache-v2-{{ .Branch }}-
13
+ - gem-cache-v2-
14
+ - run:
15
+ name: "set up environment"
16
+ command: |
17
+ echo 'export BUNDLE_PATH="$HOME/project/.bundler_cache"' >> $BASH_ENV
18
+ source $BASH_ENV
19
+ - run: bundle
20
+ - save_cache:
21
+ paths:
22
+ - ~/project/.bundler_cache
23
+ key: gem-cache-v2-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
24
+ - run: make test
25
+
26
+ workflows:
27
+ version: 2
28
+ test:
29
+ jobs:
30
+ - test
31
+
@@ -0,0 +1,12 @@
1
+ .DS_Store
2
+ .bundle/
3
+ .yardoc
4
+ _yardoc/
5
+ coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *~
11
+ splunk-tracer*.gem
12
+ splunk*.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,48 @@
1
+ AllCops:
2
+ Exclude:
3
+ - spec/**/*
4
+ - .bundle/**/*
5
+ - bin/**/*
6
+ - vendor/**/*
7
+ - tmp/**/*
8
+ - log/**/*
9
+ - Rakefile
10
+ - splunktracing.gemspec
11
+
12
+ Lint/AmbiguousOperator:
13
+ Enabled: false
14
+
15
+ Metrics/ParameterLists:
16
+ Enabled: false
17
+
18
+ Metrics/AbcSize:
19
+ Max: 147
20
+
21
+ Metrics/BlockNesting:
22
+ Max: 4
23
+
24
+ # Configuration parameters: CountComments.
25
+ Metrics/ClassLength:
26
+ Max: 406
27
+
28
+ Metrics/CyclomaticComplexity:
29
+ Max: 24
30
+
31
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
32
+ # URISchemes: http, https
33
+ Metrics/LineLength:
34
+ Enabled: false
35
+
36
+ # Configuration parameters: CountComments.
37
+ Metrics/MethodLength:
38
+ Max: 88
39
+
40
+ # Configuration parameters: CountComments.
41
+ Metrics/ModuleLength:
42
+ Max: 1000
43
+
44
+ Performance/RedundantBlockCall:
45
+ Enabled: false
46
+
47
+ Style/PercentLiteralDelimiters:
48
+ Enabled: false
@@ -0,0 +1,4 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lightstep.gemspec
4
+ gemspec
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ splunk-tracer (0.1.0)
5
+ concurrent-ruby (~> 1.0)
6
+ opentracing (~> 0.4.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ bump (0.6.1)
12
+ concurrent-ruby (1.1.5)
13
+ diff-lcs (1.3)
14
+ docile (1.3.1)
15
+ json (2.1.0)
16
+ opentracing (0.4.3)
17
+ rack (2.0.5)
18
+ rake (11.3.0)
19
+ rspec (3.7.0)
20
+ rspec-core (~> 3.7.0)
21
+ rspec-expectations (~> 3.7.0)
22
+ rspec-mocks (~> 3.7.0)
23
+ rspec-core (3.7.1)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-expectations (3.7.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-mocks (3.7.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-support (3.7.1)
32
+ simplecov (0.16.1)
33
+ docile (~> 1.1)
34
+ json (>= 1.8, < 3)
35
+ simplecov-html (~> 0.10.0)
36
+ simplecov-html (0.10.2)
37
+ timecop (0.8.1)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bump (~> 0.5)
44
+ rack (~> 2.0)
45
+ rake (~> 11.3)
46
+ rspec (~> 3.0)
47
+ simplecov (~> 0.16)
48
+ splunk-tracer!
49
+ timecop (~> 0.8.0)
50
+
51
+ BUNDLED WITH
52
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Splunk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ .PHONY: build test benchmark publish
2
+
3
+ build:
4
+ gem build splunktracing.gemspec
5
+
6
+ test:
7
+ bundle exec rake spec
8
+ ruby example.rb
9
+ ruby examples/fork_children/main.rb
10
+ ruby examples/rack/inject_extract.rb
11
+
12
+ benchmark:
13
+ ruby benchmark/bench.rb
14
+ ruby benchmark/threading/thread_test.rb
15
+
16
+ bump-version:
17
+ ruby -e 'require "bump"; Bump::Bump.run("patch")'
18
+ make build # rebuild after version increment
19
+ git tag `ruby scripts/version.rb`
20
+ git push
21
+ git push --tags
22
+
23
+ publish: build test benchmark bump-version
24
+ gem push splunktracing-`ruby scripts/version.rb`.gem
@@ -0,0 +1,74 @@
1
+ # splunk-tracer-ruby
2
+
3
+ [![MIT license](http://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)
4
+
5
+ The Splunk OpenTracing library for Ruby.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'splunk-tracer'
12
+
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install splunk-tracer
21
+
22
+
23
+ ## Getting started
24
+
25
+ require 'splunktracing'
26
+
27
+ # Initialize the singleton tracer
28
+ SplunkTracing.configure(component_name: 'splunktracing/ruby/example', access_token: 'your_access_token')
29
+
30
+ # Create a basic span and attach a log to the span
31
+ span = SplunkTracing.start_span('my_span')
32
+ span.log(event: 'hello world', count: 42)
33
+
34
+ # Create a child span (and add some artificial delays to illustrate the timing)
35
+ sleep(0.1)
36
+ child = SplunkTracing.start_span('my_child', child_of: span.span_context)
37
+ sleep(0.2)
38
+ child.finish
39
+ sleep(0.1)
40
+ span.finish
41
+
42
+ ## Thread Safety
43
+
44
+ The Splunk Tracer is threadsafe. For increased performance, you can add the
45
+ `concurrent-ruby-ext` gem to your Gemfile. This will enable C extensions for
46
+ concurrent operations.
47
+
48
+ The Splunk Tracer is also Fork-safe. When forking, the child process will
49
+ not inherit the unflushed spans of the parent, so they will only be flushed
50
+ once.
51
+
52
+ ## Development
53
+
54
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `make test` to run the tests.
55
+
56
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
57
+
58
+
59
+
60
+
61
+ This library is the Splunk binding for [OpenTracing](http://opentracing.io/). See the [OpenTracing Ruby API](https://github.com/opentracing/opentracing-ruby) for additional detail.
62
+
63
+ ## License
64
+
65
+ The Splunk Tracer for Ruby is licensed under the MIT License. Details can be found in the LICENSE file.
66
+
67
+ ### Third-party libraries
68
+
69
+ This is a fork of the Ruby tracer from Lightstep, which is also licensed under the MIT License. Links to the original repository and license are below:
70
+
71
+ * [lightstep-tracer-ruby][lightstep]: [MIT][lightstep-license]
72
+
73
+ [lightstep]: https://github.com/lightstep/lightstep-tracer-ruby
74
+ [lightstep-license]: https://github.com/lightstep/lightstep-tracer-ruby/blob/master/LICENSE
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,138 @@
1
+ require 'json'
2
+ require 'splunktracing'
3
+ require 'opentracing'
4
+ require 'net/http'
5
+ require 'pp'
6
+ require 'uri'
7
+
8
+ $base_url = "http://localhost:8000"
9
+
10
+ $test_tracer = SplunkTracing::Tracer.new(
11
+ component_name: 'splunktracing/ruby/example',
12
+ transport: SplunkTracing::Transport::HTTPJSON.new(
13
+ host: 'localhost',
14
+ port: 8088,
15
+ encryption: SplunkTracing::Transport::HTTPJSON::ENCRYPTION_NONE,
16
+ access_token: 'none'
17
+ )
18
+ )
19
+ $noop_tracer = OpenTracing::Tracer.new
20
+
21
+ $prime_work = 982451653
22
+ $logs_memory = ""
23
+ $logs_size_max = (1 << 20)
24
+ $nanos_per_second = 1e9
25
+
26
+ def prepare_logs()
27
+ (0..$logs_size_max-1).each do |x|
28
+ $logs_memory << ("A".ord + x%26).chr
29
+ end
30
+ end
31
+
32
+ prepare_logs()
33
+
34
+ def do_work(n)
35
+ x = $prime_work
36
+ while n != 0 do
37
+ x *= $prime_work
38
+ x %= 4294967296
39
+ n -= 1
40
+ end
41
+ return x
42
+ end
43
+
44
+ def test_body(tracer, control)
45
+ repeat = control['Repeat']
46
+ sleepnano = control['Sleep']
47
+ sleepival = control['SleepInterval']
48
+ work = control['Work']
49
+ logn = control['NumLogs']
50
+ logsz = control['BytesPerLog']
51
+ sleep_debt = 0 # Accumulated nanoseconds
52
+ sleeps = 0
53
+ answer = 0
54
+
55
+ (1..repeat).each do
56
+ span = tracer.start_span('span/test')
57
+ (1..logn).each do
58
+ span.log_event("testlog", $logs_memory[0..logsz])
59
+ end
60
+ answer += do_work(work)
61
+ span.finish()
62
+ sleep_debt += sleepnano
63
+ if sleep_debt <= sleepival
64
+ next
65
+ end
66
+ before = Time.now.to_f
67
+ sleep(sleep_debt / $nanos_per_second)
68
+ elapsed_secs = Time.now.to_f - before
69
+ elapsed = (elapsed_secs * $nanos_per_second).round
70
+ sleeps += elapsed_secs
71
+ sleep_debt -= elapsed
72
+ end
73
+ return sleeps, answer
74
+ end
75
+
76
+ def loop()
77
+ while true do
78
+ uri = URI.parse($base_url + '/control')
79
+ resp = Net::HTTP.get(uri)
80
+ control = JSON.parse(resp)
81
+
82
+ concurrent = control['Concurrent']
83
+ trace = control['Trace']
84
+
85
+ if control['Exit']
86
+ exit(0)
87
+ end
88
+
89
+ tracer = nil
90
+ if trace
91
+ tracer = $test_tracer
92
+ else
93
+ tracer = $noop_tracer
94
+ end
95
+
96
+ before = Time.now.to_f
97
+
98
+ # Note: Concurrency test not implemented
99
+ sleeps, answer = test_body(tracer, control)
100
+
101
+ after = Time.now.to_f
102
+ flush_dur = 0.0
103
+
104
+ if trace
105
+ tracer.flush()
106
+ flush_dur = Time.now.to_f - after
107
+ end
108
+
109
+ elapsed = after - before
110
+
111
+ path = sprintf('/result?timing=%f&flush=%f&s=%f&a=%s', elapsed, flush_dur, sleeps, answer)
112
+
113
+ uri = URI.parse($base_url + path)
114
+ resp = Net::HTTP.get(uri)
115
+ end
116
+ end
117
+
118
+ def backtrace_for_all_threads(signame)
119
+ File.open("/tmp/ruby_backtrace_#{Process.pid}.txt","a") do |f|
120
+ f.puts "--- got signal #{signame}, dump backtrace for all threads at #{Time.now}"
121
+ if Thread.current.respond_to?(:backtrace)
122
+ Thread.list.each do |t|
123
+ f.puts t.inspect
124
+ PP.pp(t.backtrace.delete_if {|frame| frame =~ /^#{File.expand_path(__FILE__)}/},
125
+ f) # remove frames resulting from calling this method
126
+ end
127
+ else
128
+ PP.pp(caller.delete_if {|frame| frame =~ /^#{File.expand_path(__FILE__)}/},
129
+ f) # remove frames resulting from calling this method
130
+ end
131
+ end
132
+ end
133
+
134
+ Signal.trap(29) do
135
+ backtrace_for_all_threads("INFO")
136
+ end
137
+
138
+ loop()
@@ -0,0 +1,60 @@
1
+ require 'benchmark'
2
+ require 'securerandom'
3
+
4
+ require 'bundler/setup'
5
+ require 'splunktracing'
6
+
7
+ rng = Random.new
8
+
9
+ # Run a quick profile on logging lots of spans
10
+ tracer = SplunkTracing::Tracer.new(
11
+ component_name: 'splunktracing/ruby/spec',
12
+ transport: SplunkTracing::Transport::Nil.new
13
+ )
14
+
15
+ Benchmark.bm(32) do |x|
16
+ x.report('Random.bytes.unpack') do
17
+ for i in 1..10_000; rng.bytes(8).unpack('H*')[0]; end
18
+ end
19
+ x.report('Random.bytes.each_byte.map') do
20
+ for i in 1..10_000; rng.bytes(8).each_byte.map { |b| b.to_s(16) }.join; end
21
+ end
22
+ x.report('SecureRandom.hex') do
23
+ for i in 1..10_000; SecureRandom.hex(8); end
24
+ end
25
+
26
+ x.report('start_span(100)') do
27
+ for i in 0..100; tracer.start_span('my_span').finish; end
28
+ end
29
+ x.report('start_span(1000)') do
30
+ for i in 0..1000; tracer.start_span('my_span').finish; end
31
+ end
32
+ x.report('start_span(10000)') do
33
+ for i in 0..10_000; tracer.start_span('my_span').finish; end
34
+ end
35
+
36
+ x.report('log_event(100)') do
37
+ span = tracer.start_span('my_span')
38
+ for i in 0..100; span.log(event: 'event', i: i); end
39
+ span.finish
40
+ end
41
+ x.report('log_event(1000)') do
42
+ span = tracer.start_span('my_span')
43
+ for i in 0..1000; span.log(event: 'event', i: i); end
44
+ span.finish
45
+ end
46
+ x.report('log_event(10000)') do
47
+ span = tracer.start_span('my_span')
48
+ for i in 0..10_000; span.log(event: 'event', i: i); end
49
+ span.finish
50
+ end
51
+
52
+ x.report('inject(10000)') do
53
+ span = tracer.start_span('my_span')
54
+ for i in 0..10_000
55
+ carrier = {}
56
+ tracer.inject(span.span_context, OpenTracing::FORMAT_TEXT_MAP, carrier)
57
+ end
58
+ span.finish
59
+ end
60
+ end