finagle-thrift 1.3.1 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,4 +15,8 @@ require 'tracing_types'
15
15
 
16
16
  SERVER_RECV = %q"sr"
17
17
 
18
+ SERVER_ADDR = %q"sa"
19
+
20
+ CLIENT_ADDR = %q"ca"
21
+
18
22
  end
@@ -131,6 +131,44 @@ module FinagleThrift
131
131
  ::Thrift::Struct.generate_accessors self
132
132
  end
133
133
 
134
+ # This struct serializes com.twitter.finagle.Context
135
+ class RequestContext
136
+ include ::Thrift::Struct, ::Thrift::Struct_Union
137
+ KEY = 1
138
+ VALUE = 2
139
+
140
+ FIELDS = {
141
+ KEY => {:type => ::Thrift::Types::STRING, :name => 'key', :binary => true},
142
+ VALUE => {:type => ::Thrift::Types::STRING, :name => 'value', :binary => true}
143
+ }
144
+
145
+ def struct_fields; FIELDS; end
146
+
147
+ def validate
148
+ end
149
+
150
+ ::Thrift::Struct.generate_accessors self
151
+ end
152
+
153
+ # Serializes an individual delegation.
154
+ class Delegation
155
+ include ::Thrift::Struct, ::Thrift::Struct_Union
156
+ SRC = 1
157
+ DST = 2
158
+
159
+ FIELDS = {
160
+ SRC => {:type => ::Thrift::Types::STRING, :name => 'src'},
161
+ DST => {:type => ::Thrift::Types::STRING, :name => 'dst'}
162
+ }
163
+
164
+ def struct_fields; FIELDS; end
165
+
166
+ def validate
167
+ end
168
+
169
+ ::Thrift::Struct.generate_accessors self
170
+ end
171
+
134
172
  # RequestHeader defines headers for the request. These carry the span data, and
135
173
  # a flag indicating whether the request is to be debugged.
136
174
  class RequestHeader
@@ -141,6 +179,9 @@ module FinagleThrift
141
179
  SAMPLED = 5
142
180
  CLIENT_ID = 6
143
181
  FLAGS = 7
182
+ CONTEXTS = 8
183
+ DEST = 9
184
+ DELEGATIONS = 10
144
185
 
145
186
  FIELDS = {
146
187
  TRACE_ID => {:type => ::Thrift::Types::I64, :name => 'trace_id'},
@@ -148,7 +189,10 @@ module FinagleThrift
148
189
  PARENT_SPAN_ID => {:type => ::Thrift::Types::I64, :name => 'parent_span_id', :optional => true},
149
190
  SAMPLED => {:type => ::Thrift::Types::BOOL, :name => 'sampled', :optional => true},
150
191
  CLIENT_ID => {:type => ::Thrift::Types::STRUCT, :name => 'client_id', :class => FinagleThrift::ClientId, :optional => true},
151
- FLAGS => {:type => ::Thrift::Types::I64, :name => 'flags', :optional => true}
192
+ FLAGS => {:type => ::Thrift::Types::I64, :name => 'flags', :optional => true},
193
+ CONTEXTS => {:type => ::Thrift::Types::LIST, :name => 'contexts', :element => {:type => ::Thrift::Types::STRUCT, :class => FinagleThrift::RequestContext}},
194
+ DEST => {:type => ::Thrift::Types::STRING, :name => 'dest', :optional => true},
195
+ DELEGATIONS => {:type => ::Thrift::Types::LIST, :name => 'delegations', :element => {:type => ::Thrift::Types::STRUCT, :class => FinagleThrift::Delegation}, :optional => true}
152
196
  }
153
197
 
154
198
  def struct_fields; FIELDS; end
@@ -165,9 +209,11 @@ module FinagleThrift
165
209
  class ResponseHeader
166
210
  include ::Thrift::Struct, ::Thrift::Struct_Union
167
211
  SPANS = 1
212
+ CONTEXTS = 2
168
213
 
