gruf-zipkin 0.10.3 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 689a4f4eb5b71ae46c6c5ccc40859e3ab8de4d2e
4
- data.tar.gz: 0ea5e97b910428e0aa01200b5eae9358a473822f
3
+ metadata.gz: 081c50dadfb6eba85262365f7b2f073fa541ad3f
4
+ data.tar.gz: 57d74e314465b774ffff74b74af04b607c567f1d
5
5
  SHA512:
6
- metadata.gz: 085309d83c7684b359b95d3975671170be17faab92106bae9f35924e8986d2ee0b11a5adde3b872dfb53c09f9c5d449e54c843d16f264a5b48ddd53396a6b35d
7
- data.tar.gz: 4a6613b0b14e97ccb83f44ce119b7526701bb127723fd1012784499f0a5c3d9c6555ec81c1a0de305ecc180399ad6f994923c4b47e5e86f9cdca83a7f64da58c
6
+ metadata.gz: 64d5c4cece14c36b01fabefca98808d498edba216116dafe197761e4ad32de90befd4bfed5f5e68dd04435f1c391c9be2493399eb5e02c754464ff76dae0129b
7
+ data.tar.gz: c2e5b669752cc72c7b010b360af15999dc6d60b151e61a8e584b065e9296b6df8701f4403601c4a761d30c3ead23d85bdb2f9c16c71b6d3a68f4a5d614e98f6c
@@ -1,5 +1,9 @@
1
1
  Changelog for the gruf-zipkin gem.
2
2
 
3
+ h3. 1.0.0
4
+
5
+ - Support for gruf 2.0.0
6
+
3
7
  h3. 0.10.3
4
8
 
5
9
  - Update to 0.10.3, add rubocop+bundler-audit
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # gruf-zipkin - Zipkin tracing for gruf
2
2
 
