zipkin-tracer 0.19.1 → 0.20.0
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 +4 -4
- data/lib/zipkin-tracer.rb +2 -0
- data/lib/zipkin-tracer/config.rb +1 -0
- data/lib/zipkin-tracer/faraday/zipkin-tracer.rb +2 -2
- data/lib/zipkin-tracer/rack/zipkin-tracer.rb +1 -14
- data/lib/zipkin-tracer/trace.rb +4 -6
- data/lib/zipkin-tracer/trace_client.rb +5 -5
- data/lib/zipkin-tracer/trace_container.rb +34 -0
- data/lib/zipkin-tracer/trace_generator.rb +31 -0
- data/lib/zipkin-tracer/version.rb +1 -14
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2115e2652361d00e2c3d148675b02f876dc40fab
|
4
|
+
data.tar.gz: a5994a1577f75b9540f0bf304cb11a8f7767d687
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68e707aee3cc6caf499c0421ffbae6fcd24a53342d764cddbfa7e588dab91c6e637d0000ab5c4272b2969e5d511fcc042fcadaa409032e08f04a3084b5d0734b
|
7
|
+
data.tar.gz: 7c6fcbd64fc30ea50a1381e19925c16f9e4da588086ef2950240a132e5e66824dbbc06c4fe43161d4dad06e599e8daa22da3d18ebcfbf2d09bf189f6205c0b41
|
data/lib/zipkin-tracer.rb
CHANGED
@@ -2,6 +2,8 @@ require 'base64' #Bug in finagle. They should be requiring this: finagle-thrift-
|
|
2
2
|
require 'zipkin-tracer/trace'
|
3
3
|
require 'zipkin-tracer/rack/zipkin-tracer'
|
4
4
|
require 'zipkin-tracer/trace_client'
|
5
|
+
require 'zipkin-tracer/trace_container'
|
6
|
+
require 'zipkin-tracer/trace_generator'
|
5
7
|
|
6
8
|
begin
|
7
9
|
require 'faraday'
|
data/lib/zipkin-tracer/config.rb
CHANGED
@@ -12,8 +12,8 @@ module ZipkinTracer
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def call(env)
|
15
|
-
trace_id =
|
16
|
-
|
15
|
+
trace_id = TraceGenerator.new.next_trace_id
|
16
|
+
TraceContainer.with_trace_id(trace_id) do
|
17
17
|
b3_headers.each do |method, header|
|
18
18
|
env[:request_headers][header] = trace_id.send(method).to_s
|
19
19
|
end
|
@@ -1,16 +1,3 @@
|
|
1
|
-
# Copyright 2012 Twitter Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
1
|
require 'finagle-thrift/trace'
|
15
2
|
require 'finagle-thrift/tracer'
|
16
3
|
require 'zipkin-tracer/config'
|
@@ -30,7 +17,7 @@ module ZipkinTracer
|
|
30
17
|
def call(env)
|
31
18
|
zipkin_env = ZipkinEnv.new(env, @config)
|
32
19
|
trace_id = zipkin_env.trace_id
|
33
|
-
|
20
|
+
TraceContainer.with_trace_id(trace_id) do
|
34
21
|
if !trace_id.sampled? || !routable_request?(env)
|
35
22
|
@app.call(env)
|
36
23
|
else
|
data/lib/zipkin-tracer/trace.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'finagle-thrift/trace'
|
2
2
|
require 'zipkin-tracer/zipkin_tracer_base'
|
3
|
-
|
3
|
+
# Module with a mix of functions and overwrites from the finagle implementation:
|
4
|
+
# https://github.com/twitter/finagle/blob/finagle-6.39.0/finagle-thrift/src/main/ruby/lib/finagle-thrift/trace.rb
|
4
5
|
module Trace
|
5
6
|
|
6
7
|
# We need this to access the tracer from the Faraday middleware.
|
@@ -8,11 +9,8 @@ module Trace
|
|
8
9
|
@tracer
|
9
10
|
end
|
10
11
|
|
11
|
-
def
|
12
|
-
|
13
|
-
yield
|
14
|
-
ensure
|
15
|
-
self.pop
|
12
|
+
def sample_rate
|
13
|
+
@sample_rate
|
16
14
|
end
|
17
15
|
|
18
16
|
# A TraceId contains all the information of a given trace id
|
@@ -4,19 +4,19 @@ module ZipkinTracer
|
|
4
4
|
end
|
5
5
|
end
|
6
6
|
|
7
|
+
# The trace client provides the user of this library an API to interact
|
8
|
+
# with tracing information.
|
7
9
|
class TraceClient
|
8
10
|
def self.local_component_span(local_component_value, &block)
|
9
|
-
|
10
|
-
client.trace(local_component_value, &block)
|
11
|
+
new.trace(local_component_value, &block)
|
11
12
|
end
|
12
13
|
|
13
14
|
def trace(local_component_value, &block)
|
14
15
|
raise ArgumentError, "no block given" unless block
|
15
|
-
|
16
|
-
@trace_id = Trace.id.next_id
|
16
|
+
@trace_id = TraceGenerator.new.next_trace_id
|
17
17
|
result = nil
|
18
18
|
if @trace_id.sampled?
|
19
|
-
|
19
|
+
TraceContainer.with_trace_id(@trace_id) do
|
20
20
|
Trace.tracer.with_new_span(@trace_id, local_component_value) do |span|
|
21
21
|
result = block.call(span)
|
22
22
|
span.record_local_component local_component_value
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ZipkinTracer
|
2
|
+
# This class manages a thread-unique container with the stack of traceIds
|
3
|
+
# This stack may grow if for instance the current process creates local components inside local components
|
4
|
+
class TraceContainer
|
5
|
+
class << self
|
6
|
+
def with_trace_id(trace_id, &_block)
|
7
|
+
container.push(trace_id)
|
8
|
+
yield
|
9
|
+
ensure
|
10
|
+
container.pop
|
11
|
+
end
|
12
|
+
|
13
|
+
def current
|
14
|
+
container.last
|
15
|
+
end
|
16
|
+
|
17
|
+
def tracing_information_set?
|
18
|
+
!container.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
# DO NOT USE unless you ABSOLUTELY know what you are doing.
|
22
|
+
def cleanup!
|
23
|
+
Thread.current[TRACE_STACK] = []
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def container
|
29
|
+
Thread.current[TRACE_STACK] ||= []
|
30
|
+
end
|
31
|
+
TRACE_STACK = :trace_stack
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ZipkinTracer
|
2
|
+
# This class generates trace ids.
|
3
|
+
class TraceGenerator
|
4
|
+
# Next id, based on the current information in the container
|
5
|
+
def next_trace_id
|
6
|
+
if TraceContainer.tracing_information_set?
|
7
|
+
TraceContainer.current.next_id
|
8
|
+
else
|
9
|
+
generate_trace_id
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_trace_id
|
14
|
+
span_id = generate_id
|
15
|
+
Trace::TraceId.new(span_id, nil, span_id, should_sample?.to_s, Trace::Flags::EMPTY)
|
16
|
+
end
|
17
|
+
|
18
|
+
def should_sample?
|
19
|
+
rand < (Trace.sample_rate || DEFAULT_SAMPLE_RATE)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def generate_id
|
25
|
+
rand(TRACE_ID_UPPER_BOUND)
|
26
|
+
end
|
27
|
+
|
28
|
+
TRACE_ID_UPPER_BOUND = 2**64
|
29
|
+
DEFAULT_SAMPLE_RATE = 0.001
|
30
|
+
end
|
31
|
+
end
|
@@ -1,16 +1,3 @@
|
|
1
|
-
# Copyright 2012 Twitter Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
1
|
module ZipkinTracer
|
15
|
-
VERSION = '0.
|
2
|
+
VERSION = '0.20.0'.freeze
|
16
3
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zipkin-tracer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franklin Hu
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2016-
|
16
|
+
date: 2016-12-19 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: faraday
|
@@ -162,6 +162,8 @@ files:
|
|
162
162
|
- lib/zipkin-tracer/rack/zipkin_env.rb
|
163
163
|
- lib/zipkin-tracer/trace.rb
|
164
164
|
- lib/zipkin-tracer/trace_client.rb
|
165
|
+
- lib/zipkin-tracer/trace_container.rb
|
166
|
+
- lib/zipkin-tracer/trace_generator.rb
|
165
167
|
- lib/zipkin-tracer/tracer_factory.rb
|
166
168
|
- lib/zipkin-tracer/version.rb
|
167
169
|
- lib/zipkin-tracer/zipkin_json_tracer.rb
|
@@ -170,7 +172,8 @@ files:
|
|
170
172
|
- lib/zipkin-tracer/zipkin_null_tracer.rb
|
171
173
|
- lib/zipkin-tracer/zipkin_tracer_base.rb
|
172
174
|
homepage: https://github.com/openzipkin/zipkin-tracer
|
173
|
-
licenses:
|
175
|
+
licenses:
|
176
|
+
- Apache
|
174
177
|
metadata: {}
|
175
178
|
post_install_message:
|
176
179
|
rdoc_options: []
|