lightstep 0.10.9 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c95a5745b43ca1428f8ff9f7ea8c7b70c42c7401
4
- data.tar.gz: 6b4b663ae87b92acd2221f13528aa60e68ee81f2
3
+ metadata.gz: 60cb500c09adc67c7075714882a6ee426c12296c
4
+ data.tar.gz: bf1fa6efd5ad979bbc14801653b5a4b9f628fe11
5
5
  SHA512:
6
- metadata.gz: a57a5ebb53299e9d1576d53d9674e5bb2bf9a958185ea3175467a5d44ac1f43d0edf873e65847ac917b8702bc397ebd1284f5dc9bacd056e4688f50d85ab4a33
7
- data.tar.gz: 34d6ff31de150cb543449ec7b4440e4c989742a170fe3d195168df4ab1b0eb2dd69dc4b2e53ff2fbc9ff3ff9e0ccd791306252fa96cbd2306b2e219f3a79c6b5
6
+ metadata.gz: 99870437ee219e8388040f86a924aa76906762e5be9495808ffce81bcd48b0e53ab9ca01f7d7063c88b8ee768d76a883771888dd3cb66e0f9eaffbcf84ac76ce
7
+ data.tar.gz: 9505d03f36ca6da2caaa1d5610d5510193c5308d769dfe919f1a9d9ed99abf20e3405a0c18af89010d5725800de38af795186a81a3dc35278bfdac2ccc82523a
data/README.md CHANGED
@@ -33,7 +33,7 @@ Or install it yourself as:
33
33
 
34
34
  # Create a child span (and add some artificial delays to illustrate the timing)
35
35
  sleep(0.1)
36
- child = LightStep.start_span('my_child', child_of: span)
36
+ child = LightStep.start_span('my_child', child_of: span.span_context)
37
37
  sleep(0.2)
38
38
  child.finish
39
39
  sleep(0.1)
@@ -53,7 +53,7 @@ Benchmark.bm(32) do |x|
53
53
  span = tracer.start_span('my_span')
54
54
  for i in 0..10_000
55
55
  carrier = {}
56
- tracer.inject(span, LightStep::Tracer::FORMAT_TEXT_MAP, carrier)
56
+ tracer.inject(span.span_context, LightStep::Tracer::FORMAT_TEXT_MAP, carrier)
57
57
  end
58
58
  span.finish
59
59
  end
data/example.rb CHANGED
@@ -20,7 +20,7 @@ end
20
20
  thread2 = Thread.new do
21
21
  current = 1
22
22
  for i in 1..16
23
- child = LightStep.start_span('my_child', child_of: span)
23
+ child = LightStep.start_span('my_child', child_of: span.span_context)
24
24
  sleep(0.1)
25
25
  current *= 2
26
26
  child.log(event: "2^#{i}", result: current)
@@ -13,14 +13,14 @@ puts 'Starting...'
13
13
  (1..20).each do |k|
14
14
  puts "Explicit reset iteration #{k}..."
15
15
 
16
- # pid = Process.fork do
17
- # 10.times do
18
- # span = LightStep.start_span("my_forked_span-#{Process.pid}")
19
- # sleep(0.0025 * rand(k))
20
- # span.finish
21
- # end
22
- # LightStep.flush
23
- # end
16
+ pid = Process.fork do
17
+ 10.times do
18
+ span = LightStep.start_span("my_forked_span-#{Process.pid}")
19
+ sleep(0.0025 * rand(k))
20
+ span.finish
21
+ end
22
+ LightStep.flush
23
+ end
24
24
 
25
25
  3.times do
26
26
  span = LightStep.start_span("my_process_span-#{Process.pid}")
@@ -30,23 +30,23 @@ puts 'Starting...'
30
30
  span.finish
31
31
  end
32
32
 
