lightstep 0.9.9 → 0.9.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Makefile +1 -0
- data/benchmark.rb +140 -0
- data/example.rb +1 -1
- data/examples/rack/inject_extract.rb +66 -0
- data/lib/lightstep/reporter.rb +4 -2
- data/lib/lightstep/span.rb +28 -20
- data/lib/lightstep/span_context.rb +12 -0
- data/lib/lightstep/tracer.rb +65 -23
- data/lib/lightstep/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a02601ce2a4492bb33a7fd9efee072355800c67b
|
4
|
+
data.tar.gz: 9ac1d7f5f660d442382c7c76875a719502b4d94e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0143c3a49f63d4b92a6d7df08eb719bc2702e69663b8a240954aa252869d88071d1f99da25764eba8c187d621b042e2c32f5ce187ae259c2db29f74be2f6833
|
7
|
+
data.tar.gz: 6ff5a25034f87dd93fe18c40df50bfb9b2036af6a00da19dcfd9b95177c575dfc05a352a350d7145e5c299a69b40fc257f5b38b7188064089d82083bd5014b5c
|
data/Makefile
CHANGED
data/benchmark.rb
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'lightstep'
|
3
|
+
require 'net/http'
|
4
|
+
require 'pp'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
$base_url = "http://localhost:8000"
|
8
|
+
|
9
|
+
$test_tracer = LightStep::Tracer.new(
|
10
|
+
component_name: 'lightstep/ruby/example',
|
11
|
+
transport: LightStep::Transport::HTTPJSON.new(
|
12
|
+
host: 'localhost',
|
13
|
+
port: 8000,
|
14
|
+
encryption: LightStep::Transport::HTTPJSON::ENCRYPTION_NONE,
|
15
|
+
access_token: 'none'
|
16
|
+
)
|
17
|
+
)
|
18
|
+
$noop_tracer = LightStep::Tracer.new(
|
19
|
+
component_name: 'ruby',
|
20
|
+
transport: LightStep::Transport::Nil.new
|
21
|
+
)
|
22
|
+
|
23
|
+
$prime_work = 982451653
|
24
|
+
$logs_memory = ""
|
25
|
+
$logs_size_max = (1 << 20)
|
26
|
+
$nanos_per_second = 1e9
|
27
|
+
|
28
|
+
def prepare_logs()
|
29
|
+
(0..$logs_size_max-1).each do |x|
|
30
|
+
$logs_memory << ("A".ord + x%26).chr
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
prepare_logs()
|
35
|
+
|
36
|
+
def do_work(n)
|
37
|
+
x = $prime_work
|
38
|
+
while n != 0 do
|
39
|
+
x *= $prime_work
|
40
|
+
x %= 4294967296
|
41
|
+
n -= 1
|
42
|
+
end
|
43
|
+
return x
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_body(tracer, control)
|
47
|
+
repeat = control['Repeat']
|
48
|
+
sleepnano = control['Sleep']
|
49
|
+
sleepival = control['SleepInterval']
|
50
|
+
work = control['Work']
|
51
|
+
logn = control['NumLogs']
|
52
|
+
logsz = control['BytesPerLog']
|
53
|
+
sleep_debt = 0 # Accumulated nanoseconds
|
54
|
+
sleeps = 0
|
55
|
+
answer = 0
|
56
|
+
|
57
|
+
(1..repeat).each do
|
58
|
+
span = tracer.start_span('span/test')
|
59
|
+
(1..logn).each do
|
60
|
+
span.log_event("testlog", $logs_memory[0..logsz])
|
61
|
+
end
|
62
|
+
answer += do_work(work)
|
63
|
+
span.finish()
|
64
|
+
sleep_debt += sleepnano
|
65
|
+
if sleep_debt <= sleepival
|
66
|
+
next
|
67
|
+
end
|
68
|
+
before = Time.now.to_f
|
69
|
+
sleep(sleep_debt / $nanos_per_second)
|
70
|
+
elapsed_secs = Time.now.to_f - before
|
71
|
+
elapsed = (elapsed_secs * $nanos_per_second).round
|
72
|
+
sleeps += elapsed_secs
|
73
|
+
sleep_debt -= elapsed
|
74
|
+
end
|
75
|
+
return sleeps, answer
|
76
|
+
end
|
77
|
+
|
78
|
+
def loop()
|
79
|
+
while true do
|
80
|
+
uri = URI.parse($base_url + '/control')
|
81
|
+
resp = Net::HTTP.get(uri)
|
82
|
+
control = JSON.parse(resp)
|
83
|
+
|
84
|
+
concurrent = control['Concurrent']
|
85
|
+
trace = control['Trace']
|
86
|
+
|
87
|
+
if control['Exit']
|
88
|
+
exit(0)
|
89
|
+
end
|
90
|
+
|
91
|
+
tracer = nil
|
92
|
+
if trace
|
93
|
+
tracer = $test_tracer
|
94
|
+
else
|
95
|
+
tracer = $noop_tracer
|
96
|
+
end
|
97
|
+
|
98
|
+
before = Time.now.to_f
|
99
|
+
|
100
|
+
# Note: Concurrency test not implemented
|
101
|
+
sleeps, answer = test_body(tracer, control)
|
102
|
+
|
103
|
+
after = Time.now.to_f
|
104
|
+
flush_dur = 0.0
|
105
|
+
|
106
|
+
if trace
|
107
|
+
tracer.flush()
|
108
|
+
flush_dur = Time.now.to_f - after
|
109
|
+
end
|
110
|
+
|
111
|
+
elapsed = after - before
|
112
|
+
|
113
|
+
path = sprintf('/result?timing=%f&flush=%f&s=%f&a=%s', elapsed, flush_dur, sleeps, answer)
|
114
|
+
|
115
|
+
uri = URI.parse($base_url + path)
|
116
|
+
resp = Net::HTTP.get(uri)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def backtrace_for_all_threads(signame)
|
121
|
+
File.open("/tmp/ruby_backtrace_#{Process.pid}.txt","a") do |f|
|
122
|
+
f.puts "--- got signal #{signame}, dump backtrace for all threads at #{Time.now}"
|
123
|
+
if Thread.current.respond_to?(:backtrace)
|
124
|
+
Thread.list.each do |t|
|
125
|
+
f.puts t.inspect
|
126
|
+
PP.pp(t.backtrace.delete_if {|frame| frame =~ /^#{File.expand_path(__FILE__)}/},
|
127
|
+
f) # remove frames resulting from calling this method
|
128
|
+
end
|
129
|
+
else
|
130
|
+
PP.pp(caller.delete_if {|frame| frame =~ /^#{File.expand_path(__FILE__)}/},
|
131
|
+
f) # remove frames resulting from calling this method
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
Signal.trap(29) do
|
137
|
+
backtrace_for_all_threads("INFO")
|
138
|
+
end
|
139
|
+
|
140
|
+
loop()
|
data/example.rb
CHANGED
@@ -31,4 +31,4 @@ end
|
|
31
31
|
span.finish
|
32
32
|
LightStep.flush
|
33
33
|
puts 'Done!'
|
34
|
-
puts "https://app.lightstep.com/#{access_token}/trace?span_guid=#{span.
|
34
|
+
puts "https://app.lightstep.com/#{access_token}/trace?span_guid=#{span.span_context.id}&at_micros=#{span.start_micros}"
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'lightstep'
|
3
|
+
|
4
|
+
require 'rack'
|
5
|
+
require 'rack/server'
|
6
|
+
|
7
|
+
$token = '{your_access_token}'
|
8
|
+
$request_id = 'abc123'
|
9
|
+
|
10
|
+
class Router
|
11
|
+
def initialize
|
12
|
+
@tracer = LightStep::Tracer.new(component_name: 'router', access_token: $token)
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
span = @tracer.start_span("router_call").set_baggage_item("request-id", $request_id)
|
17
|
+
span.log(event: "router_request", env: env)
|
18
|
+
puts "parent #{span.span_context.trace_id}"
|
19
|
+
|
20
|
+
client = Net::HTTP.new("localhost", "9002")
|
21
|
+
req = Net::HTTP::Post.new("/")
|
22
|
+
@tracer.inject(span, LightStep::Tracer::FORMAT_RACK, req)
|
23
|
+
res = client.request(req)
|
24
|
+
|
25
|
+
span.log(event: "application_response", response: res.to_s)
|
26
|
+
span.finish
|
27
|
+
@tracer.flush
|
28
|
+
puts "----> https://app.lightstep.com/#{$token}/trace?span_guid=#{span.span_context.id}&at_micros=#{span.start_micros} <----"
|
29
|
+
[200, {}, [res.body]]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class App
|
34
|
+
def initialize
|
35
|
+
@tracer = LightStep::Tracer.new(component_name: 'app', access_token: $token)
|
36
|
+
end
|
37
|
+
|
38
|
+
def call(env)
|
39
|
+
span = @tracer.extract("app_call", LightStep::Tracer::FORMAT_RACK, env)
|
40
|
+
puts "child #{span.to_h[:trace_guid]}"
|
41
|
+
span.log(event: "application", env: env)
|
42
|
+
sleep 0.05
|
43
|
+
span.finish
|
44
|
+
@tracer.flush
|
45
|
+
[200, {}, ["application"]]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
router_thread = Thread.new do
|
50
|
+
Thread.abort_on_exception = true
|
51
|
+
Rack::Server.start(app: Router.new, Port: 9001)
|
52
|
+
end
|
53
|
+
|
54
|
+
app_thread = Thread.new do
|
55
|
+
Thread.abort_on_exception = true
|
56
|
+
Rack::Server.start(app: App.new, Port: 9002)
|
57
|
+
end
|
58
|
+
|
59
|
+
loop do
|
60
|
+
begin
|
61
|
+
p Net::HTTP.get(URI("http://localhost:9001/"))
|
62
|
+
break
|
63
|
+
rescue Errno::ECONNREFUSED
|
64
|
+
sleep 0.05
|
65
|
+
end
|
66
|
+
end
|
data/lib/lightstep/reporter.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'lightstep/version'
|
2
|
+
|
1
3
|
module LightStep
|
2
4
|
# Reporter builds up reports of spans and flushes them to a transport
|
3
5
|
class Reporter
|
@@ -5,7 +7,7 @@ module LightStep
|
|
5
7
|
attr_accessor :max_span_records
|
6
8
|
attr_accessor :period
|
7
9
|
|
8
|
-
def initialize(max_span_records:, transport:, guid:, component_name:)
|
10
|
+
def initialize(max_span_records:, transport:, guid:, component_name:, tags: {})
|
9
11
|
@max_span_records = max_span_records
|
10
12
|
@span_records = Concurrent::Array.new
|
11
13
|
@dropped_spans = Concurrent::AtomicFixnum.new
|
@@ -24,7 +26,7 @@ module LightStep
|
|
24
26
|
{Key: "lightstep.tracer_platform", Value: "ruby"},
|
25
27
|
{Key: "lightstep.tracer_version", Value: LightStep::VERSION},
|
26
28
|
{Key: "lightstep.tracer_platform_version", Value: RUBY_VERSION}
|
27
|
-
]
|
29
|
+
] + tags.map{|k,v| {Key: k.to_s, Value: v.to_s}}
|
28
30
|
}.freeze
|
29
31
|
|
30
32
|
reset_on_fork
|
data/lib/lightstep/span.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'concurrent'
|
2
|
+
require 'lightstep/span_context'
|
2
3
|
|
3
4
|
module LightStep
|
4
5
|
# Span represents an OpenTracer Span
|
@@ -10,7 +11,7 @@ module LightStep
|
|
10
11
|
|
11
12
|
# Internal use only
|
12
13
|
# @private
|
13
|
-
attr_reader :
|
14
|
+
attr_reader :start_micros, :end_micros, :baggage, :tags, :operation_name, :span_context
|
14
15
|
|
15
16
|
# Creates a new {Span}
|
16
17
|
#
|
@@ -23,38 +24,31 @@ module LightStep
|
|
23
24
|
def initialize(
|
24
25
|
tracer:,
|
25
26
|
operation_name:,
|
26
|
-
|
27
|
-
|
27
|
+
child_of_id: nil,
|
28
|
+
trace_id:,
|
28
29
|
start_micros:,
|
29
30
|
tags: nil,
|
30
31
|
max_log_records:
|
31
32
|
)
|
32
33
|
@tags = Concurrent::Hash.new
|
33
34
|
@tags.update(tags) unless tags.nil?
|
34
|
-
@baggage = Concurrent::Hash.new
|
35
35
|
@log_records = Concurrent::Array.new
|
36
36
|
@dropped_logs = Concurrent::AtomicFixnum.new
|
37
37
|
@max_log_records = max_log_records
|
38
38
|
|
39
39
|
@tracer = tracer
|
40
|
-
@guid = LightStep.guid
|
41
40
|
self.operation_name = operation_name
|
42
41
|
self.start_micros = start_micros
|
43
|
-
|
44
|
-
set_tag(:parent_span_guid,
|
42
|
+
@span_context = SpanContext.new(id: LightStep.guid, trace_id: trace_id)
|
43
|
+
set_tag(:parent_span_guid, child_of_id) if !child_of_id.nil?
|
45
44
|
end
|
46
45
|
|
47
46
|
# Set a tag value on this span
|
48
47
|
# @param key [String] the key of the tag
|
49
|
-
# @param value [String
|
50
|
-
#
|
48
|
+
# @param value [String] the value of the tag. If it's not a String
|
49
|
+
# it will be encoded with to_s
|
51
50
|
def set_tag(key, value)
|
52
|
-
|
53
|
-
when String, Fixnum, TrueClass, FalseClass
|
54
|
-
tags[key] = value
|
55
|
-
else
|
56
|
-
tags[key] = value.to_s
|
57
|
-
end
|
51
|
+
tags[key] = value.to_s
|
58
52
|
self
|
59
53
|
end
|
60
54
|
|
@@ -65,15 +59,29 @@ module LightStep
|
|
65
59
|
# @param key [String] the key of the baggage item
|
66
60
|
# @param value [String] the value of the baggage item
|
67
61
|
def set_baggage_item(key, value)
|
68
|
-
|
62
|
+
@span_context = SpanContext.new(
|
63
|
+
id: span_context.id,
|
64
|
+
trace_id: span_context.trace_id,
|
65
|
+
baggage: span_context.baggage.merge({key => value})
|
66
|
+
)
|
69
67
|
self
|
70
68
|
end
|
71
69
|
|
70
|
+
# Set all baggage at once. This will reset the baggage to the given param.
|
71
|
+
# @param baggage [Hash] new baggage for the span
|
72
|
+
def set_baggage(baggage = {})
|
73
|
+
@span_context = SpanContext.new(
|
74
|
+
id: span_context.id,
|
75
|
+
trace_id: span_context.trace_id,
|
76
|
+
baggage: baggage
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
72
80
|
# Get a baggage item
|
73
81
|
# @param key [String] the key of the baggage item
|
74
82
|
# @return Value of the baggage item
|
75
83
|
def get_baggage_item(key)
|
76
|
-
baggage[key]
|
84
|
+
span_context.baggage[key]
|
77
85
|
end
|
78
86
|
|
79
87
|
# Add a log entry to this span
|
@@ -117,8 +125,8 @@ module LightStep
|
|
117
125
|
def to_h
|
118
126
|
{
|
119
127
|
runtime_guid: tracer.guid,
|
120
|
-
span_guid:
|
121
|
-
trace_guid:
|
128
|
+
span_guid: span_context.id,
|
129
|
+
trace_guid: span_context.trace_id,
|
122
130
|
span_name: operation_name,
|
123
131
|
attributes: tags.map {|key, value|
|
124
132
|
{Key: key.to_s, Value: value}
|
@@ -146,6 +154,6 @@ module LightStep
|
|
146
154
|
private
|
147
155
|
|
148
156
|
attr_reader :tracer, :dropped_logs, :log_records
|
149
|
-
attr_writer :
|
157
|
+
attr_writer :start_micros, :end_micros
|
150
158
|
end
|
151
159
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module LightStep
|
2
|
+
# SpanContext holds the data for a span that gets inherited to child spans
|
3
|
+
class SpanContext
|
4
|
+
attr_reader :id, :trace_id, :baggage
|
5
|
+
|
6
|
+
def initialize(id:, trace_id:, baggage: {})
|
7
|
+
@id = id.freeze
|
8
|
+
@trace_id = trace_id.freeze
|
9
|
+
@baggage = baggage.freeze
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/lightstep/tracer.rb
CHANGED
@@ -11,6 +11,7 @@ module LightStep
|
|
11
11
|
class Tracer
|
12
12
|
FORMAT_TEXT_MAP = 1
|
13
13
|
FORMAT_BINARY = 2
|
14
|
+
FORMAT_RACK = 3
|
14
15
|
|
15
16
|
class Error < LightStep::Error; end
|
16
17
|
class ConfigurationError < LightStep::Tracer::Error; end
|
@@ -22,10 +23,11 @@ module LightStep
|
|
22
23
|
# @param component_name [String] Component name to use for the tracer
|
23
24
|
# @param access_token [String] The project access token when pushing to LightStep
|
24
25
|
# @param transport [LightStep::Transport] How the data should be transported
|
26
|
+
# @param tags [Hash] Tracer-level tags
|
25
27
|
# @return LightStep::Tracer
|
26
28
|
# @raise LightStep::ConfigurationError if the group name or access token is not a valid string.
|
27
|
-
def initialize(component_name:, access_token: nil, transport: nil)
|
28
|
-
configure(component_name: component_name, access_token: access_token, transport: transport)
|
29
|
+
def initialize(component_name:, access_token: nil, transport: nil, tags: {})
|
30
|
+
configure(component_name: component_name, access_token: access_token, transport: transport, tags: tags)
|
29
31
|
end
|
30
32
|
|
31
33
|
def max_log_records
|
@@ -60,36 +62,44 @@ module LightStep
|
|
60
62
|
# @param tags [Hash] tags for the span
|
61
63
|
# @return [Span]
|
62
64
|
def start_span(operation_name, child_of: nil, start_time: nil, tags: nil)
|
63
|
-
|
64
|
-
|
65
|
+
child_of_id = nil
|
66
|
+
trace_id = nil
|
65
67
|
if Span === child_of
|
66
|
-
|
67
|
-
|
68
|
+
child_of_id = child_of.span_context.id
|
69
|
+
trace_id = child_of.span_context.trace_id
|
68
70
|
else
|
69
|
-
|
71
|
+
trace_id = LightStep.guid
|
70
72
|
end
|
71
73
|
|
72
|
-
Span.new(
|
74
|
+
span = Span.new(
|
73
75
|
tracer: self,
|
74
76
|
operation_name: operation_name,
|
75
|
-
|
76
|
-
|
77
|
+
child_of_id: child_of_id,
|
78
|
+
trace_id: trace_id,
|
77
79
|
start_micros: start_time.nil? ? LightStep.micros(Time.now) : LightStep.micros(start_time),
|
78
80
|
tags: tags,
|
79
81
|
max_log_records: max_log_records
|
80
82
|
)
|
83
|
+
|
84
|
+
if Span === child_of
|
85
|
+
span.set_baggage(child_of.baggage)
|
86
|
+
end
|
87
|
+
|
88
|
+
span
|
81
89
|
end
|
82
90
|
|
83
91
|
# Inject a span into the given carrier
|
84
92
|
# @param span [Span]
|
85
93
|
# @param format [LightStep::Tracer::FORMAT_TEXT_MAP, LightStep::Tracer::FORMAT_BINARY]
|
86
|
-
# @param carrier [Hash
|
94
|
+
# @param carrier [Hash]
|
87
95
|
def inject(span, format, carrier)
|
88
96
|
case format
|
89
97
|
when LightStep::Tracer::FORMAT_TEXT_MAP
|
90
98
|
inject_to_text_map(span, carrier)
|
91
99
|
when LightStep::Tracer::FORMAT_BINARY
|
92
100
|
warn 'Binary inject format not yet implemented'
|
101
|
+
when LightStep::Tracer::FORMAT_RACK
|
102
|
+
inject_to_rack(span, carrier)
|
93
103
|
else
|
94
104
|
warn 'Unknown inject format'
|
95
105
|
end
|
@@ -98,7 +108,7 @@ module LightStep
|
|
98
108
|
# Extract a span from a carrier
|
99
109
|
# @param operation_name [String]
|
100
110
|
# @param format [LightStep::Tracer::FORMAT_TEXT_MAP, LightStep::Tracer::FORMAT_BINARY]
|
101
|
-
# @param carrier [Hash
|
111
|
+
# @param carrier [Hash]
|
102
112
|
# @return [Span]
|
103
113
|
def extract(operation_name, format, carrier)
|
104
114
|
case format
|
@@ -107,6 +117,8 @@ module LightStep
|
|
107
117
|
when LightStep::Tracer::FORMAT_BINARY
|
108
118
|
warn 'Binary join format not yet implemented'
|
109
119
|
nil
|
120
|
+
when LightStep::Tracer::FORMAT_RACK
|
121
|
+
extract_from_rack(operation_name, carrier)
|
110
122
|
else
|
111
123
|
warn 'Unknown join format'
|
112
124
|
nil
|
@@ -147,7 +159,7 @@ module LightStep
|
|
147
159
|
|
148
160
|
protected
|
149
161
|
|
150
|
-
def configure(component_name:, access_token: nil, transport: nil)
|
162
|
+
def configure(component_name:, access_token: nil, transport: nil, tags: {})
|
151
163
|
raise ConfigurationError, "component_name must be a string" unless String === component_name
|
152
164
|
raise ConfigurationError, "component_name cannot be blank" if component_name.empty?
|
153
165
|
|
@@ -161,7 +173,8 @@ module LightStep
|
|
161
173
|
max_span_records: max_span_records,
|
162
174
|
transport: transport,
|
163
175
|
guid: guid,
|
164
|
-
component_name: component_name
|
176
|
+
component_name: component_name,
|
177
|
+
tags: tags
|
165
178
|
)
|
166
179
|
end
|
167
180
|
|
@@ -176,11 +189,11 @@ module LightStep
|
|
176
189
|
MIN_MAX_SPAN_RECORDS = 1
|
177
190
|
|
178
191
|
def inject_to_text_map(span, carrier)
|
179
|
-
carrier[CARRIER_TRACER_STATE_PREFIX + 'spanid'] = span.
|
180
|
-
carrier[CARRIER_TRACER_STATE_PREFIX + 'traceid'] = span.
|
192
|
+
carrier[CARRIER_TRACER_STATE_PREFIX + 'spanid'] = span.span_context.id
|
193
|
+
carrier[CARRIER_TRACER_STATE_PREFIX + 'traceid'] = span.span_context.trace_id unless span.span_context.trace_id.nil?
|
181
194
|
carrier[CARRIER_TRACER_STATE_PREFIX + 'sampled'] = 'true'
|
182
195
|
|
183
|
-
span.baggage.each do |key, value|
|
196
|
+
span.span_context.baggage.each do |key, value|
|
184
197
|
carrier[CARRIER_BAGGAGE_PREFIX + key] = value
|
185
198
|
end
|
186
199
|
end
|
@@ -190,17 +203,46 @@ module LightStep
|
|
190
203
|
tracer: self,
|
191
204
|
operation_name: operation_name,
|
192
205
|
start_micros: LightStep.micros(Time.now),
|
193
|
-
|
194
|
-
|
206
|
+
child_of_id: carrier[CARRIER_TRACER_STATE_PREFIX + 'spanid'],
|
207
|
+
trace_id: carrier[CARRIER_TRACER_STATE_PREFIX + 'traceid'],
|
195
208
|
max_log_records: max_log_records
|
196
209
|
)
|
197
210
|
|
198
|
-
carrier.
|
199
|
-
|
200
|
-
|
201
|
-
|
211
|
+
baggage = carrier.reduce({}) do |baggage, tuple|
|
212
|
+
key, value = tuple
|
213
|
+
if key.start_with?(CARRIER_BAGGAGE_PREFIX)
|
214
|
+
plain_key = key.to_s[CARRIER_BAGGAGE_PREFIX.length..key.to_s.length]
|
215
|
+
baggage[plain_key] = value
|
216
|
+
end
|
217
|
+
baggage
|
202
218
|
end
|
219
|
+
span.set_baggage(baggage)
|
220
|
+
|
203
221
|
span
|
204
222
|
end
|
223
|
+
|
224
|
+
def inject_to_rack(span, carrier)
|
225
|
+
carrier[CARRIER_TRACER_STATE_PREFIX + 'spanid'] = span.span_context.id
|
226
|
+
carrier[CARRIER_TRACER_STATE_PREFIX + 'traceid'] = span.span_context.trace_id unless span.span_context.trace_id.nil?
|
227
|
+
carrier[CARRIER_TRACER_STATE_PREFIX + 'sampled'] = 'true'
|
228
|
+
|
229
|
+
span.span_context.baggage.each do |key, value|
|
230
|
+
if key =~ /[^A-Za-z0-9\-_]/
|
231
|
+
# TODO: log the error internally
|
232
|
+
next
|
233
|
+
end
|
234
|
+
carrier[CARRIER_BAGGAGE_PREFIX + key] = value
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
def extract_from_rack(operation_name, env)
|
239
|
+
extract_from_text_map(operation_name, env.reduce({}){|memo, tuple|
|
240
|
+
raw_header, value = tuple
|
241
|
+
header = raw_header.gsub(/^HTTP_/, '').gsub("_", "-").downcase
|
242
|
+
|
243
|
+
memo[header] = value if header.start_with?(CARRIER_TRACER_STATE_PREFIX, CARRIER_BAGGAGE_PREFIX)
|
244
|
+
memo
|
245
|
+
})
|
246
|
+
end
|
205
247
|
end
|
206
248
|
end
|
data/lib/lightstep/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lightstep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bcronin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- Makefile
|
123
123
|
- README.md
|
124
124
|
- Rakefile
|
125
|
+
- benchmark.rb
|
125
126
|
- benchmark/bench.rb
|
126
127
|
- benchmark/threading/thread_test.rb
|
127
128
|
- bin/console
|
@@ -130,10 +131,12 @@ files:
|
|
130
131
|
- example.rb
|
131
132
|
- examples/fork_children/main.rb
|
132
133
|
- examples/rack/hello.rb
|
134
|
+
- examples/rack/inject_extract.rb
|
133
135
|
- lib/lightstep.rb
|
134
136
|
- lib/lightstep/global_tracer.rb
|
135
137
|
- lib/lightstep/reporter.rb
|
136
138
|
- lib/lightstep/span.rb
|
139
|
+
- lib/lightstep/span_context.rb
|
137
140
|
- lib/lightstep/tracer.rb
|
138
141
|
- lib/lightstep/transport/base.rb
|
139
142
|
- lib/lightstep/transport/callback.rb
|
@@ -162,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
165
|
version: '0'
|
163
166
|
requirements: []
|
164
167
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.5.
|
168
|
+
rubygems_version: 2.5.2
|
166
169
|
signing_key:
|
167
170
|
specification_version: 4
|
168
171
|
summary: LightStep OpenTracing Ruby bindings
|