3
- [![Build Status](https://travis-ci.org/bigcommerce/gruf-zipkin.svg?branch=master)](https://travis-ci.org/bigcommerce/gruf-zipkin)
3
+ [![Build Status](https://travis-ci.org/bigcommerce/gruf-zipkin.svg?branch=master)](https://travis-ci.org/bigcommerce/gruf-zipkin) [![Gem Version](https://badge.fury.io/rb/gruf-zipkin.svg)](https://badge.fury.io/rb/gruf-zipkin) [![Inline docs](http://inch-ci.org/github/bigcommerce/gruf-zipkin.svg?branch=master)](http://inch-ci.org/github/bigcommerce/gruf-zipkin)
4
4
 
5
- Adds Zipkin tracing support for [gruf](https://github.com/bigcommerce/gruf) 1.0.0 or later.
5
+ Adds Zipkin tracing support for [gruf](https://github.com/bigcommerce/gruf) 2.0.0+.
6
6
 
7
7
  ## Installation
8
8
 
@@ -25,9 +25,8 @@ Rails.application.config.zipkin_tracer = {
25
25
  sample_rate: 0.1 # 0.0 to 1.0, where 1.0 => 100% of requests
26
26
  }
27
27
  Gruf.configure do |c|
28
- c.hook_options[:zipkin] = Rails.application.config.zipkin_tracer
28
+ c.interceptors.use(Gruf::Zipkin::Interceptor, Rails.application.config.zipkin_tracer)
29
29
  end
30
- Gruf::Hooks::Registry.add(:zipkin, Gruf::Zipkin::Hook)
31
30
  ```
32
31
 
33
32
  This assumes you have Zipkin already setup in your Ruby/Rails app via the installation
@@ -47,9 +46,10 @@ You can further customize the tracing of gruf services via the configuration:
47
46
 
48
47
  ```ruby
49
48
  Gruf.configure do |c|
50
- c.hook_options[:zipkin] = {
49
+ c.interceptors.use(
50
+ Gruf::Zipkin::Interceptor,
51
51
  span_prefix: 'myapp'
52
- }
52
+ )
53
53
  end
54
54
  ```
55
55
 
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
2
  #
4
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
@@ -26,6 +25,7 @@ Gem::Specification.new do |spec|
26
25
  spec.summary = %q{Plugin for zipkin tracing for gruf}
27
26
  spec.description = spec.summary
28
27
  spec.homepage = 'https://github.com/bigcommerce/gruf-zipkin'
28
+ spec.license = 'MIT'
29
29
 
30
30
  spec.files = Dir['README.md', 'CHANGELOG.md', 'CODE_OF_CONDUCT.md', 'lib/**/*', 'gruf-zipkin.gemspec']
31
31
  spec.require_paths = ['lib']
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
2
  #
4
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
@@ -19,9 +18,14 @@ require_relative 'zipkin/version'
19
18
  require_relative 'zipkin/headers'
20
19
  require_relative 'zipkin/method'
21
20
  require_relative 'zipkin/trace'
22
- require_relative 'zipkin/hook'
21
+ require_relative 'zipkin/interceptor'
23
22
 
23
+ ##
24
+ # Gruf main base module
24
25
  module Gruf
26
+ ##
27
+ # Zipkin gruf module
28
+ #
25
29
  module Zipkin
26
30
  end
27
31
  end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
2
  #
4
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
@@ -26,11 +25,11 @@ module Gruf
26
25
  # @property [Hash<Symbol|Array<String>>] Hash mapping of metadata keys
27
26
  #
28
27
  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)
28
+ parent_span_id: %w(x-b3-parentspanid X-B3-ParentSpanId HTTP_X_B3_PARENTSPANID),
29
+ span_id: %w(x-b3-spanid X-B3-SpanId HTTP_X_B3_SPANID),
30
+ trace_id: %w(x-b3-traceid X-B3-TraceId HTTP_X_B3_TRACEID),
31
+ sampled: %w(x-b3-sampled X-B3-Sampled HTTP_X_B3_SAMPLED),
32
+ flags: %w(x-b3-flags X-B3-Flags HTTP_X_B3_FLAGS)
34
33
  }.freeze
35
34
 
36
35
  ##
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
2
  #
4
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
@@ -16,30 +15,22 @@
16
15
  #
17
16
  module Gruf
18
17
  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
-
18
+ ##
19
+ # Intercepts calls to provide Zipkin tracing
20
+ #
21
+ class Interceptor < Gruf::Interceptors::ServerInterceptor
29
22
  ##
30
23
  # Handle the gruf around hook and trace sampled requests
31
24
  #
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)
25
+ def call(&block)
26
+ # do this here to ensure the tracer is initialized before the trace block. Zipkin's library has poor OOE support
27
+ tr = tracer
38
28
 
39
- if trace.sampled?
29
+ trace = build_trace
30
+ if trace && trace.sampled?
40
31
  result = nil
41
32
  ::ZipkinTracer::TraceContainer.with_trace_id(trace.trace_id) do
42
- result = trace.trace!(@tracer, &block)
33
+ result = trace.trace!(tr, &block)
43
34
  end
44
35
  else
45
36
  result = yield
@@ -47,31 +38,31 @@ module Gruf
47
38
  result
48
39
  end
49
40
 
41
+ private
42
+
50
43
  ##
51
- # @return [String]
44
+ # @return [ZipkinTracer::Config]
52
45
  #
53
- def service_key
54
- service.class.name.underscore.tr('/', '.')
46
+ def config
47
+ @config ||= ::ZipkinTracer::Config.new(nil, { sampled_as_boolean: false }.merge(options)).freeze
55
48
  end
56
49
 
57
50
  ##
58
- # @return [Hash]
51
+ # @return [Trace::ZipkinTracerBase]
59
52
  #
60
- def options
61
- @options.fetch(:zipkin, {})
53
+ def tracer
54
+ @tracer ||= ::ZipkinTracer::TracerFactory.new.tracer(config)
62
55
  end
63
56
 
64
- private
65
-
66
57
  ##
67
- # @param [Symbol] call_signature
68
- # @param [Object] request
69
- # @param [GRPC::ActiveCall] active_call
70
58
  # @return [Gruf::Zipkin::Trace]
71
59
  #
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)
60
+ def build_trace
61
+ method = Gruf::Zipkin::Method.new(request.active_call, request.method_key, request.message)
62
+ Gruf::Zipkin::Trace.new(method, request.service_key, options)
63
+ rescue StandardError => e # catchall for zipkin failure
64
+ Gruf.logger.error "Failed to build zipkin trace: #{e.message}"
65
+ nil
75
66
  end
76
67
  end
77
68
  end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
2
  #
4
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
@@ -29,7 +28,7 @@ module Gruf
29
28
  #
30
29
  def initialize(active_call, signature, request)
31
30
  @active_call = active_call
32
- @signature = signature.to_s.gsub('_without_intercept', '')
31
+ @signature = signature.to_s
33
32
  @request = request
34
33
  end
35
34
 
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
2
  #
4
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
@@ -71,7 +70,7 @@ module Gruf
71
70
  begin
72
71
  result = block.call(method.request, method.active_call)
73
72
  span.record(::Trace::Annotation::SERVER_SEND)
74
- rescue => e
73
+ rescue StandardError => e
75
74
  if e.is_a?(::GRPC::BadStatus)
76
75
  span.record_tag(METADATA_KEYS[:error], true)
77
76
  span.record_tag(METADATA_KEYS[:grpc][:error], true)
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
2
  #
4
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
@@ -16,6 +15,6 @@
16
15
  #
17
16
  module Gruf
18
17
  module Zipkin
19
- VERSION = '0.10.3'.freeze
18
+ VERSION = '1.0.0'.freeze
20
19
  end
21
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gruf-zipkin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-12 00:00:00.000000000 Z
11
+ date: 2017-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,12 +93,13 @@ files:
93
93
  - gruf-zipkin.gemspec
94
94
  - lib/gruf/zipkin.rb
95
95
  - lib/gruf/zipkin/headers.rb
96
- - lib/gruf/zipkin/hook.rb
96
+ - lib/gruf/zipkin/interceptor.rb
97
97
  - lib/gruf/zipkin/method.rb
98
98
  - lib/gruf/zipkin/trace.rb
99
99
  - lib/gruf/zipkin/version.rb
100
100
  homepage: https://github.com/bigcommerce/gruf-zipkin
101
- licenses: []
101
+ licenses:
102
+ - MIT
102
103
  metadata: {}
103
104
  post_install_message:
104
105
  rdoc_options: []