33
- # # Make sure redundant enable calls don't cause problems
34
- # # NOTE: disabling discards the buffer by default, so all spans
35
- # # get cleared here except the final toggle span
36
- # 10.times do
37
- # LightStep.disable
38
- # LightStep.enable
39
- # LightStep.disable
40
- # LightStep.disable
41
- # LightStep.enable
42
- # LightStep.enable
43
- # span = LightStep.start_span("my_toggle_span-#{Process.pid}")
44
- # sleep(0.0025 * rand(k))
45
- # span.finish
46
- # end
47
-
48
- # puts "Parent, pid #{Process.pid}, waiting on child pid #{pid}"
49
- # Process.wait(pid)
33
+ # Make sure redundant enable calls don't cause problems
34
+ # NOTE: disabling discards the buffer by default, so all spans
35
+ # get cleared here except the final toggle span
36
+ 10.times do
37
+ LightStep.disable
38
+ LightStep.enable
39
+ LightStep.disable
40
+ LightStep.disable
41
+ LightStep.enable
42
+ LightStep.enable
43
+ span = LightStep.start_span("my_toggle_span-#{Process.pid}")
44
+ sleep(0.0025 * rand(k))
45
+ span.finish
46
+ end
47
+
48
+ puts "Parent, pid #{Process.pid}, waiting on child pid #{pid}"
49
+ Process.wait(pid)
50
50
  end
51
51
 
52
52
  puts 'Done!'
@@ -19,7 +19,7 @@ class Router
19
19
 
20
20
  client = Net::HTTP.new("localhost", "9002")
21
21
  req = Net::HTTP::Post.new("/")
22
- @tracer.inject(span, LightStep::Tracer::FORMAT_RACK, req)
22
+ @tracer.inject(span.span_context, LightStep::Tracer::FORMAT_RACK, req)
23
23
  res = client.request(req)
24
24
 
25
25
  span.log(event: "application_response", response: res.to_s)
@@ -36,7 +36,8 @@ class App
36
36
  end
37
37
 
38
38
  def call(env)
39
- span = @tracer.extract("app_call", LightStep::Tracer::FORMAT_RACK, env)
39
+ wire_ctx = @tracer.extract(LightStep::Tracer::FORMAT_RACK, env)
40
+ span = @tracer.start_span("app_call", child_of: wire_ctx)
40
41
  puts "child #{span.to_h[:trace_guid]}"
41
42
  span.log(event: "application", env: env)
42
43
  sleep 0.05
@@ -17,20 +17,22 @@ module LightStep
17
17
  #
18
18
  # @param tracer [Tracer] the tracer that created this span
19
19
  # @param operation_name [String] the operation name of this span. If it's
20
- # not a String it will be encoded with to_s.
21
- # @param child_of_guid [String] the guid of the span this span is a child of
22
- # @param trace_guid [String] the guid of this span's trace
20
+ # not a String it will be encoded with to_s.
21
+ # @param child_of [SpanContext] the parent SpanContext (per child_of)
23
22
  # @param start_micros [Numeric] start time of the span in microseconds
24
- # @return [Span] a new Span
23
+ # @param tags [Hash] initial key:value tags (per set_tag) for the Span
24
+ # @param max_log_records [Numeric] maximum allowable number of log records
25
+ # for the Span
26
+ # @return [Span] a started Span
25
27
  def initialize(
26
28
  tracer:,
27
29
  operation_name:,
28
- child_of_id: nil,
29
- trace_id:,
30
+ child_of: nil,
30
31
  start_micros:,
31
32
  tags: nil,
32
33
  max_log_records:
33
34
  )
35
+ child_of = child_of.span_context if (Span === child_of)
34
36
  @tags = Concurrent::Hash.new
35
37
  @tags.update(tags) unless tags.nil?
36
38
  @log_records = Concurrent::Array.new
@@ -40,8 +42,14 @@ module LightStep
40
42
  @tracer = tracer
41
43
  self.operation_name = operation_name.to_s
42
44
  self.start_micros = start_micros
45
+
46
+ trace_id = (SpanContext === child_of ? child_of.trace_id : LightStep.guid)
43
47
  @span_context = SpanContext.new(id: LightStep.guid, trace_id: trace_id)
44
- set_tag(:parent_span_guid, child_of_id) if !child_of_id.nil?
48
+
49
+ if SpanContext === child_of
50
+ set_baggage(child_of.baggage)
51
+ set_tag(:parent_span_guid, child_of.id)
52
+ end
45
53
  end
