gruf-zipkin 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 689a4f4eb5b71ae46c6c5ccc40859e3ab8de4d2e
4
+ data.tar.gz: 0ea5e97b910428e0aa01200b5eae9358a473822f
5
+ SHA512:
6
+ metadata.gz: 085309d83c7684b359b95d3975671170be17faab92106bae9f35924e8986d2ee0b11a5adde3b872dfb53c09f9c5d449e54c843d16f264a5b48ddd53396a6b35d
7
+ data.tar.gz: 4a6613b0b14e97ccb83f44ce119b7526701bb127723fd1012784499f0a5c3d9c6555ec81c1a0de305ecc180399ad6f994923c4b47e5e86f9cdca83a7f64da58c
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ Changelog for the gruf-zipkin gem.
2
+
3
+ h3. 0.10.3
4
+
5
+ - Update to 0.10.3, add rubocop+bundler-audit
6
+
7
+ h3. 0.10.2
8
+
9
+ - Updated license to MIT
10
+
11
+ h3. 0.10.1
12
+
13
+ - Handle case when tracer is not yet initialized before trace executes
14
+
15
+ h3. 0.10.0
16
+
17
+ - Initial public release
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at splittingred@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # gruf-zipkin - Zipkin tracing for gruf
2
+
3
+ [![Build Status](https://travis-ci.org/bigcommerce/gruf-zipkin.svg?branch=master)](https://travis-ci.org/bigcommerce/gruf-zipkin)
4
+
5
+ Adds Zipkin tracing support for [gruf](https://github.com/bigcommerce/gruf) 1.0.0 or later.
6
+
7
+ ## Installation
8
+
9
+ ```ruby
10
+ gem 'gruf-zipkin'
11
+ ```
12
+
13
+ Then in an initializer or before use, after loading gruf:
14
+
15
+ ```ruby
16
+ require 'zipkin-tracer'
17
+ require 'gruf/zipkin'
18
+
19
+ # Set it in the Rails config, or alternatively make this just a hash if not using Rails
20
+ Rails.application.config.zipkin_tracer = {
21
+ service_name: 'my-service',
22
+ service_port: 1234,
23
+ json_api_host: 'zipkin.mydomain.com',
24
+ sampled_as_boolean: false,
25
+ sample_rate: 0.1 # 0.0 to 1.0, where 1.0 => 100% of requests
26
+ }
27
+ Gruf.configure do |c|
28
+ c.hook_options[:zipkin] = Rails.application.config.zipkin_tracer
29
+ end
30
+ Gruf::Hooks::Registry.add(:zipkin, Gruf::Zipkin::Hook)
31
+ ```
32
+
33
+ This assumes you have Zipkin already setup in your Ruby/Rails app via the installation
34
+ instructions in the [zipkin-tracer](https://github.com/openzipkin/zipkin-ruby) gem.
35
+
36
+ ### Rails/Rack Tracing
37
+
38
+ Add this to config.ru, if using above configuration:
39
+
40
+ ```ruby
41
+ use ZipkinTracer::RackHandler, Rails.application.config.zipkin_tracer
42
+ ```
43
+
44
+ ## Configuration
45
+
46
+ You can further customize the tracing of gruf services via the configuration:
47
+
48
+ ```ruby
49
+ Gruf.configure do |c|
50
+ c.hook_options[:zipkin] = {
51
+ span_prefix: 'myapp'
52
+ }
53
+ end
54
+ ```
55
+
56
+ ## License
57
+
58
+ Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
59
+
60
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
61
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
62
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
63
+ persons to whom the Software is furnished to do so, subject to the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
66
+ Software.
67
+
68
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
69
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
70
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
71
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ $:.push File.expand_path("../lib", __FILE__)
18
+ require 'gruf/zipkin/version'
19
+
20
+ Gem::Specification.new do |spec|
21
+ spec.name = 'gruf-zipkin'
22
+ spec.version = Gruf::Zipkin::VERSION
23
+ spec.authors = ['Shaun McCormick']
24
+ spec.email = ['shaun.mccormick@bigcommerce.com']
25
+
26
+ spec.summary = %q{Plugin for zipkin tracing for gruf}
27
+ spec.description = spec.summary
28
+ spec.homepage = 'https://github.com/bigcommerce/gruf-zipkin'
29
+
30
+ spec.files = Dir['README.md', 'CHANGELOG.md', 'CODE_OF_CONDUCT.md', 'lib/**/*', 'gruf-zipkin.gemspec']
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_development_dependency 'bundler', '~> 1.11'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.0'
36
+ spec.add_development_dependency 'pry'
37
+
38
+ spec.add_runtime_dependency 'zipkin-tracer', '~> 0.22.0'
39
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ require 'zipkin-tracer'
18
+ require_relative 'zipkin/version'
19
+ require_relative 'zipkin/headers'
20
+ require_relative 'zipkin/method'
21
+ require_relative 'zipkin/trace'
22
+ require_relative 'zipkin/hook'
23
+
24
+ module Gruf
25
+ module Zipkin
26
+ end
27
+ end
@@ -0,0 +1,58 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ module Gruf
18
+ module Zipkin
19
+ ##
20
+ # Abstraction accessor class for B3 propagation headers across GRPC ActiveCall objects
21
+ #
22
+ class Headers
23
+ attr_reader :active_call
24
+
25
+ ##
26
+ # @property [Hash<Symbol|Array<String>>] Hash mapping of metadata keys
27
+ #
28
+ ZIPKIN_KEYS = {
29
+ parent_span_id: %w(x-b3-parentspanid X-B3-ParentSpanId HTTP_X_B3_PARENTSPANID),
30
+ span_id: %w(x-b3-spanid X-B3-SpanId HTTP_X_B3_SPANID),
31
+ trace_id: %w(x-b3-traceid X-B3-TraceId HTTP_X_B3_TRACEID),
32
+ sampled: %w(x-b3-sampled X-B3-Sampled HTTP_X_B3_SAMPLED),
33
+ flags: %w(x-b3-flags X-B3-Flags HTTP_X_B3_FLAGS)
34
+ }.freeze
35
+
36
+ ##
37
+ # @param [GRPC::ActiveCall] active_call
38
+ #
39
+ def initialize(active_call)
40
+ @active_call = active_call
41
+ end
42
+
43
+ ##
44
+ # Return a B3 propagation header if present
45
+ #
46
+ # @param [Symbol] key
47
+ # @return [String|NilClass]
48
+ #
49
+ def value(key)
50
+ return nil unless ZIPKIN_KEYS.key?(key)
51
+ ZIPKIN_KEYS[key].each do |k|
52
+ return @active_call.metadata[k] if @active_call.metadata.key?(k)
53
+ end
54
+ nil
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,78 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ module Gruf
18
+ module Zipkin
19
+ class Hook < Gruf::Hooks::Base
20
+
21
+ ##
22
+ # Sets up the tracing hook
23
+ #
24
+ def setup
25
+ @config = ::ZipkinTracer::Config.new(nil, options).freeze
26
+ @tracer = ::ZipkinTracer::TracerFactory.new.tracer(@config)
27
+ end
28
+
29
+ ##
30
+ # Handle the gruf around hook and trace sampled requests
31
+ #
32
+ # @param [Symbol] call_signature
33
+ # @param [Object] request
34
+ # @param [GRPC::ActiveCall] active_call
35
+ #
36
+ def around(call_signature, request, active_call, &block)
37
+ trace = build_trace(call_signature, request, active_call)
38
+
39
+ if trace.sampled?
40
+ result = nil
41
+ ::ZipkinTracer::TraceContainer.with_trace_id(trace.trace_id) do
42
+ result = trace.trace!(@tracer, &block)
43
+ end
44
+ else
45
+ result = yield
46
+ end
47
+ result
48
+ end
49
+
50
+ ##
51
+ # @return [String]
52
+ #
53
+ def service_key
54
+ service.class.name.underscore.tr('/', '.')
55
+ end
56
+
57
+ ##
58
+ # @return [Hash]
59
+ #
60
+ def options
61
+ @options.fetch(:zipkin, {})
62
+ end
63
+
64
+ private
65
+
66
+ ##
67
+ # @param [Symbol] call_signature
68
+ # @param [Object] request
69
+ # @param [GRPC::ActiveCall] active_call
70
+ # @return [Gruf::Zipkin::Trace]
71
+ #
72
+ def build_trace(call_signature, request, active_call)
73
+ method = Gruf::Zipkin::Method.new(active_call, call_signature, request)
74
+ Gruf::Zipkin::Trace.new(method, service_key, options)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,51 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ module Gruf
18
+ module Zipkin
19
+ ##
20
+ # Represents a Gruf gRPC method call
21
+ #
22
+ class Method
23
+ attr_reader :active_call, :signature, :request
24
+
25
+ ##
26
+ # @param [GRPC::ActiveCall] active_call The gRPC ActiveCall object for this method
27
+ # @param [String|Symbol] signature The method signature being called
28
+ # @param [Object] request The gRPC request object being used
29
+ #
30
+ def initialize(active_call, signature, request)
31
+ @active_call = active_call
32
+ @signature = signature.to_s.gsub('_without_intercept', '')
33
+ @request = request
34
+ end
35
+
36
+ ##
37
+ # @return [Gruf::Zipkin::Headers]
38
+ #
39
+ def headers
40
+ @headers ||= Gruf::Zipkin::Headers.new(@active_call)
41
+ end
42
+
43
+ ##
44
+ # @return [String]
45
+ #
46
+ def request_class
47
+ @request.class.to_s
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,157 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ module Gruf
18
+ module Zipkin
19
+ ##
20
+ # Represents a trace through Gruf and gRPC
21
+ #
22
+ class Trace
23
+ attr_reader :method, :service_key
24
+
25
+ METADATA_KEYS = {
26
+ error: 'error',
27
+ grpc: {
28
+ method: 'grpc.method',
29
+ request_class: 'grpc.request_class',
30
+ error: 'grpc.error',
31
+ error_code: 'grpc.error_code',
32
+ error_class: 'grpc.error_class',
33
+ success: 'grpc.success'
34
+ }
35
+ }.freeze
36
+
37
+ ##
38
+ # @param [Gruf::Zipkin::Method] method
39
+ # @param [String|Symbol] service_key
40
+ # @param [Hash] options
41
+ #
42
+ def initialize(method, service_key, options = {})
43
+ @method = method
44
+ @service_key = service_key.to_s
45
+ @options = options
46
+ end
47
+
48
+ ##
49
+ # Trace the request
50
+ #
51
+ # @param [::Trace::Tracer] The tracing service to use
52
+ # @return [Object]
53
+ #
54
+ def trace!(tracer, &block)
55
+ raise ArgumentError, 'no block given' unless block_given?
56
+ # If for some reason we don't have a tracer, let's just proceed as normal
57
+ # and not cause the request to fail
58
+ unless tracer
59
+ Gruf.logger.warn "Failed to log trace for #{method.request_class}.#{method.signature.classify} because Tracer was not found!" if Gruf.logger
60
+ return block.call(method.request, method.active_call)
61
+ end
62
+
63
+ result = nil
64
+
65
+ tracer.with_new_span(trace_id, component) do |span|
66
+ span.record(::Trace::Annotation::SERVER_RECV)
67
+ span.record_local_component(component)
68
+ span.record_tag(METADATA_KEYS[:grpc][:method], method.signature.classify)
69
+ span.record_tag(METADATA_KEYS[:grpc][:request_class], method.request_class)
70
+
71
+ begin
72
+ result = block.call(method.request, method.active_call)
73
+ span.record(::Trace::Annotation::SERVER_SEND)
74
+ rescue => e
75
+ if e.is_a?(::GRPC::BadStatus)
76
+ span.record_tag(METADATA_KEYS[:error], true)
77
+ span.record_tag(METADATA_KEYS[:grpc][:error], true)
78
+ span.record_tag(METADATA_KEYS[:grpc][:error_code], e.code.to_s)
79
+ span.record_tag(METADATA_KEYS[:grpc][:error_class], e.class.to_s)
80
+ end
81
+ span.record(::Trace::Annotation::SERVER_SEND)
82
+ tracer.end_span(span) # manually end here as the raise prevents this
83
+ raise # passthrough, we just want the annotations
84
+ end
85
+ end
86
+ result
87
+ end
88
+
89
+ ##
90
+ # Memoize build of a new trace_id based on propagation headers, or generator if
91
+ # no headers are present
92
+ #
93
+ # @return [::Trace::TraceId]
94
+ #
95
+ def trace_id
96
+ unless @trace_id
97
+ tid = header_value(:trace_id)
98
+ span_id = header_value(:span_id)
99
+ # both trace ID and span ID are required for propagation
100
+ if !tid.to_s.empty? && !span_id.to_s.empty?
101
+ # we have a propagated trace, let's carry over the information
102
+ parent_id = header_value(:parent_span_id)
103
+ sampled = header_value(:sampled)
104
+ flags = header_value(:flags)
105
+ @trace_id = ::Trace::TraceId.new(tid, parent_id, span_id, sampled, flags)
106
+ else
107
+ # if trace_id/span_id are not present, generate a new trace
108
+ @trace_id = ::ZipkinTracer::TraceGenerator.new.next_trace_id
109
+ end
110
+ end
111
+ @trace_id
112
+ end
113
+
114
+ ##
115
+ # Delegator to headers object to get value of a B3 header
116
+ #
117
+ # @param [Symbol] key
118
+ # @return [String|NilClass]
119
+ #
120
+ def header_value(key)
121
+ @method.headers.value(key)
122
+ end
123
+
124
+ ##
125
+ # Returning whether or not this trace is sampled, which is based on either:the sample
126
+ # 1) The X-B3-Sampled header, if present
127
+ # 2) The sample rate set in the zipkin configuration
128
+ # ...in that order.
129
+ #
130
+ # @return [Boolean]
131
+ #
132
+ def sampled?
133
+ sampled = header_value(:sampled)
134
+ if sampled && sampled.to_s != ''
135
+ [1, '1', 'true', true].include?(sampled)
136
+ else
137
+ trace_id.sampled?
138
+ end
139
+ end
140
+
141
+ ##
142
+ # @return [String]
143
+ #
144
+ def component
145
+ "#{span_prefix}#{@service_key}.#{@method.signature}"
146
+ end
147
+
148
+ ##
149
+ # @return [String]
150
+ #
151
+ def span_prefix
152
+ prefix = @options.fetch(:span_prefix, '').to_s
153
+ prefix.empty? ? '' : "#{prefix}."
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ module Gruf
18
+ module Zipkin
19
+ VERSION = '0.10.3'.freeze
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gruf-zipkin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.3
5
+ platform: ruby
6
+ authors:
7
+ - Shaun McCormick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: zipkin-tracer
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.22.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.22.0
83
+ description: Plugin for zipkin tracing for gruf
84
+ email:
85
+ - shaun.mccormick@bigcommerce.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - CHANGELOG.md
91
+ - CODE_OF_CONDUCT.md
92
+ - README.md
93
+ - gruf-zipkin.gemspec
94
+ - lib/gruf/zipkin.rb
95
+ - lib/gruf/zipkin/headers.rb
96
+ - lib/gruf/zipkin/hook.rb
97
+ - lib/gruf/zipkin/method.rb
98
+ - lib/gruf/zipkin/trace.rb
99
+ - lib/gruf/zipkin/version.rb
100
+ homepage: https://github.com/bigcommerce/gruf-zipkin
101
+ licenses: []
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.6.12
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Plugin for zipkin tracing for gruf
123
+ test_files: []