opencensus 0.1.0 → 0.2.0

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: 47862e6aad5e10aa18a54f75679e2886c753127d
4
- data.tar.gz: a534f715d68bb80323efe18ff61eab3776f6365c
3
+ metadata.gz: 90ff804d909c01ac8eb0ba83fd0add78451b186f
4
+ data.tar.gz: 16805cbe660a480f7aa52a3e3cb25ff8a799f039
5
5
  SHA512:
6
- metadata.gz: 67d7652f2ffd69c7338b975ef1b9200054dda31bd9bc64283ef4038ac1afb46b57780cd97ffaa6bd1dfc2403de84842c7b83e3020cfdfcdfee1b3083dd480513
7
- data.tar.gz: bad91bedd06219d6669a1982b25853d7a9fffb4a2de2ef4fc5c3297c1937a6d72e8eec1928f68d12e94d9df689dcb6ca8d11622585d0720861e46070f7f5fe35
6
+ metadata.gz: 6be6ad106a73d7f5972e5eba7af5449a484bc04e6c967ffd3d59d4776bb4c9d2d79308938fe0d7bc538f4d95b0fc567c286a9d21056a9695e52ac5c049016597
7
+ data.tar.gz: 9557b149c2ba5997152d511c22149b2c21922e6ec723d7fa0ecf0571f83440afd086e2a6a1c8c4e55bbd5f22989f4bbc434ccd298525d9a428c70b6739e79954
@@ -0,0 +1,18 @@
1
+ # Release History
2
+
3
+ ### 0.2.0 / 2018-02-13
4
+
5
+ * Span creation sets the "same_process_as_parent_span" field if possible.
6
+ * The "stack_trace_hash_id" field was missing from the interfaces. Fixed.
7
+ * Nullability of a few fields did not match the proto specs. Fixed.
8
+ * Fixed some documentation errors and omissions.
9
+
10
+ ### 0.1.0 / 2018-01-12
11
+
12
+ Initial release of the core library, including:
13
+
14
+ * Trace interfaces
15
+ * Rack integration
16
+ * Rails integration
17
+ * Faraday integration
18
+ * Logging exporter
data/README.md CHANGED
@@ -130,7 +130,7 @@ config.opencensus.trace.default_sampler =
130
130
  config.opencensus.trace.default_max_attributes = 16
