apollo-tracing 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ce351de83cfe780dc152768b22274e822bd3bd02
4
+ data.tar.gz: 77e54bc35f506288f4456828f7968694bea3eab3
5
+ SHA512:
6
+ metadata.gz: b9fb6347e03e0d62173308209d46316aa5ce5b49f0c858d11367c201a1b3d660d3bb8790f8f3e1e8d374f16d9a20004ea25f10acd65a432a89dfdbaea77c56d4
7
+ data.tar.gz: d611be717f55895b345c1399ff2b39be246e46e0ae0425ce111c04924d0e1737c95943edbcba15b7b39106cf7cb6949fecd36ebafc6e15f9cc1862b2f3bceff3
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ 2.3.4
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ script: bundle exec rspec
@@ -0,0 +1,41 @@
1
+ # Changelog
2
+
3
+ The following are lists of the notable changes included with each release.
4
+ This is intended to help keep people informed about notable changes between
5
+ versions, as well as provide a rough history. Each item is prefixed with
6
+ one of the following labels: `Added`, `Changed`, `Deprecated`,
7
+ `Removed`, `Fixed`, `Security`. We also use [Semantic Versioning](http://semver.org)
8
+ to manage the versions of this gem so
9
+ that you can set version constraints properly.
10
+
11
+ #### [Unreleased](https://github.com/uniiverse/apollo-tracing-ruby/compare/v1.0.0...HEAD)
12
+
13
+ * WIP
14
+
15
+ #### [v1.0.0](https://github.com/uniiverse/apollo-tracing-ruby/compare/v0.1.1...v1.0.0) – 2017-10-17
16
+
17
+ * `Changed`: the gem name from `graphql-tracing` to `apollo-tracing`.
18
+
19
+ ```ruby
20
+ # Before:
21
+
22
+ Schema = GraphQL::Schema.define do
23
+ use GraphQL::Tracing.new
24
+ end
25
+ ```
26
+
27
+ ```ruby
28
+ # After:
29
+
30
+ Schema = GraphQL::Schema.define do
31
+ use ApolloTracing.new
32
+ end
33
+ ```
34
+
35
+ #### [v0.1.1](https://github.com/uniiverse/apollo-tracing-ruby/compare/v0.1.0...v0.1.1) – 2017-10-17
36
+
37
+ * `Fixed`: naming conflicts with [graphql-ruby](https://github.com/rmosolgo/graphql-ruby/pull/996) by restricting the gem version.
38
+
39
+ #### [v0.1.0](https://github.com/uniiverse/apollo-tracing-ruby/compare/d346dd2...v0.1.0) – 2017-08-28
40
+
41
+ * `Added`: initial functional version.
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at rsuh@uwaterloo.ca. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in apollo-tracing.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Reginald
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,157 @@
1
+ # Apollo Tracing
2
+
3
+ [![Build Status](https://travis-ci.org/uniiverse/apollo-tracing-ruby.svg?branch=master)](https://travis-ci.org/uniiverse/apollo-tracing-ruby)
4
+
5
+ Ruby implementation of [GraphQL](https://github.com/rmosolgo/graphql-ruby) trace data in the [Apollo Tracing](https://github.com/apollographql/apollo-tracing) format.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'apollo-tracing'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install apollo-tracing
22
+
23
+ ## Usage
24
+
25
+ Define a GraphQL schema:
26
+
27
+ ```ruby
28
+ # Define a type
29
+ PostType = GraphQL::ObjectType.define do
30
+ name "Post"
31
+
32
+ field :id, !types.ID
33
+ field :title, !types.String
34
+ end
35
+
36
+ # Define a query
37
+ QueryType = GraphQL::ObjectType.define do
38
+ name "Query"
39
+
40
+ field :posts, !types[PostType] do
41
+ argument :user_id, !types.ID
42
+ resolve ->(obj, args, ctx) { Post.where(user_id: args[:user_id]) }
43
+ end
44
+ end
45
+
46
+ # Define a schema
47
+ Schema = GraphQL::Schema.define do
48
+ query QueryType
49
+ end
50
+
51
+ # Execute query
52
+ query = "query($user_id: ID!) {
53
+ posts(user_id: $user_id) {
54
+ id
55
+ title
56
+ }
57
+ }"
58
+ Schema.execute(query, variables: { user_id: 1 })
59
+ ```
60
+
61
+ ### Setup Tracing
62
+
63
+ Add 'ApolloTracing' to your schema:
64
+
65
+ <pre>
66
+ Schema = GraphQL::Schema.define do
67
+ query QueryType
68
+ <b>use ApolloTracing.new</b>
69
+ end
70
+ </pre>
71
+
72
+ Now your response should look something like:
73
+ ```
74
+ {
75
+ "data":{
76
+ "posts":[
77
+ {
78
+ "id":"1",
79
+ "title":"Post Title"
80
+ }
81
+ ]
82
+ },
83
+ "extensions":{
84
+ "tracing":{
85
+ "version":1,
86
+ "startTime":"2017-08-25T19:55:04.821Z",
87
+ "endTime":"2017-08-25T19:55:04.823Z",
88
+ "duration":1702785,
89
+ "execution":{
90
+ "resolvers":[
91
+ {
92
+ "path":[
93
+ "posts"
94
+ ],
95
+ "parentType":"Query",
96
+ "fieldName":"posts",
97
+ "returnType":"[Post!]!",
98
+ "startOffset":1451015,
99
+ "duration":15735
100
+ },
101
+ {
102
+ "path":[
103
+ "posts",
104
+ 0,
105
+ "id"
106
+ ],
107
+ "parentType":"Post",
108
+ "fieldName":"id",
109
+ "returnType":"ID!",
110
+ "startOffset":1556873,
111
+ "duration":6914
112
+ },
113
+ {
114
+ "path":[
115
+ "posts",
116
+ 0,
117
+ "title"
118
+ ],
119
+ "parentType":"Post",
120
+ "fieldName":"title",
121
+ "returnType":"String!",
122
+ "startOffset":1604795,
123
+ "duration":4053
124
+ },
125
+ {
126
+ "path":[
127
+ "posts",
128
+ 0,
129
+ "user_id"
130
+ ],
131
+ "parentType":"Post",
132
+ "fieldName":"user_id",
133
+ "returnType":"ID!",
134
+ "startOffset":1642942,
135
+ "duration":3814
136
+ }
137
+ ]
138
+ }
139
+ }
140
+ }
141
+ }
142
+ ```
143
+
144
+ ## Development
145
+
146
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
147
+
148
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
149
+
150
+ ## Contributing
151
+
152
+ Bug reports and pull requests are welcome on GitHub at https://github.com/uniiverse/apollo-tracing-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
153
+
154
+ ## License
155
+
156
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
157
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'apollo_tracing/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "apollo-tracing"
8
+ spec.version = ApolloTracing::VERSION
9
+ spec.authors = ["Reginald Suh", "Evgeny Li"]
10
+ spec.email = ["evgeny.li@universe.com", "rsuh@edu.uwaterloo.ca"]
11
+
12
+ spec.summary = %q{Ruby implementation of GraphQL trace data in the Apollo Tracing format.}
13
+ spec.description = %q{Ruby implementation of GraphQL trace data in the Apollo Tracing format.}
14
+ spec.homepage = "https://github.com/uniiverse/apollo-tracing-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.required_ruby_version = '>= 2.1.0' # keyword args
25
+
26
+ spec.add_runtime_dependency "graphql", ">= 1.6.0", "< 2"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.14"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency "pry"
32
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "apollo_tracing"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../apollo_tracing'
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "graphql"
4
+ require "apollo_tracing/version"
5
+
6
+ class ApolloTracing
7
+ def use(schema_definition)
8
+ schema_definition.instrument(:query, self)
9
+ schema_definition.instrument(:field, self)
10
+ end
11
+
12
+ def before_query(query)
13
+ query.context['apollo-tracing'] = {
14
+ 'start_time' => Time.now.utc,
15
+ 'resolvers' => []
16
+ }
17
+ end
18
+
19
+ def after_query(query)
20
+ result = query.result
21
+ end_time = Time.now.utc
22
+ duration_nanos = duration_nanos(start_time: query.context['apollo-tracing']['start_time'], end_time: end_time)
23
+
24
+ result["extensions"] ||= {}
25
+ result["extensions"]["tracing"] = {
26
+ "version" => 1,
27
+ "startTime" => query.context['apollo-tracing']['start_time'].strftime('%FT%T.%3NZ'),
28
+ "endTime" => end_time.strftime('%FT%T.%3NZ'),
29
+ "duration" => duration_nanos,
30
+ "execution" => {
31
+ "resolvers" => query.context['apollo-tracing']['resolvers']
32
+ }
33
+ }
34
+ end
35
+
36
+ def instrument(type, field)
37
+ old_resolve_proc = field.resolve_proc
38
+
39
+ new_resolve_proc = ->(obj, args, ctx) do
40
+ resolve_start_time = Time.now.utc
41
+ result = old_resolve_proc.call(obj, args, ctx)
42
+ resolve_end_time = Time.now.utc
43
+
44
+ ctx['apollo-tracing']['resolvers'] << {
45
+ 'path' => ctx.path,
46
+ 'parentType' => type.name,
47
+ 'fieldName' => field.name,
48
+ 'returnType' => field.type.to_s,
49
+ 'startOffset' => duration_nanos(start_time: ctx['apollo-tracing']['start_time'], end_time: resolve_start_time),
50
+ 'duration' => duration_nanos(start_time: resolve_start_time, end_time: resolve_end_time)
51
+ }
52
+
53
+ result
54
+ end
55
+
56
+ field.redefine { resolve(new_resolve_proc) }
57
+ end
58
+
59
+ private
60
+
61
+ def duration_nanos(start_time:, end_time:)
62
+ ((end_time.to_f - start_time.to_f) * 1e9).to_i
63
+ end
64
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApolloTracing
4
+ VERSION = "1.0.0"
5
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apollo-tracing
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Reginald Suh
8
+ - Evgeny Li
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-10-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: graphql
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 1.6.0
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '2'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: 1.6.0
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: pry
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ description: Ruby implementation of GraphQL trace data in the Apollo Tracing format.
91
+ email:
92
+ - evgeny.li@universe.com
93
+ - rsuh@edu.uwaterloo.ca
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - ".gitignore"
99
+ - ".rspec"
100
+ - ".ruby-version"
101
+ - ".travis.yml"
102
+ - CHANGELOG.md
103
+ - CODE_OF_CONDUCT.md
104
+ - Gemfile
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - apollo-tracing.gemspec
109
+ - bin/console
110
+ - bin/setup
111
+ - lib/apollo/tracing.rb
112
+ - lib/apollo_tracing.rb
113
+ - lib/apollo_tracing/version.rb
114
+ homepage: https://github.com/uniiverse/apollo-tracing-ruby
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 2.1.0
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.6.13
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Ruby implementation of GraphQL trace data in the Apollo Tracing format.
138
+ test_files: []