opentelemetry-sdk-experimental 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 +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +8 -0
- data/lib/opentelemetry/sdk/experimental/version.rb +1 -1
- data/lib/opentelemetry/sdk/trace/samplers/consistent_probability_based.rb +8 -25
- data/lib/opentelemetry/sdk/trace/samplers/consistent_probability_tracestate.rb +52 -17
- data/lib/opentelemetry/sdk/trace/samplers/parent_consistent_probability_based.rb +1 -26
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51a09141af347e88764533ef7ae7a072d1fe45935c61a04ffec0f92d535d90a7
|
4
|
+
data.tar.gz: 641bb04a0687ac7c67de416569270b394246f37bc9245435e53b954b93f0a4a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b531cbb38ca9d102377250b501b4ed4309336bc49432c0f8fb8070795d9849406fcb93324563fed99e0e9e4fc0dce30f55d7abe65ac639f2ae7a0e0b128c37fb
|
7
|
+
data.tar.gz: f833b0e558897fe05ec52dbe79ecf0a73d45b4783ed46f992fc73f7b556a8fe56bb806964115a35b8bfc80fcfa4de7b6b95fc31ef142241f2a9c11c6766275ac
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Release History: opentelemetry-sdk-experimental
|
2
2
|
|
3
|
+
### v0.2.0 / 2023-05-30
|
4
|
+
|
5
|
+
* FIXED: Consistent probability sampler init
|
6
|
+
* BREAKING CHANGE: Consistently pass tracestate
|
7
|
+
* BREAKING CHANGE: Set r in Parent CPS
|
8
|
+
|
9
|
+
### v0.1.1 / 2023-03-06
|
10
|
+
|
11
|
+
* FIXED: Reduce allocations in update_tracestate
|
12
|
+
* FIXED: Refactor consistent prob sampler for reuse
|
13
|
+
|
3
14
|
### v0.1.0 / 2022-11-09
|
4
15
|
|
5
16
|
* Initial release.
|
data/README.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Experimental SDK
|
2
|
+
|
3
|
+
The experimental SDK houses bleeding-edge(-ish) functionality that may have unstable APIs. Some examples of what's in
|
4
|
+
here:
|
5
|
+
|
6
|
+
* `traceresponse` propagator (in [w3c `trace-context` editor's draft](https://w3c.github.io/trace-context/))
|
7
|
+
* Consistent Probability Sampler (marked as `experimental` in [opentelemetry-specification)](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/tracestate-probability-sampling.md))
|
8
|
+
|
@@ -25,7 +25,7 @@ module OpenTelemetry
|
|
25
25
|
end
|
26
26
|
|
27
27
|
@p_floor = (Math.frexp(probability)[1] - 1).abs
|
28
|
-
@p_ceil = @p_floor
|
28
|
+
@p_ceil = @p_floor - 1
|
29
29
|
floor = Math.ldexp(1.0, -@p_floor)
|
30
30
|
ceil = Math.ldexp(1.0, -@p_ceil)
|
31
31
|
@p_ceil_probability = (probability - floor) / (ceil - floor)
|
@@ -42,39 +42,22 @@ module OpenTelemetry
|
|
42
42
|
def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:)
|
43
43
|
parent_span_context = OpenTelemetry::Trace.current_span(parent_context).context
|
44
44
|
p = probabilistic_p
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
r
|
49
|
-
|
50
|
-
generate_r(trace_id)
|
51
|
-
else
|
52
|
-
in_r
|
53
|
-
end
|
54
|
-
if p <= r
|
55
|
-
Result.new(decision: Decision::RECORD_AND_SAMPLE, tracestate: update_tracestate(tracestate, p, r, rest))
|
56
|
-
else
|
57
|
-
Result.new(decision: Decision::DROP, tracestate: update_tracestate(tracestate, nil, r, rest))
|
58
|
-
end
|
45
|
+
tracestate = parent_span_context.tracestate
|
46
|
+
parse_ot_vendor_tag(tracestate) do |_, r, rest|
|
47
|
+
if r.nil? || r > 62
|
48
|
+
OpenTelemetry.logger.debug("ConsistentProbabilitySampler: potentially inconsistent trace detected - r: #{r.inspect}") if parent_span_context.valid?
|
49
|
+
r = generate_r(trace_id)
|
59
50
|
end
|
60
|
-
else
|
61
|
-
r = generate_r(trace_id)
|
62
51
|
if p <= r
|
63
|
-
Result.new(decision: Decision::RECORD_AND_SAMPLE, tracestate:
|
52
|
+
Result.new(decision: Decision::RECORD_AND_SAMPLE, tracestate: update_tracestate(tracestate, p, r, rest))
|
64
53
|
else
|
65
|
-
Result.new(decision: Decision::DROP, tracestate:
|
54
|
+
Result.new(decision: Decision::DROP, tracestate: update_tracestate(tracestate, nil, r, rest))
|
66
55
|
end
|
67
56
|
end
|
68
57
|
end
|
69
58
|
|
70
59
|
private
|
71
60
|
|
72
|
-
def generate_r(trace_id)
|
73
|
-
x = trace_id[8, 8].unpack1('Q>') | 0x3
|
74
|
-
clz = 64 - x.bit_length
|
75
|
-
clz
|
76
|
-
end
|
77
|
-
|
78
61
|
def probabilistic_p
|
79
62
|
if Random.rand < @p_ceil_probability
|
80
63
|
@p_ceil
|
@@ -17,6 +17,40 @@ module OpenTelemetry
|
|
17
17
|
MAX_LIST_LENGTH = 256 # Defined by https://www.w3.org/TR/trace-context/
|
18
18
|
private_constant(:DECIMAL, :MAX_LIST_LENGTH)
|
19
19
|
|
20
|
+
private
|
21
|
+
|
22
|
+
# sanitized_tracestate returns an OpenTelemetry Tracestate object with the
|
23
|
+
# tracestate sanitized according to the Context invariants defined in the
|
24
|
+
# tracestate probability sampling spec.
|
25
|
+
#
|
26
|
+
# If r is nil after the sanitization, it is generated from the trace_id.
|
27
|
+
#
|
28
|
+
# This method assumes the parent span context is valid.
|
29
|
+
#
|
30
|
+
# @param trace_id [OpenTelemetry::Trace::TraceId] the trace id
|
31
|
+
# @param span_context [OpenTelemetry::Trace::SpanContext] the parent span context
|
32
|
+
# @return [OpenTelemetry::Trace::Tracestate] the sanitized tracestate
|
33
|
+
def sanitized_tracestate(trace_id, span_context)
|
34
|
+
sampled = span_context.trace_flags.sampled?
|
35
|
+
tracestate = span_context.tracestate
|
36
|
+
parse_ot_vendor_tag(tracestate) do |p, r, rest|
|
37
|
+
if !r.nil? && r > 62
|
38
|
+
p = r = nil
|
39
|
+
elsif !p.nil? && p > 63
|
40
|
+
p = nil
|
41
|
+
elsif !p.nil? && !r.nil? && !invariant(p, r, sampled)
|
42
|
+
p = nil
|
43
|
+
elsif !r.nil?
|
44
|
+
return tracestate
|
45
|
+
end
|
46
|
+
if r.nil?
|
47
|
+
OpenTelemetry.logger.debug("ConsistentProbabilitySampler: potentially inconsistent trace detected - r: #{r.inspect}")
|
48
|
+
r = generate_r(trace_id)
|
49
|
+
end
|
50
|
+
update_tracestate(tracestate, p, r, rest)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
20
54
|
# parse_ot_vendor_tag parses the 'ot' vendor tag of the tracestate.
|
21
55
|
# It yields the parsed probability fields and the remaining tracestate.
|
22
56
|
# It returns the result of the block.
|
@@ -44,27 +78,22 @@ module OpenTelemetry
|
|
44
78
|
end
|
45
79
|
|
46
80
|
def update_tracestate(tracestate, p, r, rest) # rubocop:disable Naming/UncommunicativeMethodParamName
|
47
|
-
|
48
|
-
# in the most common configuration of parent_consistent_probability_based(root: consistent_probability_based(p)).
|
49
|
-
ps = "p:#{p}" unless p.nil?
|
50
|
-
rs = "r:#{r}" unless r.nil?
|
51
|
-
ot = [ps, rs, rest].compact.join(';')
|
52
|
-
if ot.empty?
|
81
|
+
if p.nil? && r.nil? && rest.nil?
|
53
82
|
tracestate.delete('ot')
|
54
|
-
|
55
|
-
tracestate.set_value('ot',
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
if p.nil? && r.nil?
|
61
|
-
OpenTelemetry::Trace::Tracestate.DEFAULT
|
83
|
+
elsif p.nil? && r.nil?
|
84
|
+
tracestate.set_value('ot', rest)
|
85
|
+
elsif p.nil? && rest.nil?
|
86
|
+
tracestate.set_value('ot', "r:#{r}")
|
87
|
+
elsif r.nil? && rest.nil?
|
88
|
+
tracestate.set_value('ot', "p:#{p}")
|
62
89
|
elsif p.nil?
|
63
|
-
|
90
|
+
tracestate.set_value('ot', "r:#{r};#{rest}")
|
64
91
|
elsif r.nil?
|
65
|
-
|
92
|
+
tracestate.set_value('ot', "p:#{p};#{rest}")
|
93
|
+
elsif rest.nil?
|
94
|
+
tracestate.set_value('ot', "p:#{p};r:#{r}")
|
66
95
|
else
|
67
|
-
|
96
|
+
tracestate.set_value('ot', "p:#{p};r:#{r};#{rest}")
|
68
97
|
end
|
69
98
|
end
|
70
99
|
|
@@ -75,6 +104,12 @@ module OpenTelemetry
|
|
75
104
|
def decimal(str)
|
76
105
|
str.to_i if !str.nil? && DECIMAL.match?(str)
|
77
106
|
end
|
107
|
+
|
108
|
+
def generate_r(trace_id)
|
109
|
+
x = trace_id[8, 8].unpack1('Q>') | 0x3
|
110
|
+
clz = 64 - x.bit_length
|
111
|
+
clz
|
112
|
+
end
|
78
113
|
end
|
79
114
|
end
|
80
115
|
end
|
@@ -43,7 +43,7 @@ module OpenTelemetry
|
|
43
43
|
if !parent_span_context.valid?
|
44
44
|
@root.should_sample?(trace_id: trace_id, parent_context: parent_context, links: links, name: name, kind: kind, attributes: attributes)
|
45
45
|
else
|
46
|
-
tracestate = sanitized_tracestate(parent_span_context)
|
46
|
+
tracestate = sanitized_tracestate(trace_id, parent_span_context)
|
47
47
|
if parent_span_context.trace_flags.sampled?
|
48
48
|
Result.new(decision: Decision::RECORD_AND_SAMPLE, tracestate: tracestate)
|
49
49
|
else
|
@@ -55,31 +55,6 @@ module OpenTelemetry
|
|
55
55
|
protected
|
56
56
|
|
57
57
|
attr_reader :root
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
# sanitized_tracestate returns an OpenTelemetry Tracestate object with the
|
62
|
-
# tracestate sanitized according to the Context invariants defined in the
|
63
|
-
# tracestate probability sampling spec.
|
64
|
-
#
|
65
|
-
# @param span_context [OpenTelemetry::Trace::SpanContext] the parent span context
|
66
|
-
# @return [OpenTelemetry::Trace::Tracestate] the sanitized tracestate
|
67
|
-
def sanitized_tracestate(span_context)
|
68
|
-
sampled = span_context.trace_flags.sampled?
|
69
|
-
tracestate = span_context.tracestate
|
70
|
-
parse_ot_vendor_tag(tracestate) do |p, r, rest|
|
71
|
-
if !r.nil? && r > 62
|
72
|
-
p = r = nil
|
73
|
-
elsif !p.nil? && p > 63
|
74
|
-
p = nil
|
75
|
-
elsif !p.nil? && !r.nil? && !invariant(p, r, sampled)
|
76
|
-
p = nil
|
77
|
-
else
|
78
|
-
return tracestate
|
79
|
-
end
|
80
|
-
update_tracestate(tracestate, p, r, rest)
|
81
|
-
end
|
82
|
-
end
|
83
58
|
end
|
84
59
|
end
|
85
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentelemetry-sdk-experimental
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OpenTelemetry Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-api
|
@@ -188,6 +188,7 @@ files:
|
|
188
188
|
- ".yardopts"
|
189
189
|
- CHANGELOG.md
|
190
190
|
- LICENSE
|
191
|
+
- README.md
|
191
192
|
- lib/opentelemetry-sdk-experimental.rb
|
192
193
|
- lib/opentelemetry/sdk/experimental.rb
|
193
194
|
- lib/opentelemetry/sdk/experimental/samplers_patch.rb
|
@@ -200,10 +201,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
|
|
200
201
|
licenses:
|
201
202
|
- Apache-2.0
|
202
203
|
metadata:
|
203
|
-
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk-experimental/v0.
|
204
|
-
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/
|
204
|
+
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk-experimental/v0.2.0/file.CHANGELOG.html
|
205
|
+
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/sdk_experimental
|
205
206
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
|
206
|
-
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk-experimental/v0.
|
207
|
+
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk-experimental/v0.2.0
|
207
208
|
post_install_message:
|
208
209
|
rdoc_options: []
|
209
210
|
require_paths:
|