131
131
  ```
132
132
 
133
- You can configure a variety of core OpenCensuys options, including:
133
+ You can configure a variety of core OpenCensus options, including:
134
134
 
135
135
  * Sampling, which controls how often a request is traced.
136
136
  * Exporting, which controls how trace information is reported.
data/Rakefile CHANGED
@@ -17,4 +17,8 @@ YARD::Rake::YardocTask.new do |t|
17
17
  t.stats_options = ['--list-undoc'] # optional
18
18
  end
19
19
 
20
+ task :faster do
21
+ ENV["FASTER_TESTS"] = "true"
22
+ end
23
+
20
24
  task :default => [:test, :rubocop, :yard]
@@ -88,9 +88,14 @@ module OpenCensus
88
88
  #
89
89
  # @param [TraceContextData] trace_context The request's incoming trace
90
90
  # context (optional)
91
- #
92
- def start_request_trace trace_context: nil
93
- span_context = SpanContext.create_root trace_context: trace_context
91
+ # @param [boolean, nil] same_process_as_parent Set to `true` if the parent
92
+ # span is local, `false` if it is remote, or `nil` if there is no
93
+ # parent span or this information is not available.
94
+ #
95
+ def start_request_trace trace_context: nil, same_process_as_parent: nil
96
+ span_context = SpanContext.create_root \
97
+ trace_context: trace_context,
98
+ same_process_as_parent: same_process_as_parent
94
99
  self.span_context = span_context
95
100
  if block_given?
96
101
  begin
@@ -48,6 +48,9 @@ module OpenCensus
48
48
 
49
49
  private
50
50
 
51
+ # rubocop:disable Metrics/MethodLength
52
+ # rubocop:disable Metrics/AbcSize
53
+
51
54
  def format_span span
52
55
  {
53
56
  name: format_value(span.name),
@@ -60,6 +63,7 @@ module OpenCensus
60
63
  dropped_attributes_count: span.dropped_attributes_count,
61
64
  stack_trace: span.stack_trace,
62
65
  dropped_frames_count: span.dropped_frames_count,
66
+ stack_trace_hash_id: span.stack_trace_hash_id,
63
67
  time_events: span.time_events.map { |te| format_time_event(te) },
64
68
  dropped_annotations_count: span.dropped_annotations_count,
65
69
  dropped_message_events_count: span.dropped_message_events_count,
@@ -71,6 +75,9 @@ module OpenCensus
71
75
  }
72
76
  end
73
77
 
78
+ # rubocop:enable Metrics/MethodLength
79
+ # rubocop:enable Metrics/AbcSize
80
+
74
81
  def format_time_event time_event
75
82
  case time_event
76
83
  when Annotation
@@ -70,7 +70,9 @@ module OpenCensus
70
70
  context = formatter.deserialize env[formatter.rack_header_name]
71
71
  end
72
72
 
73
- Trace.start_request_trace trace_context: context do |span_context|
73
+ Trace.start_request_trace \
74
+ trace_context: context,
75
+ same_process_as_parent: false do |span_context|
74
76
  begin
75
77
  span_context.in_span get_path(env) do |span|
76
78
  start_request span, env
@@ -58,7 +58,7 @@ module OpenCensus
58
58
  # The number of compressed bytes sent or received. If zero, assumed to
59
59
  # be the same size as uncompressed.
60
60
  #
61
- # @return [Integer, nil]
61
+ # @return [Integer]
62
62
  #
63
63
  attr_reader :compressed_size
64
64
 
@@ -67,7 +67,7 @@ module OpenCensus
67
67
  #
68
68
  # @private
69
69
  #
70
- def initialize type, id, uncompressed_size, compressed_size: nil,
70
+ def initialize type, id, uncompressed_size, compressed_size: 0,
71
71
  time: nil
72
72
  super time: time
73
73
  @type = type
@@ -79,6 +79,9 @@ module OpenCensus
79
79
  # The number of attributes that were discarded. Attributes can be
80
80
  # discarded because their keys are too long or because there are too
81
81
  # many attributes. If this value is 0, then no attributes were dropped.
82
+ #
83
+ # @return [Integer]
84
+ #
82
85
  attr_reader :dropped_attributes_count
83
86
 
84
87
  ##
@@ -88,6 +91,15 @@ module OpenCensus
88
91
  #
89
92
  attr_reader :stack_trace
90
93
 
94
+ ##
95
+ # A hash of the stack trace. This may be used by exporters to identify
96
+ # duplicate stack traces transmitted in the same request; only one copy
97
+ # of the actual data needs to be sent.
98
+ #
99
+ # @return [Integer]
100
+ #
101
+ attr_reader :stack_trace_hash_id
102
+
91
103
  ##
92
104
  # The number of stack frames that were dropped because there were too many
93
105
  # stack frames. If this value is 0, then no stack frames were dropped.
@@ -138,6 +150,7 @@ module OpenCensus
138
150
  # An optional final status for this span.
139
151
  #
140
152
  # @return [Status, nil]
153
+ #
141
154
  attr_reader :status
142
155
 
143
156
  ##
@@ -145,7 +158,7 @@ module OpenCensus
145
158
  # crosses a process boundary. True when the parent_span belongs to the
146
159
  # same process as the current span.
147
160
  #
148
- # @return [Boolean]
161
+ # @return [boolean, nil]
149
162
  #
150
163
  attr_reader :same_process_as_parent_span
151
164
 
@@ -170,7 +183,7 @@ module OpenCensus
170
183
  dropped_annotations_count: 0,
171
184
  dropped_message_events_count: 0, links: [],
172
185
  dropped_links_count: 0, status: nil,
173
- same_process_as_parent_span: true,
186
+ same_process_as_parent_span: nil,
174
187
  child_span_count: nil
175
188
  @name = name
176
189
  @trace_id = trace_id
@@ -181,6 +194,8 @@ module OpenCensus
181
194
  @attributes = attributes
182
195
  @dropped_attributes_count = dropped_attributes_count
183
196
  @stack_trace = stack_trace
197
+ @stack_trace_hash_id = [stack_trace, dropped_frames_count].hash
198
+ @stack_trace_hash_id = -1 if @stack_trace_hash_id.zero?
184
199
  @dropped_frames_count = dropped_frames_count
185
200
  @time_events = time_events
186
201
  @dropped_annotations_count = dropped_annotations_count
@@ -279,6 +279,21 @@ module OpenCensus
279
279
  ##
280
280
  # Return a read-only version of this span
281
281
  #
282
+ # @param [Integer, nil] max_attributes The maximum number of attributes
283
+ # to save, or `nil` to use the config value.
284
+ # @param [Integer, nil] max_stack_frames The maximum number of stack
285
+ # frames to save, or `nil` to use the config value.
286
+ # @param [Integer, nil] max_annotations The maximum number of annotations
287
+ # to save, or `nil` to use the config value.
288
+ # @param [Integer, nil] max_message_events The maximum number of message
289
+ # events to save, or `nil` to use the config value.
290
+ # @param [Integer, nil] max_links The maximum number of links to save,
291
+ # or `nil` to use the config value.
292
+ # @param [Integer, nil] max_string_length The maximum length in bytes for
293
+ # truncated strings, or `nil` to use the config value.
294
+ # @param [Integer, nil] child_span_count The number of child spans to
295
+ # declare, or `nil` to omit the `child_span_count` field.
296
+ #
282
297
  # @return [Span]
283
298
  #
284
299
  def to_span max_attributes: nil,
@@ -287,7 +302,7 @@ module OpenCensus
287
302
  max_message_events: nil,
288
303
  max_links: nil,
289
304
  max_string_length: nil,
290
- same_process_as_parent_span: nil
305
+ child_span_count: nil
291
306
 
292
307
  raise "Span must have start_time" unless @start_time
293
308
  raise "Span must have end_time" unless @end_time
@@ -312,6 +327,7 @@ module OpenCensus
312
327
  built_links = builder.convert_links @links
313
328
  dropped_links_count = @links.size - built_links.size
314
329
  built_status = builder.convert_status @status_code, @status_message
330
+ same_process_as_parent_span = context.parent.same_process_as_parent
315
331
 
316
332
  Span.new trace_id, span_id, built_name, @start_time, @end_time,
317
333
  parent_span_id: parent_span_id,
@@ -325,7 +341,8 @@ module OpenCensus
325
341
  links: built_links,
326
342
  dropped_links_count: dropped_links_count,
327
343
  status: built_status,
328
- same_process_as_parent_span: same_process_as_parent_span
344
+ same_process_as_parent_span: same_process_as_parent_span,
345
+ child_span_count: child_span_count
329
346
  end
330
347
 
331
348
  # rubocop:enable Metrics/MethodLength
@@ -15,9 +15,9 @@
15
15
  module OpenCensus
16
16
  module Trace
17
17
  ##
18
- # Span represents a span in a trace record. Spans are contained in
19
- # a trace and arranged in a forest. That is, each span may be a root span
20
- # or have a parent span, and may have zero or more children.
18
+ # SpanContext represents the context within which a span may be created.
19
+ # It includes the ID of the parent trace, the ID of the parent span, and
20
+ # sampling state.
21
21
  #
22
22
  class SpanContext
23
23
  ##
@@ -51,19 +51,23 @@ module OpenCensus
51
51
  #
52
52
  # @param [TraceContextData] trace_context The request's incoming trace
53
53
  # context (optional)
54
+ # @param [boolean, nil] same_process_as_parent Set to `true` if the
55
+ # parent span is local, `false` if it is remote, or `nil` if there
56
+ # is no parent span or this information is not available.
54
57
  #
55
58
  # @return [SpanContext]
56
59
  #
57
- def create_root trace_context: nil
60
+ def create_root trace_context: nil, same_process_as_parent: nil
58
61
  if trace_context
59
62
  trace_data = TraceData.new \
60
63
  trace_context.trace_id, trace_context.trace_options, {}
61
- new trace_data, nil, trace_context.span_id
64
+ new trace_data, nil, trace_context.span_id,
65
+ same_process_as_parent
62
66
  else
63
67
  trace_id = rand 1..MAX_TRACE_ID
64
68
  trace_id = trace_id.to_s(16).rjust(32, "0")
65
69
  trace_data = TraceData.new trace_id, 0, {}
66
- new trace_data, nil, ""
70
+ new trace_data, nil, "", nil
67
71
  end
68
72
  end
69
73
  end
@@ -132,6 +136,14 @@ module OpenCensus
132
136
  #
133
137
  attr_reader :span_id
134
138
 
139
+ ##
140
+ # Whether the parent of spans created by this context is local, or `nil`
141
+ # if this context creates root spans or this information is unknown.
142
+ #
143
+ # @return [boolean, nil]
144
+ #
145
+ attr_reader :same_process_as_parent
146
+
135
147
  ##
136
148
  # Whether the context (e.g. the parent span) has been sampled. This
137
149
  # information may be used in sampling decisions for new spans.
@@ -227,10 +239,35 @@ module OpenCensus
227
239
  # Does not build any ancestor spans. If you want the entire span tree
228
240
  # built, call this method on the `#root` context.