169
214
  FIELDS = {
170
- SPANS => {:type => ::Thrift::Types::LIST, :name => 'spans', :element => {:type => ::Thrift::Types::STRUCT, :class => FinagleThrift::Span}}
215
+ SPANS => {:type => ::Thrift::Types::LIST, :name => 'spans', :element => {:type => ::Thrift::Types::STRUCT, :class => FinagleThrift::Span}},
216
+ CONTEXTS => {:type => ::Thrift::Types::LIST, :name => 'contexts', :element => {:type => ::Thrift::Types::STRUCT, :class => FinagleThrift::RequestContext}}
171
217
  }
172
218
 
173
219
  def struct_fields; FIELDS; end
@@ -2,6 +2,7 @@ module Trace
2
2
  extend self
3
3
  DEFAULT_SAMPLE_RATE = 0.001
4
4
  TRACE_ID_UPPER_BOUND = 2 ** 64
5
+ TRACE_STACK = :trace_stack
5
6
 
6
7
  def id
7
8
  if stack.empty?
@@ -33,7 +34,7 @@ module Trace
33
34
  saved_stack = stack.dup
34
35
  yield
35
36
  ensure
36
- @stack = saved_stack
37
+ stack = saved_stack
37
38
  end
38
39
  end
39
40
  end
@@ -85,11 +86,11 @@ module Trace
85
86
  "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})"
86
87
  end
87
88
  end
88
-
89
+
89
90
  # there are a total of 64 flags that can be passed down with the various tracing headers
90
91
  # at the time of writing only one is used (debug).
91
92
  #
92
- # Note that using the 64th bit in Ruby requires some sign conversion since Thrift i64s are signed
93
+ # Note that using the 64th bit in Ruby requires some sign conversion since Thrift i64s are signed
93
94
  # but Ruby won't do the right thing if you try to set 1 << 64
94
95
  class Flags
95
96
  # no flags set
@@ -146,8 +147,14 @@ module Trace
146
147
 
147
148
  private
148
149
 
150
+ # "stack" acts as a thread local variable and cannot be shared between
151
+ # threads.
152
+ def stack=(stack)
153
+ Thread.current[TRACE_STACK] = stack
154
+ end
155
+
149
156
  def stack
150
- @stack ||= []
157
+ Thread.current[TRACE_STACK] ||= []
151
158
  end
152
159
 
153
160
  def tracer
@@ -181,8 +181,14 @@ module Trace
181
181
  DOUBLE = "DOUBLE"
182
182
  STRING = "STRING"
183
183
 
184
- def self.to_thrift(v)
185
- FinagleThrift::AnnotationType::VALUE_MAP.index(v)
184
+ if {}.respond_to?(:key)
185
+ def self.to_thrift(v)
186
+ FinagleThrift::AnnotationType::VALUE_MAP.key(v)
187
+ end
188
+ else
189
+ def self.to_thrift(v)
190
+ FinagleThrift::AnnotationType::VALUE_MAP.index(v)
191
+ end
186
192
  end
187
193
  end
188
194
 
@@ -245,4 +251,4 @@ module Trace
245
251
  end
246
252
  end
247
253
 
248
- end
254
+ end
@@ -1,3 +1,4 @@
1
1
  module FinagleThrift
2
- VERSION = "1.3.1"
2
+ VERSION = "1.4.1"
3
3
  end
4
+
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: 25
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 3
8
+ - 4
9
9
  - 1
10
- version: 1.3.1
10
+ version: 1.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Arya Asemanfar
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-06-13 00:00:00 Z
18
+ date: 2015-06-19 00:00:00 -07:00
19
+ default_executable:
19
20
  dependencies: []
20
21
 
21
22
  description: A Ruby client library for integrating into finagle's thrift tracing protocol
@@ -36,9 +37,10 @@ files:
36
37
  - lib/finagle-thrift/tracer.rb
37
38
  - lib/finagle-thrift/version.rb
38
39
  - lib/finagle-thrift.rb
40
+ has_rdoc: true
39
41
  homepage:
40
- licenses: []
41
-
42
+ licenses:
43
+ - Apache License Version 2.0
42
44
  post_install_message:
43
45
  rdoc_options: []
44
46
 
@@ -67,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
69
  requirements: []
68
70
 
69
71
  rubyforge_project:
70
- rubygems_version: 1.8.15
72
+ rubygems_version: 1.6.2
71
73
  signing_key:
72
74
  specification_version: 3
73
75
  summary: ""