gruf-lightstep 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7208452825f60d83446d8bf3bb3f060a499ec7e505cee6b1e0c37e39ed90a0af
4
+ data.tar.gz: e431b38fa9b30736bf07853ce14a3319fb2ad0a6f874d16b7e38f3c5167edd93
5
+ SHA512:
6
+ metadata.gz: b57836ff6f8c1cda1e8fa6fb82ec188e440ae2e8c0f84debcad6915eaf050310b8dc0b45740463945e14503360f774036f24418f954cf1c80d681b4b27003006
7
+ data.tar.gz: 65b8196733faeabfead68528d3408adda9ac3dcf1baf437637f033a9d67e7c313d61d19ac46507d1b51d4e3e897dd63b766bb34e4a72f79311863b864c1ef49e
@@ -0,0 +1,47 @@
1
+ Changelog for the gruf-zipkin gem.
2
+
3
+ h3. Pending Release
4
+
5
+ h3. 1.1.2
6
+
7
+ - First OSS release
8
+ - Explicitly require bc-lightstep-ruby dependency
9
+ - Add option to whitelist request params to lightstep as span tags
10
+
11
+ h3. 1.1.1
12
+
13
+ - Bump bc-lightstep-ruby to 1.1.5
14
+ - Bump gruf minimum version to 2.4
15
+
16
+ h3. 1.1.0
17
+
18
+ - Exclude client validation errors from being "errors"
19
+
20
+ h3. 1.0.3
21
+
22
+ - Ensure gRPC requests are always the root span
23
+
24
+ h3. 1.0.2
25
+
26
+ - Add ignore_methods as an option to server interceptor
27
+ - Standardize span tags according to BC spec
28
+
29
+ h3. 1.0.0
30
+
31
+ - Support for gruf 2.0.0
32
+
33
+ h3. 0.10.3
34
+
35
+ - Update to 0.10.3, add rubocop+bundler-audit
36
+
37
+ h3. 0.10.2
38
+
39
+ - Updated license to MIT
40
+
41
+ h3. 0.10.1
42
+
43
+ - Handle case when tracer is not yet initialized before trace executes
44
+
45
+ h3. 0.10.0
46
+
47
+ - 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/
@@ -0,0 +1,76 @@
1
+ # gruf-lightstep - LightStep tracing for gruf
2
+
3
+ [![Build Status](https://travis-ci.com/bigcommerce/gruf-lightstep.svg?branch=master)](https://travis-ci.com/bigcommerce/gruf-lightstep) [![Gem Version](https://badge.fury.io/rb/gruf-lightstep.svg)](https://badge.fury.io/rb/gruf-lightstep) [![Inline docs](http://inch-ci.org/github/bigcommerce/gruf-lightstep.svg?branch=master)](http://inch-ci.org/github/bigcommerce/gruf-lightstep)
4
+
5
+ Adds LightStep tracing support for [gruf](https://github.com/bigcommerce/gruf) 2.0.0+.
6
+
7
+ ## Installation
8
+
9
+ ```ruby
10
+ gem 'gruf-lightstep'
11
+ ```
12
+
13
+ Then in an initializer or before use, after loading gruf:
14
+
15
+ ```ruby
16
+ require 'gruf/lightstep'
17
+
18
+ Gruf::Lightstep.configure do |c|
19
+ c.component_name = 'myapp'
20
+ c.access_token = 'abcdefg'
21
+ c.host = 'my.lightstep.service.io'
22
+ c.port = 8080
23
+ c.verbosity = 1
24
+ end
25
+ Gruf::Lightstep.start
26
+ ```
27
+
28
+ Then after, in your gruf initializer:
29
+
30
+ ```ruby
31
+ Gruf.configure do |c|
32
+ c.interceptors.use(Gruf::Lightstep::ServerInterceptor)
33
+ end
34
+ ```
35
+
36
+ It comes with a few more options as well:
37
+
38
+ | Option | Description | Default |
39
+ | ------ | ----------- | ------- |
40
+ | whitelist | An array of parameter key names to log to lightstep. E.g. `[uuid kind]` | `[]` |
41
+ | ignore_methods | An array of method names to ignore from logging. E.g. `['namespace.health.check']` | `[]` |
42
+
43
+ It's important to maintain a safe whitelist should you decide to log parameters; gruf does no
44
+ parameter sanitization on its own. We also recommend do not whitelist parameters that may contain
45
+ very large values (such as binary or json data).
46
+
47
+ ### Client Interceptors
48
+
49
+ To automatically propagate the trace context outbound, in your Gruf clients, pass the client interceptor
50
+ to your `Gruf::Client` initializer:
51
+
52
+ ```ruby
53
+ Gruf::Client.new(
54
+ service: MyService,
55
+ client_options: {
56
+ interceptors: [Gruf::Lightstep::ClientInterceptor.new]
57
+ }
58
+ )
59
+ ```
60
+
61
+ ## License
62
+
63
+ Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
64
+
65
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
66
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
67
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
68
+ persons to whom the Software is furnished to do so, subject to the following conditions:
69
+
70
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
71
+ Software.
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
74
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
75
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
76
+ 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
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
7
+ #
8
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
9
+ # Software.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ #
16
+ $:.push File.expand_path("../lib", __FILE__)
17
+ require 'gruf/lightstep/version'
18
+
19
+ Gem::Specification.new do |spec|
20
+ spec.name = 'gruf-lightstep'
21
+ spec.version = Gruf::Lightstep::VERSION
22
+ spec.authors = ['Shaun McCormick']
23
+ spec.email = ['shaun.mccormick@bigcommerce.com']
24
+
25
+ spec.summary = %q{Plugin for lightstep tracing for gruf}
26
+ spec.description = spec.summary
27
+ spec.homepage = 'https://github.com/bigcommerce/gruf-lightstep'
28
+ spec.license = 'MIT'
29
+
30
+ spec.files = Dir['README.md', 'CHANGELOG.md', 'CODE_OF_CONDUCT.md', 'lib/**/*', 'gruf-lightstep.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.7'
36
+ spec.add_development_dependency 'pry'
37
+
38
+ spec.add_runtime_dependency 'bc-lightstep-ruby', '~> 1.1'
39
+ end
@@ -0,0 +1,33 @@
1
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
7
+ #
8
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
9
+ # Software.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ #
16
+ require 'bigcommerce/lightstep'
17
+ require_relative 'lightstep/version'
18
+ require_relative 'lightstep/configuration'
19
+ require_relative 'lightstep/client_interceptor'
20
+ require_relative 'lightstep/server_interceptor'
21
+ require_relative 'lightstep/headers'
22
+ require_relative 'lightstep/method'
23
+
24
+ ##
25
+ # Gruf main base module
26
+ module Gruf
27
+ ##
28
+ # Lightstep gruf module
29
+ #
30
+ module Lightstep
31
+ extend Configuration
32
+ end
33
+ end
@@ -0,0 +1,51 @@
1
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
7
+ #
8
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
9
+ # Software.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ #
16
+ module Gruf
17
+ module Lightstep
18
+ ##
19
+ # Intercepts outbound calls to provide LightStep tracing
20
+ #
21
+ class ClientInterceptor < Gruf::Interceptors::ClientInterceptor
22
+ def call(request_context:)
23
+ span = active_span
24
+ if span
25
+ span_data = span.to_h
26
+ logger.debug "[gruf-lightstep] Injecting current active span #{span_data[:span_guid]} into outbound request context for #{request_context.method_name}"
27
+ request_context.metadata['ot-tracer-spanid'] = span_data[:span_guid].to_s
28
+ request_context.metadata['ot-tracer-traceid'] = span_data[:trace_guid].to_s
29
+ request_context.metadata['ot-tracer-sampled'] = '1'
30
+ end
31
+
32
+ yield
33
+ end
34
+
35
+ private
36
+
37
+ ##
38
+ # @return [::LightStep::Span|NilClass]
39
+ #
40
+ def active_span
41
+ tracer = ::Bigcommerce::Lightstep::Tracer.instance
42
+ return unless tracer
43
+
44
+ span = tracer.active_span
45
+ return unless span && span.is_a?(::LightStep::Span)
46
+
47
+ span
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,81 @@
1
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
7
+ #
8
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
9
+ # Software.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ #
16
+
17
+ module Gruf
18
+ module Lightstep
19
+ ##
20
+ # General configuration for lightstep integration
21
+ #
22
+ module Configuration
23
+ VALID_CONFIG_KEYS = {
24
+ }.freeze
25
+
26
+ attr_accessor *VALID_CONFIG_KEYS.keys
27
+
28
+ ##
29
+ # Whenever this is extended into a class, setup the defaults
30
+ #
31
+ def self.extended(base)
32
+ base.reset
33
+ end
34
+
35
+ ##
36
+ # Yield self for ruby-style initialization
37
+ #
38
+ # @yields [Bigcommerce::Instrumentation::Configuration]
39
+ # @return [Bigcommerce::Instrumentation::Configuration]
40
+ #
41
+ def configure
42
+ reset unless @configured
43
+ yield self
44
+ @configured = true
45
+ end
46
+
47
+ ##
48
+ # Return the current configuration options as a Hash
49
+ #
50
+ # @return [Hash]
51
+ #
52
+ def options
53
+ opts = {}
54
+ VALID_CONFIG_KEYS.each_key do |k|
55
+ opts.merge!(k => send(k))
56
+ end
57
+ opts
58
+ end
59
+
60
+ ##
61
+ # Set the default configuration onto the extended class
62
+ #
63
+ def reset
64
+ VALID_CONFIG_KEYS.each do |k, v|
65
+ send("#{k}=".to_sym, v)
66
+ end
67
+ end
68
+
69
+ ##
70
+ # Automatically determine environment
71
+ #
72
+ def environment
73
+ if defined?(Rails)
74
+ Rails.env
75
+ else
76
+ ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,73 @@
1
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
7
+ #
8
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
9
+ # Software.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ #
16
+ module Gruf
17
+ module Lightstep
18
+ ##
19
+ # Abstraction accessor class for B3 propagation headers across GRPC ActiveCall objects
20
+ #
21
+ class Headers
22
+ attr_reader :active_call
23
+
24
+ ##
25
+ # @property [Hash<Symbol|Array<String>>] Hash mapping of metadata keys
26
+ #
27
+ OT_KEYS = {
28
+ parent_span_id: %w(ot-tracer-parentspanid OT-Tracer-ParentSpanId HTTP_X_OT_TRACER_PARENTSPANID),
29
+ span_id: %w(ot-tracer-spanid OT-Tracer-SpanId HTTP_X_OT_TRACER_SPANID),
30
+ trace_id: %w(ot-tracer-traceid OT-Tracer-TraceId HTTP_X_OT_TRACER_TRACEID),
31
+ sampled: %w(ot-tracer-sampled OT-Tracer-Sampled HTTP_X_OT_TRACER_SAMPLED),
32
+ flags: %w(ot-tracer-flags OT-Tracer-Flags HTTP_X_OT_TRACER_FLAGS)
33
+ }.freeze
34
+
35
+ delegate :has_key?, :key?, to: :metadata
36
+
37
+ ##
38
+ # @param [GRPC::ActiveCall] active_call
39
+ #
40
+ def initialize(active_call)
41
+ @active_call = active_call
42
+ end
43
+
44
+ ##
45
+ # Return a B3 propagation header if present
46
+ #
47
+ # @param [Symbol] key
48
+ # @return [String|NilClass]
49
+ #
50
+ def value(key)
51
+ return nil unless OT_KEYS.key?(key)
52
+ OT_KEYS[key].each do |k|
53
+ return metadata[k] if metadata.key?(k)
54
+ end
55
+ nil
56
+ end
57
+
58
+ ##
59
+ # @return [Hash]
60
+ #
61
+ def metadata
62
+ @active_call.metadata
63
+ end
64
+
65
+ ##
66
+ # @return [Hash]
67
+ #
68
+ def to_h
69
+ @active_call.metadata
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
7
+ #
8
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
9
+ # Software.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ #
16
+ module Gruf
17
+ module Lightstep
18
+ ##
19
+ # Represents a Gruf gRPC method call
20
+ #
21
+ class Method
22
+ attr_reader :active_call, :signature, :request
23
+
24
+ ##
25
+ # @param [GRPC::ActiveCall] active_call The gRPC ActiveCall object for this method
26
+ # @param [String|Symbol] signature The method signature being called
27
+ # @param [Object] request The gRPC request object being used
28
+ #
29
+ def initialize(active_call, signature, request)
30
+ @active_call = active_call
31
+ @signature = signature.to_s
32
+ @request = request
33
+ end
34
+
35
+ ##
36
+ # @return [Gruf::Zipkin::Headers]
37
+ #
38
+ def headers
39
+ @headers ||= Gruf::Lightstep::Headers.new(@active_call)
40
+ end
41
+
42
+ ##
43
+ # @return [String]
44
+ #
45
+ def request_class
46
+ @request.class.to_s
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,89 @@
1
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
7
+ #
8
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
9
+ # Software.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ #
16
+ module Gruf
17
+ module Lightstep
18
+ ##
19
+ # Intercepts inbound calls to provide LightStep tracing
20
+ #
21
+ class ServerInterceptor < Gruf::Interceptors::ServerInterceptor
22
+ ##
23
+ # Handle the gruf around hook and trace sampled requests
24
+ #
25
+ def call(&_block)
26
+ return yield if options.fetch(:ignore_methods, []).include?(request.method_name)
27
+
28
+ result = nil
29
+
30
+ whitelist = options.fetch(:whitelist, []).map(&:to_s).map(&:to_sym)
31
+ params = request_message_params
32
+
33
+ tracer = ::Bigcommerce::Lightstep::Tracer.instance
34
+ tracer.clear_active_span! # because we're always starting from the top on a gRPC boundary
35
+ tracer.start_span(request.method_name, context: request_method.headers.to_h) do |span|
36
+ span.set_tag('grpc.method', request.method_key)
37
+ span.set_tag('grpc.request_class', request.request_class)
38
+ span.set_tag('grpc.service', request.service_key)
39
+
40
+ whitelist.each do |param|
41
+ span.set_tag(param.to_s, params[param]) if params.key?(param)
42
+ end
43
+
44
+ begin
45
+ result = yield
46
+ rescue StandardError => e
47
+ span.set_tag('error', true) if error?(e)
48
+ span.set_tag('grpc.error', true)
49
+ span.set_tag('grpc.error_code', e.code)
50
+ span.set_tag('grpc.error_class', e.class)
51
+ raise # passthrough, we just want the annotations
52
+ end
53
+ end
54
+ result
55
+ end
56
+
57
+ private
58
+
59
+ ##
60
+ # @return [Gruf::Lightstep::Method]
61
+ #
62
+ def request_method
63
+ Gruf::Lightstep::Method.new(request.active_call, request.method_key, request.message)
64
+ end
65
+
66
+ ##
67
+ # @return [Hash]
68
+ #
69
+ def request_message_params
70
+ return {} if request.client_streamer? || !request.message.respond_to?(:to_h)
71
+ request.message.to_h
72
+ end
73
+
74
+ ##
75
+ # @return [Boolean]
76
+ #
77
+ def error?(exception)
78
+ error_classes.include?(exception.class.to_s)
79
+ end
80
+
81
+ ##
82
+ # @return [Array]
83
+ #
84
+ def error_classes
85
+ options.fetch(:error_classes, %w(GRPC::Unknown GRPC::Internal GRPC::DataLoss GRPC::FailedPrecondition GRPC::Unavailable GRPC::DeadlineExceeded GRPC::Cancelled))
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,20 @@
1
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
7
+ #
8
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
9
+ # Software.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ #
16
+ module Gruf
17
+ module Lightstep
18
+ VERSION = '1.1.2'.freeze
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gruf-lightstep
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Shaun McCormick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-06 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.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.7'
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: bc-lightstep-ruby
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ description: Plugin for lightstep 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-lightstep.gemspec
94
+ - lib/gruf/lightstep.rb
95
+ - lib/gruf/lightstep/client_interceptor.rb
96
+ - lib/gruf/lightstep/configuration.rb
97
+ - lib/gruf/lightstep/headers.rb
98
+ - lib/gruf/lightstep/method.rb
99
+ - lib/gruf/lightstep/server_interceptor.rb
100
+ - lib/gruf/lightstep/version.rb
101
+ homepage: https://github.com/bigcommerce/gruf-lightstep
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.7.7
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Plugin for lightstep tracing for gruf
125
+ test_files: []