graphql-opentracing 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b60128dba178e274a2326bb1a1a96be149890df
4
- data.tar.gz: 92c4629475a4e6d706def8eed6f7ed3e5e98f319
3
+ metadata.gz: 8d648af2c21ad166ce60ccdaa6684367130a830c
4
+ data.tar.gz: 488781fda3b16de2272388eb55bd5bff44f2f6a0
5
5
  SHA512:
6
- metadata.gz: 3e55ae32c014d2743ef4b78b9456e3a56daeb30aed72eac1d875a794b0c8dbb829a51fff19d950814085eb0efe4ecd917d93f27048762707449fc08c85918b89
7
- data.tar.gz: 20cd2923c4504bdba7b2f3b708352cb00998282956cb3ab4180f86a134beea89f223f6fccf88d4916523d22396da52b9ea9d448fb345fdb4dc7c6280e7b84644
6
+ metadata.gz: 51132d0527b462918eee0e0897ad954f4a9a55a505f28c75d2f3d8380062b64e6555090e3c201040e8d5450a100132c4fa78a46d4b8b8bb5e3d2b2d92a053f5a
7
+ data.tar.gz: a30fbb76b03ec618cf4254da896e0d9e7f3777a64007268dcf6fa24177a6c266740159327ea7cf873a26ed58c16cccfcacb9534af947c6a00589454a16ac8421
@@ -1,5 +1,8 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ## 0.2.0 10/29/2019
5
+ * Move instrumentation off ActiveSupport onto the custom tracer framework
6
+
4
7
  ## 0.1.0 10/10/2019
5
8
  * Instrumention for open tracing
@@ -1,24 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql-opentracing (0.1.0)
5
- activesupport
4
+ graphql-opentracing (0.2.0)
6
5
  opentracing (~> 0.5.0)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
10
9
  specs:
11
- activesupport (5.2.3)
12
- concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
16
- concurrent-ruby (1.1.5)
17
10
  diff-lcs (1.3)
18
11
  graphql (1.9.12)
19
- i18n (1.6.0)
20
- concurrent-ruby (~> 1.0)
21
- minitest (5.11.3)
22
12
  opentracing (0.5.0)
23
13
  rake (10.5.0)
24
14
  rspec (3.8.0)
@@ -34,9 +24,6 @@ GEM
34
24
  diff-lcs (>= 1.2.0, < 2.0)
35
25
  rspec-support (~> 3.8.0)
36
26
  rspec-support (3.8.2)
37
- thread_safe (0.3.6)
38
- tzinfo (1.2.5)
39
- thread_safe (~> 0.1)
40
27
 
41
28
  PLATFORMS
42
29
  ruby
data/README.md CHANGED
@@ -38,19 +38,12 @@ tracer(GraphQL::Tracing::ActiveSupportNotificationsTracing)
38
38
  Under the hood this gem subscribes to graphql instrumentation events through the ActiveSupport notifications framework. If you find the number of spans too noisy you can control which spans are reported though a callback like:
39
39
  ```
40
40
  GraphQl::Tracer.instrument(
41
+ schema: MyGQLSchema,
41
42
  tracer: tracer,
42
43
  ignore_request: ->(name, started, finished, id, data) { !name.include? 'execute_query' }
43
44
  )
44
45
  ```
45
46
 
46
- If you have a bespoke way of passing errors in the response that is not part of context errors you can detect errors for tagging your spans through a callback:
47
- ```
48
- GraphQl::Tracer.instrument(
49
- tracer: tracer,
50
- check_errors: ->(name, started, finished, id, data) { data[:context] == "whatever" }
51
- )
52
- ```
53
-
54
47
  ## Development
55
48
 
56
49
  After checking out the repo, run `bundle install` to install dependencies. Then, run `rspec` to run the tests.
@@ -29,7 +29,6 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  spec.add_dependency "opentracing", "~> 0.5.0"
32
- spec.add_dependency "activesupport"
33
32
  spec.add_development_dependency "graphql"
34
33
  spec.add_development_dependency "bundler", "~> 2.0"
35
34
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Opentracing
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'graphql/opentracing/version'
2
- require 'active_support'
3
4
 
4
5
  module GraphQL
5
6
  module Tracer
6
- class IncompatibleGemVersion < StandardError; end;
7
+ class IncompatibleGemVersion < StandardError; end
7
8
 
8
9
  class << self
9
10
  attr_accessor :ignore_request, :tracer
10
11
 
11
- IgnoreRequest = ->(_name, _started, _finished, _id, _data) { false }
12
- CheckErrors = -> (_name, _started, _finished, _id, data) { data[:context]&.errors&.any? }
13
- def instrument(tracer: OpenTracing.global_tracer, ignore_request: IgnoreRequest, check_errors: CheckErrors)
12
+ IgnoreRequest = ->(_name, _metadata) { false }
13
+
14
+ def instrument(schema: nil, tracer: OpenTracing.global_tracer,
15
+ ignore_request: IgnoreRequest)
14
16
  begin
15
17
  require 'graphql'
16
18
  rescue LoadError
@@ -18,10 +20,10 @@ module GraphQL
18
20
  end
19
21
  raise IncompatibleGemVersion unless compatible_version?
20
22
 
23
+ @schema = schema
21
24
  @ignore_request = ignore_request
22
- @check_errors = check_errors
23
25
  @tracer = tracer
24
- subscribe_active_support_notifications
26
+ install_tracer
25
27
  end
26
28
 
27
29
  def compatible_version?
@@ -29,21 +31,23 @@ module GraphQL
29
31
  Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.7.0')
30
32
  end
31
33
 
32
- def subscribe_active_support_notifications
33
- ActiveSupport::Notifications.subscribe(/^graphql/) do |name, started, finished, id, data|
34
- next if @ignore_request.call(name, started, finished, id, data)
35
-
36
- tags = {
37
- "component" => "ruby-graphql",
38
- "span.kind" => "server",
39
- "operation" => name
40
- }
41
- span = tracer.start_span("graphql",
42
- tags: tags,
43
- start_time: started)
44
-
45
- span.set_tag("error", true) if @check_errors.call(name, started, finished, id, data)
46
- span.finish(end_time: finished)
34
+ def install_tracer
35
+ @schema.tracer self if @schema
36
+ end
37
+
38
+ def trace(key, metadata)
39
+ return yield if @ignore_request.call(key, metadata)
40
+
41
+ @tracer.start_active_span("graphql.#{key}", tags: {
42
+ 'component' => 'ruby-graphql',
43
+ 'span.kind' => 'server'
44
+ }) do |scope|
45
+ begin
46
+ yield
47
+ rescue StandardError
48
+ scope.span.set_tag('error', true)
49
+ raise
50
+ end
47
51
  end
48
52
  end
49
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-opentracing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Fischer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-10 00:00:00.000000000 Z
11
+ date: 2019-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentracing
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.5.0
27
- - !ruby/object:Gem::Dependency
28
- name: activesupport
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: graphql
43
29
  requirement: !ruby/object:Gem::Requirement