229
241
  #
242
+ # @param [Integer, nil] max_attributes The maximum number of attributes
243
+ # to save, or `nil` to use the config value.
244
+ # @param [Integer, nil] max_stack_frames The maximum number of stack
245
+ # frames to save, or `nil` to use the config value.
246
+ # @param [Integer, nil] max_annotations The maximum number of annotations
247
+ # to save, or `nil` to use the config value.
248
+ # @param [Integer, nil] max_message_events The maximum number of message
249
+ # events to save, or `nil` to use the config value.
250
+ # @param [Integer, nil] max_links The maximum number of links to save,
251
+ # or `nil` to use the config value.
252
+ # @param [Integer, nil] max_string_length The maximum length in bytes for
253
+ # truncated strings, or `nil` to use the config value.
254
+ #
230
255
  # @return [Array<Span>] Built Span objects
231
256
  #
232
- def build_contained_spans
233
- contained_span_builders.find_all(&:finished?).map(&:to_span)
257
+ def build_contained_spans max_attributes: nil,
258
+ max_stack_frames: nil,
259
+ max_annotations: nil,
260
+ max_message_events: nil,
261
+ max_links: nil,
262
+ max_string_length: nil
263
+ contained_span_builders.find_all(&:finished?).map do |sb|
264
+ sb.to_span max_attributes: max_attributes,
265
+ max_stack_frames: max_stack_frames,
266
+ max_annotations: max_annotations,
267
+ max_message_events: max_message_events,
268
+ max_links: max_links,
269
+ max_string_length: max_string_length
270
+ end
234
271
  end
