optics-agent 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -1
- data/lib/optics-agent/agent.rb +1 -0
- data/lib/optics-agent/instrumenters/field.rb +7 -1
- data/spec/field_connection_instrumenter_spec.rb +59 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e66f0b58d77d29c4999ab86a26b9881eec66b75d
|
4
|
+
data.tar.gz: 2cbac6e78c27f4636cc40c94e8cf613e764946a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1eec3c92af1dfad4da0a0c22bba4eb0d458100e4947a3c4392867884e1f1caff11550d973aca07c4147becd0eef51bb712e5e72ab4955c03a53c3b9f011509b9
|
7
|
+
data.tar.gz: 56466763944928e04c81a8467a774fd978064ce8d144be2445058add1179af57fb0bc523125c91e56be948f6566474124044d27943fbc5e39a4c928e7cd12974
|
data/README.md
CHANGED
@@ -63,7 +63,7 @@ You must:
|
|
63
63
|
|
64
64
|
### Configuration
|
65
65
|
|
66
|
-
After creating an agent, you can configure it with:
|
66
|
+
After creating an agent, you can configure it with (the values listed are the defaults):
|
67
67
|
|
68
68
|
```rb
|
69
69
|
# defaults are show below
|
@@ -102,6 +102,30 @@ agent.configure do
|
|
102
102
|
end
|
103
103
|
```
|
104
104
|
|
105
|
+
## Troubleshooting
|
106
|
+
|
107
|
+
The Optics agent is designed to allow your application to continue working, even if the agent is not configured properly.
|
108
|
+
|
109
|
+
### No data in Optics
|
110
|
+
|
111
|
+
If there is no data being sent to Optics, ensure you've followed the steps above, then check your application logs to look for the following messages:
|
112
|
+
|
113
|
+
### Message: No api_key set.
|
114
|
+
|
115
|
+
Solution: Get a valid API key from Optics and use the `OPTICS_API_KEY` environment variable, or [configuration](#configuration) to pass it to the agent.
|
116
|
+
|
117
|
+
### Message: No schema instrumented
|
118
|
+
|
119
|
+
Solution: Ensure you are passing your schema to the agent [configuration](#configuration).
|
120
|
+
|
121
|
+
### Message: No agent passed in graphql context
|
122
|
+
|
123
|
+
Solution: Ensure you are passing `context: { optics_agent: env[:optics_agent].with_document(query_string) }` where `env` is the Rack request environment, and `query_string` is the string representing your query. See the [setup instructions](#rails-setup) for more details.
|
124
|
+
|
125
|
+
### Debugging
|
126
|
+
|
127
|
+
You can also use the `debug` [configuration](#configuration) setting to get more detailed debugging information, which may give hints as to what the issue is.
|
128
|
+
|
105
129
|
## Development
|
106
130
|
|
107
131
|
### Running tests
|
data/lib/optics-agent/agent.rb
CHANGED
@@ -13,9 +13,15 @@ module OpticsAgent
|
|
13
13
|
end
|
14
14
|
}
|
15
15
|
|
16
|
-
field.redefine do
|
16
|
+
new_field = field.redefine do
|
17
17
|
resolve(new_resolve_proc)
|
18
18
|
end
|
19
|
+
|
20
|
+
if old_resolve_proc.instance_of? GraphQL::Relay::ConnectionResolve
|
21
|
+
new_field.arguments = field.arguments
|
22
|
+
end
|
23
|
+
|
24
|
+
new_field
|
19
25
|
end
|
20
26
|
|
21
27
|
def middleware(agent, parent_type, parent_object, field_definition, field_args, query_context, next_middleware)
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'optics-agent/instrumenters/field'
|
3
|
+
require 'graphql'
|
4
|
+
|
5
|
+
include OpticsAgent
|
6
|
+
|
7
|
+
describe "connection" do
|
8
|
+
it 'collects the correct query stats' do
|
9
|
+
person_type = GraphQL::ObjectType.define do
|
10
|
+
name "Person"
|
11
|
+
field :firstName do
|
12
|
+
type types.String
|
13
|
+
resolve -> (obj, args, ctx) { sleep(0.100); return 'Tom' }
|
14
|
+
end
|
15
|
+
field :lastName do
|
16
|
+
type types.String
|
17
|
+
resolve -> (obj, args, ctx) { sleep(0.100); return 'Coleman' }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
query_type = GraphQL::ObjectType.define do
|
21
|
+
name 'Query'
|
22
|
+
field :person do
|
23
|
+
type person_type
|
24
|
+
resolve -> (obj, args, ctx) { sleep(0.050); return {} }
|
25
|
+
end
|
26
|
+
connection :people do
|
27
|
+
type person_type.connection_type
|
28
|
+
resolve -> (obj, args, ctx) { ["a", "b", "c"] }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
instrumenter = Instrumenters::Field.new
|
33
|
+
instrumenter.agent = true
|
34
|
+
schema = GraphQL::Schema.define do
|
35
|
+
query query_type
|
36
|
+
instrument :field, instrumenter
|
37
|
+
end
|
38
|
+
|
39
|
+
query = spy("query")
|
40
|
+
allow(query).to receive(:duration_so_far).and_return(1.0)
|
41
|
+
|
42
|
+
result = schema.execute('{ people(first: 2) { edges { node { firstName lastName } } } }', {
|
43
|
+
context: { optics_agent: OpenStruct.new(query: query) }
|
44
|
+
})
|
45
|
+
|
46
|
+
expect(result).not_to have_key("errors")
|
47
|
+
expect(result).to have_key("data")
|
48
|
+
|
49
|
+
expect(query).to have_received(:report_field).exactly(1 + 1 + 2 * 1 + 2 * 2).times
|
50
|
+
expect(query).to have_received(:report_field)
|
51
|
+
.with('Query', 'people', be_instance_of(Float), be_instance_of(Float))
|
52
|
+
expect(query).to have_received(:report_field)
|
53
|
+
.exactly(2).times
|
54
|
+
.with('Person', 'firstName', be_instance_of(Float), be_instance_of(Float))
|
55
|
+
expect(query).to have_received(:report_field)
|
56
|
+
.exactly(2).times
|
57
|
+
.with('Person', 'lastName', be_instance_of(Float), be_instance_of(Float))
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optics-agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 'Tom Coleman '
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/optics-agent/reporting/schema.rb
|
154
154
|
- lib/optics-agent/reporting/schema_job.rb
|
155
155
|
- spec/benchmark/benchmark.rb
|
156
|
+
- spec/field_connection_instrumenter_spec.rb
|
156
157
|
- spec/field_instrumenter_spec.rb
|
157
158
|
- spec/latency_spec.rb
|
158
159
|
- spec/query-normalization_spec.rb
|
@@ -188,6 +189,7 @@ specification_version: 4
|
|
188
189
|
summary: An Agent for Apollo Optics
|
189
190
|
test_files:
|
190
191
|
- spec/benchmark/benchmark.rb
|
192
|
+
- spec/field_connection_instrumenter_spec.rb
|
191
193
|
- spec/field_instrumenter_spec.rb
|
192
194
|
- spec/latency_spec.rb
|
193
195
|
- spec/query-normalization_spec.rb
|