finagle-thrift 1.2.0 → 1.3.1
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.
|
@@ -21,7 +21,7 @@ module FinagleThrift
|
|
|
21
21
|
header.parent_span_id = Trace.id.parent_id.to_i
|
|
22
22
|
header.span_id = Trace.id.span_id.to_i
|
|
23
23
|
header.sampled = Trace.id.sampled?
|
|
24
|
-
header.
|
|
24
|
+
header.flags = Trace.id.flags.to_i
|
|
25
25
|
|
|
26
26
|
header.client_id = client_id if client_id
|
|
27
27
|
|
|
@@ -43,11 +43,13 @@ module FinagleThrift
|
|
|
43
43
|
TIMESTAMP = 1
|
|
44
44
|
VALUE = 2
|
|
45
45
|
HOST = 3
|
|
46
|
+
DURATION = 4
|
|
46
47
|
|
|
47
48
|
FIELDS = {
|
|
48
49
|
TIMESTAMP => {:type => ::Thrift::Types::I64, :name => 'timestamp'},
|
|
49
50
|
VALUE => {:type => ::Thrift::Types::STRING, :name => 'value'},
|
|
50
|
-
HOST => {:type => ::Thrift::Types::STRUCT, :name => 'host', :class => FinagleThrift::Endpoint, :optional => true}
|
|
51
|
+
HOST => {:type => ::Thrift::Types::STRUCT, :name => 'host', :class => FinagleThrift::Endpoint, :optional => true},
|
|
52
|
+
DURATION => {:type => ::Thrift::Types::I32, :name => 'duration', :optional => true}
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
def struct_fields; FIELDS; end
|
|
@@ -91,6 +93,7 @@ module FinagleThrift
|
|
|
91
93
|
PARENT_ID = 5
|
|
92
94
|
ANNOTATIONS = 6
|
|
93
95
|
BINARY_ANNOTATIONS = 8
|
|
96
|
+
DEBUG = 9
|
|
94
97
|
|
|
95
98
|
FIELDS = {
|
|
96
99
|
TRACE_ID => {:type => ::Thrift::Types::I64, :name => 'trace_id'},
|
|
@@ -98,7 +101,8 @@ module FinagleThrift
|
|
|
98
101
|
ID => {:type => ::Thrift::Types::I64, :name => 'id'},
|
|
99
102
|
PARENT_ID => {:type => ::Thrift::Types::I64, :name => 'parent_id', :optional => true},
|
|
100
103
|
ANNOTATIONS => {:type => ::Thrift::Types::LIST, :name => 'annotations', :element => {:type => ::Thrift::Types::STRUCT, :class => FinagleThrift::Annotation}},
|
|
101
|
-
BINARY_ANNOTATIONS => {:type => ::Thrift::Types::LIST, :name => 'binary_annotations', :element => {:type => ::Thrift::Types::STRUCT, :class => FinagleThrift::BinaryAnnotation}}
|
|
104
|
+
BINARY_ANNOTATIONS => {:type => ::Thrift::Types::LIST, :name => 'binary_annotations', :element => {:type => ::Thrift::Types::STRUCT, :class => FinagleThrift::BinaryAnnotation}},
|
|
105
|
+
DEBUG => {:type => ::Thrift::Types::BOOL, :name => 'debug'}
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
def struct_fields; FIELDS; end
|
|
@@ -134,17 +138,17 @@ module FinagleThrift
|
|
|
134
138
|
TRACE_ID = 1
|
|
135
139
|
SPAN_ID = 2
|
|
136
140
|
PARENT_SPAN_ID = 3
|
|
137
|
-
DEBUG = 4
|
|
138
141
|
SAMPLED = 5
|
|
139
142
|
CLIENT_ID = 6
|
|
143
|
+
FLAGS = 7
|
|
140
144
|
|
|
141
145
|
FIELDS = {
|
|
142
146
|
TRACE_ID => {:type => ::Thrift::Types::I64, :name => 'trace_id'},
|
|
143
147
|
SPAN_ID => {:type => ::Thrift::Types::I64, :name => 'span_id'},
|
|
144
148
|
PARENT_SPAN_ID => {:type => ::Thrift::Types::I64, :name => 'parent_span_id', :optional => true},
|
|
145
|
-
DEBUG => {:type => ::Thrift::Types::BOOL, :name => 'debug'},
|
|
146
149
|
SAMPLED => {:type => ::Thrift::Types::BOOL, :name => 'sampled', :optional => true},
|
|
147
|
-
CLIENT_ID => {:type => ::Thrift::Types::STRUCT, :name => 'client_id', :class => FinagleThrift::ClientId, :optional => true}
|
|
150
|
+
CLIENT_ID => {:type => ::Thrift::Types::STRUCT, :name => 'client_id', :class => FinagleThrift::ClientId, :optional => true},
|
|
151
|
+
FLAGS => {:type => ::Thrift::Types::I64, :name => 'flags', :optional => true}
|
|
148
152
|
}
|
|
149
153
|
|
|
150
154
|
def struct_fields; FIELDS; end
|
data/lib/finagle-thrift/trace.rb
CHANGED
|
@@ -6,7 +6,7 @@ module Trace
|
|
|
6
6
|
def id
|
|
7
7
|
if stack.empty?
|
|
8
8
|
span_id = generate_id
|
|
9
|
-
trace_id = TraceId.new(span_id, nil, span_id, should_sample
|
|
9
|
+
trace_id = TraceId.new(span_id, nil, span_id, should_sample?, Flags::EMPTY)
|
|
10
10
|
stack.push(trace_id)
|
|
11
11
|
end
|
|
12
12
|
stack.last
|
|
@@ -33,7 +33,7 @@ module Trace
|
|
|
33
33
|
saved_stack = stack.dup
|
|
34
34
|
yield
|
|
35
35
|
ensure
|
|
36
|
-
@stack =
|
|
36
|
+
@stack = saved_stack
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
end
|
|
@@ -58,23 +58,45 @@ module Trace
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
class TraceId
|
|
61
|
-
attr_reader :trace_id, :parent_id, :span_id, :sampled
|
|
62
|
-
|
|
63
|
-
def initialize(trace_id, parent_id, span_id, sampled)
|
|
61
|
+
attr_reader :trace_id, :parent_id, :span_id, :sampled, :flags
|
|
62
|
+
|
|
63
|
+
def initialize(trace_id, parent_id, span_id, sampled, flags)
|
|
64
64
|
@trace_id = SpanId.from_value(trace_id)
|
|
65
65
|
@parent_id = parent_id.nil? ? nil : SpanId.from_value(parent_id)
|
|
66
66
|
@span_id = SpanId.from_value(span_id)
|
|
67
67
|
@sampled = !!sampled
|
|
68
|
+
@flags = flags
|
|
68
69
|
end
|
|
69
70
|
|
|
70
71
|
def next_id
|
|
71
|
-
TraceId.new(@trace_id, @span_id, Trace.generate_id, @sampled)
|
|
72
|
+
TraceId.new(@trace_id, @span_id, Trace.generate_id, @sampled, @flags)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# the debug flag is used to ensure the trace passes ALL samplers
|
|
76
|
+
def debug?
|
|
77
|
+
@flags & Flags::DEBUG == Flags::DEBUG
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def sampled?
|
|
81
|
+
debug? || @sampled
|
|
72
82
|
end
|
|
73
83
|
|
|
74
84
|
def to_s
|
|
75
|
-
"TraceId(trace_id = #{@trace_id.to_s}, parent_id = #{@parent_id.to_s}, span_id = #{@span_id.to_s}, sampled = #{@sampled.to_s})"
|
|
85
|
+
"TraceId(trace_id = #{@trace_id.to_s}, parent_id = #{@parent_id.to_s}, span_id = #{@span_id.to_s}, sampled = #{@sampled.to_s}, flags = #{@flags.to_s})"
|
|
76
86
|
end
|
|
77
87
|
end
|
|
88
|
+
|
|
89
|
+
# there are a total of 64 flags that can be passed down with the various tracing headers
|
|
90
|
+
# at the time of writing only one is used (debug).
|
|
91
|
+
#
|
|
92
|
+
# Note that using the 64th bit in Ruby requires some sign conversion since Thrift i64s are signed
|
|
93
|
+
# but Ruby won't do the right thing if you try to set 1 << 64
|
|
94
|
+
class Flags
|
|
95
|
+
# no flags set
|
|
96
|
+
EMPTY = 0
|
|
97
|
+
# the debug flag is used to ensure we pass all the sampling layers and that the trace is stored
|
|
98
|
+
DEBUG = 1
|
|
99
|
+
end
|
|
78
100
|
|
|
79
101
|
class SpanId
|
|
80
102
|
HEX_REGEX = /^[a-f0-9]{16}$/i
|
|
@@ -121,12 +121,13 @@ module Trace
|
|
|
121
121
|
end
|
|
122
122
|
|
|
123
123
|
class Span
|
|
124
|
-
attr_accessor :name, :annotations, :binary_annotations
|
|
124
|
+
attr_accessor :name, :annotations, :binary_annotations, :debug
|
|
125
125
|
def initialize(name, span_id)
|
|
126
126
|
@name = name
|
|
127
127
|
@span_id = span_id
|
|
128
128
|
@annotations = []
|
|
129
129
|
@binary_annotations = []
|
|
130
|
+
@debug = span_id.debug?
|
|
130
131
|
end
|
|
131
132
|
|
|
132
133
|
def to_thrift
|
|
@@ -136,7 +137,8 @@ module Trace
|
|
|
136
137
|
:id => @span_id.span_id.to_i,
|
|
137
138
|
:parent_id => @span_id.parent_id.nil? ? nil : @span_id.parent_id.to_i,
|
|
138
139
|
:annotations => @annotations.map { |a| a.to_thrift },
|
|
139
|
-
:binary_annotations => @binary_annotations.map { |a| a.to_thrift }
|
|
140
|
+
:binary_annotations => @binary_annotations.map { |a| a.to_thrift },
|
|
141
|
+
:debug => @debug
|
|
140
142
|
)
|
|
141
143
|
end
|
|
142
144
|
end
|
|
@@ -147,7 +149,8 @@ module Trace
|
|
|
147
149
|
SERVER_SEND = "ss"
|
|
148
150
|
SERVER_RECV = "sr"
|
|
149
151
|
|
|
150
|
-
|
|
152
|
+
# write access for tests
|
|
153
|
+
attr_accessor :value, :host, :timestamp
|
|
151
154
|
def initialize(value, host)
|
|
152
155
|
@timestamp = (Time.now.to_f * 1000 * 1000).to_i # micros
|
|
153
156
|
@value = value
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
module FinagleThrift
|
|
2
|
-
VERSION = "1.
|
|
3
|
-
end
|
|
2
|
+
VERSION = "1.3.1"
|
|
3
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: finagle-thrift
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 25
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
version: 1.
|
|
8
|
+
- 3
|
|
9
|
+
- 1
|
|
10
|
+
version: 1.3.1
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Arya Asemanfar
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date:
|
|
18
|
+
date: 2013-06-13 00:00:00 Z
|
|
19
19
|
dependencies: []
|
|
20
20
|
|
|
21
21
|
description: A Ruby client library for integrating into finagle's thrift tracing protocol
|