235
272
 
236
273
  ##
@@ -240,10 +277,11 @@ module OpenCensus
240
277
  #
241
278
  # @private
242
279
  #
243
- def initialize trace_data, parent, span_id
280
+ def initialize trace_data, parent, span_id, same_process_as_parent
244
281
  @trace_data = trace_data
245
282
  @parent = parent
246
283
  @span_id = span_id
284
+ @same_process_as_parent = same_process_as_parent
247
285
  end
248
286
 
249
287
  ##
@@ -289,7 +327,7 @@ module OpenCensus
289
327
  child_span_id = rand 1..MAX_SPAN_ID
290
328
  child_span_id = child_span_id.to_s(16).rjust(16, "0")
291
329
  unless @trace_data.span_map.key? child_span_id
292
- return SpanContext.new @trace_data, self, child_span_id
330
+ return SpanContext.new @trace_data, self, child_span_id, true
293
331
  end
294
332
  end
295
333
  end
@@ -14,5 +14,5 @@
14
14
 
15
15
  module OpenCensus
16
16
  ## Current OpenCensus version
17
- VERSION = "0.1.0".freeze
17
+ VERSION = "0.2.0".freeze
18
18
  end
@@ -6,8 +6,8 @@ require "opencensus/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "opencensus"
8
8
  spec.version = OpenCensus::VERSION
9
- spec.authors = ["Jeff Ching"]
10
- spec.email = ["chingor@google.com"]
9
+ spec.authors = ["Jeff Ching", "Daniel Azuma"]
10
+ spec.email = ["chingor@google.com", "dazuma@google.com"]
11
11
 
12
12
  spec.summary = %q{A stats collection and distributed tracing framework}
13
13
  spec.description = %q{A stats collection and distributed tracing framework}
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opencensus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Ching
8
+ - Daniel Azuma
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2018-01-12 00:00:00.000000000 Z
12
+ date: 2018-02-13 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -125,6 +126,7 @@ dependencies:
125
126
  description: A stats collection and distributed tracing framework
126
127
  email:
127
128
  - chingor@google.com
129
+ - dazuma@google.com
128
130
  executables: []
129
131
  extensions: []
130
132
  extra_rdoc_files: []
@@ -133,6 +135,7 @@ files:
133
135
  - ".rubocop.yml"
134
136
  - ".travis.yml"
135
137
  - AUTHORS
138
+ - CHANGELOG.md
136
139
  - CODE_OF_CONDUCT.md
137
140
  - CONTRIBUTING.md
138
141
  - Gemfile