46
54
 
47
55
  # Set a tag value on this span
@@ -53,72 +53,60 @@ module LightStep
53
53
  @reporter.period = seconds
54
54
  end
55
55
 
56
- # TODO(ngauthier@gmail.com) inherit SpanContext from references
56
+ # TODO(bhs): Support FollowsFrom and multiple references
57
57
 
58
58
  # Starts a new span.
59
- # @param operation_name [String] the operation name for the Span
60
- # @param child_of [Span] Span to inherit from
59
+ #
60
+ # @param operation_name [String] The operation name for the Span
61
+ # @param child_of [SpanContext] SpanContext that acts as a parent to
62
+ # the newly-started Span. If a Span instance is provided, its
63
+ # .span_context is automatically substituted.
61
64
  # @param start_time [Time] When the Span started, if not now
62
- # @param tags [Hash] tags for the span
65
+ # @param tags [Hash] Tags to assign to the Span at start time
63
66
  # @return [Span]
64
67
  def start_span(operation_name, child_of: nil, start_time: nil, tags: nil)
65
- child_of_id = nil
66
- trace_id = nil
67
- if Span === child_of
68
- child_of_id = child_of.span_context.id
69
- trace_id = child_of.span_context.trace_id
70
- else
71
- trace_id = LightStep.guid
72
- end
73
-
74
- span = Span.new(
68
+ Span.new(
75
69
  tracer: self,
76
70
  operation_name: operation_name,
77
- child_of_id: child_of_id,
78
- trace_id: trace_id,
71
+ child_of: child_of,
79
72
  start_micros: start_time.nil? ? LightStep.micros(Time.now) : LightStep.micros(start_time),
80
73
  tags: tags,
81
- max_log_records: max_log_records
74
+ max_log_records: max_log_records,
82
75
  )
83
-
84
- if Span === child_of
85
- span.set_baggage(child_of.span_context.baggage)
86
- end
87
-
88
- span
89
76
  end
90
77
 
91
- # Inject a span into the given carrier
92
- # @param span [Span]
78
+ # Inject a SpanContext into the given carrier
79
+ #
80
+ # @param spancontext [SpanContext]
93
81
  # @param format [LightStep::Tracer::FORMAT_TEXT_MAP, LightStep::Tracer::FORMAT_BINARY]
94
82
  # @param carrier [Hash]
95
- def inject(span, format, carrier)
83
+ def inject(span_context, format, carrier)
84
+ child_of = child_of.span_context if (Span === child_of)
96
85
  case format
97
86
  when LightStep::Tracer::FORMAT_TEXT_MAP
98
- inject_to_text_map(span, carrier)
87
+ inject_to_text_map(span_context, carrier)
99
88
  when LightStep::Tracer::FORMAT_BINARY
100
89
  warn 'Binary inject format not yet implemented'
101
90
  when LightStep::Tracer::FORMAT_RACK
102
- inject_to_rack(span, carrier)
91
+ inject_to_rack(span_context, carrier)
103
92
  else
104
93
  warn 'Unknown inject format'
105
94
  end
106
95
  end
107
96
 
108
- # Extract a span from a carrier
109
- # @param operation_name [String]
97
+ # Extract a SpanContext from a carrier
110
98
  # @param format [LightStep::Tracer::FORMAT_TEXT_MAP, LightStep::Tracer::FORMAT_BINARY]
111
99
  # @param carrier [Hash]
112
- # @return [Span]
113
- def extract(operation_name, format, carrier)
100
+ # @return [SpanContext] the extracted SpanContext or nil if none could be found
101
+ def extract(format, carrier)
114
102
  case format
115
103
  when LightStep::Tracer::FORMAT_TEXT_MAP
116
- extract_from_text_map(operation_name, carrier)
104
+ extract_from_text_map(carrier)
117
105
  when LightStep::Tracer::FORMAT_BINARY
118
106
  warn 'Binary join format not yet implemented'
119
107
  nil
120
108
  when LightStep::Tracer::FORMAT_RACK
121
- extract_from_rack(operation_name, carrier)
109
+ extract_from_rack(carrier)
122
110
  else
123
111
  warn 'Unknown join format'
124
112
  nil
@@ -192,32 +180,23 @@ module LightStep
192
180
  DEFAULT_MAX_SPAN_RECORDS = 1000
193
181
  MIN_MAX_SPAN_RECORDS = 1
194
182
 
195
- def inject_to_text_map(span, carrier)
196
- carrier[CARRIER_SPAN_ID] = span.span_context.id
197
- carrier[CARRIER_TRACE_ID] = span.span_context.trace_id unless span.span_context.trace_id.nil?
183
+ def inject_to_text_map(span_context, carrier)
184
+ carrier[CARRIER_SPAN_ID] = span_context.id
185
+ carrier[CARRIER_TRACE_ID] = span_context.trace_id unless span_context.trace_id.nil?
198
186
  carrier[CARRIER_SAMPLED] = 'true'
199
187
 
200
- span.span_context.baggage.each do |key, value|
188
+ span_context.baggage.each do |key, value|
201
189
  carrier[CARRIER_BAGGAGE_PREFIX + key] = value
202
190
  end
203
191
  end
204
192
 
205
- def extract_from_text_map(operation_name, carrier)
193
+ def extract_from_text_map(carrier)
206
194
  # If the carrier does not have both the span_id and trace_id key
207
195
  # skip the processing and just return a normal span
208
196
  if !carrier.has_key?(CARRIER_SPAN_ID) || !carrier.has_key?(CARRIER_TRACE_ID)
209
- return start_span(operation_name)
197
+ return nil
210
198
  end
211
199
 
212
- span = Span.new(
213
- tracer: self,
214
- operation_name: operation_name,
215
- start_micros: LightStep.micros(Time.now),
216
- child_of_id: carrier[CARRIER_SPAN_ID],
217
- trace_id: carrier[CARRIER_TRACE_ID],
218
- max_log_records: max_log_records
219
- )
220
-
221
200
  baggage = carrier.reduce({}) do |baggage, tuple|
222
201
  key, value = tuple
223
202
  if key.start_with?(CARRIER_BAGGAGE_PREFIX)
@@ -226,17 +205,19 @@ module LightStep
226
205
  end
227
206
  baggage
228
207
  end
229
- span.set_baggage(baggage)
230
-
231
- span
208
+ SpanContext.new(
209
+ id: carrier[CARRIER_SPAN_ID],
210
+ trace_id: carrier[CARRIER_TRACE_ID],
211
+ baggage: baggage,
212
+ )
232
213
  end
233
214
 
234
- def inject_to_rack(span, carrier)
235
- carrier[CARRIER_SPAN_ID] = span.span_context.id
236
- carrier[CARRIER_TRACE_ID] = span.span_context.trace_id unless span.span_context.trace_id.nil?
215
+ def inject_to_rack(span_context, carrier)
216
+ carrier[CARRIER_SPAN_ID] = span_context.id
217
+ carrier[CARRIER_TRACE_ID] = span_context.trace_id unless span_context.trace_id.nil?
237
218
  carrier[CARRIER_SAMPLED] = 'true'
238
219
 
239
- span.span_context.baggage.each do |key, value|
220
+ span_context.baggage.each do |key, value|
240
221
  if key =~ /[^A-Za-z0-9\-_]/
241
222
  # TODO: log the error internally
242
223
  next
@@ -245,8 +226,8 @@ module LightStep
245
226
  end
246
227
  end
247
228
 
248
- def extract_from_rack(operation_name, env)
249
- extract_from_text_map(operation_name, env.reduce({}){|memo, tuple|
229
+ def extract_from_rack(env)
230
+ extract_from_text_map(env.reduce({}){|memo, tuple|
250
231
  raw_header, value = tuple
251
232
  header = raw_header.gsub(/^HTTP_/, '').gsub("_", "-").downcase
252
233
 
@@ -1,3 +1,3 @@
1
1
  module LightStep
2
- VERSION = '0.10.9'.freeze
2
+ VERSION = '0.11.1'.freeze
3
3
  end
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.10.9
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - bcronin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-03 00:00:00.000000000 Z
11
+ date: 2017-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby