opentelemetry-sdk 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b0251902390864d89d8f00496f9ae36adcf3a52d1a84c574a73a107ccea70f0
4
- data.tar.gz: ed15513dcd3d4decc53a0923db83c8e10d9b65a86247775c05d354212c1439c8
3
+ metadata.gz: 7bdebb54966352742da13ac2700b592e49a9f06a751961f7e9d41e70cf855c29
4
+ data.tar.gz: 4a977ef6391a6c76b6c333797abab87aba952ee357541b482b72441156c4a7fc
5
5
  SHA512:
6
- metadata.gz: e3954c44377c4250f6dd2dcba2f88a781aa34acec642f19996014014c9d49ce3733846956043f09ce548ceee0362befa9ff9af660f894c39a446bdca5e0d7fb3
7
- data.tar.gz: f8ddde936a93b87682a2f85a0d3a800ed0de25643bce04e420d01c8565c2ed33548dda6174c213d868aab82fe5398868144051690601d2b49015ea48bd999b9f
6
+ metadata.gz: 8c54d7a07907e48fcef2e9bcab362ca15e8f86d290daa9e88fc2118135004e734fb136998d7f4f46ac419e3a193775dd9ad5fb572fb170d71bd909c9f01a419b
7
+ data.tar.gz: be5d9d93ae1f824a250f8dbea0ca63d5318c1d109bc3d83a9a7d237305a2de899c102dd144eb9f03ecb6f653af7415616deecbf609ca30fba7a9941532d88d2a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Release History: opentelemetry-sdk
2
2
 
3
+ ### v1.0.2 / 2021-12-01
4
+
5
+ * FIXED: Default span kind
6
+ * FIXED: Use monotonic clock where possible
7
+
3
8
  ### v1.0.1 / 2021-10-29
4
9
 
5
10
  * FIXED: Add unexpected error handlign in BSP and OTLP exporter (#995)
@@ -131,7 +131,7 @@ module OpenTelemetry
131
131
  #
132
132
  # @return [self] returns itself
133
133
  def add_event(name, attributes: nil, timestamp: nil)
134
- event = Event.new(name, truncate_attribute_values(attributes), wall_clock(timestamp))
134
+ event = Event.new(name, truncate_attribute_values(attributes), relative_timestamp(timestamp))
135
135
 
136
136
  @mutex.synchronize do
137
137
  if @ended
@@ -233,7 +233,7 @@ module OpenTelemetry
233
233
  OpenTelemetry.logger.warn('Calling finish on an ended Span.')
234
234
  return self
235
235
  end
236
- @end_timestamp = wall_clock(end_timestamp)
236
+ @end_timestamp = relative_timestamp(end_timestamp)
237
237
  @attributes = validated_attributes(@attributes).freeze
238
238
  @events.freeze
239
239
  @ended = true
@@ -276,7 +276,7 @@ module OpenTelemetry
276
276
  end
277
277
 
278
278
  # @api private
279
- def initialize(context, parent_context, name, kind, parent_span_id, span_limits, span_processors, attributes, links, start_timestamp, resource, instrumentation_library) # rubocop:disable Metrics/AbcSize
279
+ def initialize(context, parent_context, parent_span, name, kind, parent_span_id, span_limits, span_processors, attributes, links, start_timestamp, resource, instrumentation_library) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
280
280
  super(span_context: context)
281
281
  @mutex = Mutex.new
282
282
  @name = name
@@ -291,17 +291,45 @@ module OpenTelemetry
291
291
  @total_recorded_events = 0
292
292
  @total_recorded_links = links&.size || 0
293
293
  @total_recorded_attributes = attributes&.size || 0
294
- @start_timestamp = wall_clock(start_timestamp)
295
- @end_timestamp = nil
296
294
  @attributes = attributes.nil? ? nil : Hash[attributes] # We need a mutable copy of attributes.
297
295
  trim_span_attributes(@attributes)
298
296
  @events = nil
299
297
  @links = trim_links(links, span_limits.link_count_limit, span_limits.link_attribute_count_limit)
298
+
299
+ # Times are hard. Whenever an explicit timestamp is provided
300
+ # (for Events or for the Span start_timestamp or end_timestamp),
301
+ # we use that as the recorded timestamp. An implicit Event timestamp
302
+ # and end_timestamp is computed as a monotonic clock offset from
303
+ # the realtime start_timestamp. The realtime start_timestamp is
304
+ # computed as a monotonic clock offset from the realtime
305
+ # start_timestamp of its parent span, if available, or it is
306
+ # fetched from the realtime system clock.
307
+ #
308
+ # We therefore have 3 start timestamps. The first two are used
309
+ # internally (and by child spans) to compute other timestamps.
310
+ # The last is the start timestamp actually recorded in the
311
+ # SpanData.
312
+ @monotonic_start_timestamp = monotonic_now
313
+ @realtime_start_timestamp = if parent_span.recording?
314
+ relative_realtime(parent_span.realtime_start_timestamp, parent_span.monotonic_start_timestamp)
315
+ else
316
+ realtime_now
317
+ end
318
+ @start_timestamp = if start_timestamp
319
+ time_in_nanoseconds(start_timestamp)
320
+ else
321
+ @realtime_start_timestamp
322
+ end
323
+ @end_timestamp = nil
300
324
  @span_processors.each { |processor| processor.on_start(self, parent_context) }
301
325
  end
302
326
 
303
327
  # TODO: Java implementation overrides finalize to log if a span isn't finished.
304
328
 
329
+ protected
330
+
331
+ attr_reader :monotonic_start_timestamp, :realtime_start_timestamp
332
+
305
333
  private
306
334
 
307
335
  def validated_attributes(attrs)
@@ -376,9 +404,26 @@ module OpenTelemetry
376
404
  events << event
377
405
  end
378
406
 
379
- def wall_clock(timestamp)
380
- timestamp = (timestamp.to_r * 1_000_000_000).to_i unless timestamp.nil?
381
- timestamp || Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)
407
+ def relative_timestamp(timestamp)
408
+ return time_in_nanoseconds(timestamp) unless timestamp.nil?
409
+
410
+ relative_realtime(realtime_start_timestamp, monotonic_start_timestamp)
411
+ end
412
+
413
+ def time_in_nanoseconds(timestamp)
414
+ (timestamp.to_r * 1_000_000_000).to_i
415
+ end
416
+
417
+ def relative_realtime(realtime_base, monotonic_base)
418
+ realtime_base + (monotonic_now - monotonic_base)
419
+ end
420
+
421
+ def realtime_now
422
+ Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)
423
+ end
424
+
425
+ def monotonic_now
426
+ Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
382
427
  end
383
428
  end
384
429
  # rubocop:enable Metrics/ClassLength
@@ -31,12 +31,14 @@ module OpenTelemetry
31
31
  name ||= 'empty'
32
32
 
33
33
  with_parent ||= Context.current
34
+ parent_span = OpenTelemetry::Trace.current_span(with_parent)
34
35
  parent_span_context = OpenTelemetry::Trace.current_span(with_parent).context
35
36
  if parent_span_context.valid?
36
37
  parent_span_id = parent_span_context.span_id
37
38
  trace_id = parent_span_context.trace_id
38
39
  end
39
- @tracer_provider.internal_create_span(name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, with_parent, @instrumentation_library)
40
+
41
+ @tracer_provider.internal_create_span(name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, with_parent, parent_span, @instrumentation_library)
40
42
  end
41
43
  end
42
44
  end
@@ -126,8 +126,15 @@ module OpenTelemetry
126
126
  end
127
127
 
128
128
  # @api private
129
- def internal_create_span(name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, parent_context, instrumentation_library) # rubocop:disable Metrics/MethodLength
129
+ def internal_create_span(name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, parent_context, parent_span, instrumentation_library) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
130
+ parent_span_context = parent_span.context
131
+ if parent_span_context.valid?
132
+ parent_span_id = parent_span_context.span_id
133
+ trace_id = parent_span_context.trace_id
134
+ end
135
+ name ||= 'empty'
130
136
  trace_id ||= @id_generator.generate_trace_id
137
+ kind ||= :internal
131
138
  result = @sampler.should_sample?(trace_id: trace_id, parent_context: parent_context, links: links, name: name, kind: kind, attributes: attributes)
132
139
  span_id = @id_generator.generate_span_id
133
140
  if result.recording? && !@stopped
@@ -137,6 +144,7 @@ module OpenTelemetry
137
144
  Span.new(
138
145
  context,
139
146
  parent_context,
147
+ parent_span,
140
148
  name,
141
149
  kind,
142
150
  parent_span_id,
@@ -7,6 +7,6 @@
7
7
  module OpenTelemetry
8
8
  module SDK
9
9
  ## Current OpenTelemetry version
10
- VERSION = '1.0.1'
10
+ VERSION = '1.0.2'
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-01 00:00:00.000000000 Z
11
+ date: 2021-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.19.2
33
+ version: 0.19.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.19.2
40
+ version: 0.19.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: opentelemetry-instrumentation-base
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.18.3
47
+ version: 0.19.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.18.3
54
+ version: 0.19.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: opentelemetry-semantic_conventions
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -265,10 +265,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
265
265
  licenses:
266
266
  - Apache-2.0
267
267
  metadata:
268
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v1.0.1/file.CHANGELOG.html
268
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v1.0.2/file.CHANGELOG.html
269
269
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/sdk
270
270
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
271
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v1.0.1
271
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v1.0.2
272
272
  post_install_message:
273
273
  rdoc_options: []
274
274
  require_paths: