Class: Yabeda::GraphQL::YabedaTracing
- Inherits:
-
GraphQL::Tracing::PlatformTracing
- Object
- GraphQL::Tracing::PlatformTracing
- Yabeda::GraphQL::YabedaTracing
- Defined in:
- lib/yabeda/graphql/yabeda_tracing.rb
Instance Method Summary collapse
- #cache(query) ⇒ Object
- #extract_field_tags(field) ⇒ Object
- #extract_field_trace_data(data) ⇒ Object
- #instrument_field_execution(query, path, tags, duration) ⇒ Object
- #instrument_mutation_execution(tags) ⇒ Object
- #instrument_query_execution(tags) ⇒ Object
-
#platform_authorized_key(type) ⇒ Object
We don’t use these yet, but graphql-ruby require us to declare them.
- #platform_field_key(type, field) ⇒ Object
- #platform_resolve_type_key(type) ⇒ Object
- #platform_trace(platform_key, key, data, &block) ⇒ Object
Instance Method Details
#cache(query) ⇒ Object
81 82 83 |
# File 'lib/yabeda/graphql/yabeda_tracing.rb', line 81 def cache(query) query.context.namespace(Yabeda::GraphQL)[:field_call_cache] end |
#extract_field_tags(field) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/yabeda/graphql/yabeda_tracing.rb', line 57 def (field) owner = field.respond_to?(:owner) ? field.owner : field.[:type_class].owner { type: owner.graphql_name, field: field.graphql_name, deprecated: !field.deprecation_reason.nil?, } end |
#extract_field_trace_data(data) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/yabeda/graphql/yabeda_tracing.rb', line 49 def extract_field_trace_data(data) if data[:context] # Legacy non-interpreter mode [data[:context].field, data[:context].path, data[:context].query] else # Interpreter mode data.values_at(:field, :path, :query) end end |
#instrument_field_execution(query, path, tags, duration) ⇒ Object
66 67 68 69 |
# File 'lib/yabeda/graphql/yabeda_tracing.rb', line 66 def instrument_field_execution(query, path, , duration) cache(query)[path][:tags] = cache(query)[path][:duration] += duration end |
#instrument_mutation_execution(tags) ⇒ Object
71 72 73 74 |
# File 'lib/yabeda/graphql/yabeda_tracing.rb', line 71 def instrument_mutation_execution() = { name: [:field], deprecated: [:deprecated] } Yabeda.graphql.mutation_fields_count.increment() end |
#instrument_query_execution(tags) ⇒ Object
76 77 78 79 |
# File 'lib/yabeda/graphql/yabeda_tracing.rb', line 76 def instrument_query_execution() = { name: [:field], deprecated: [:deprecated] } Yabeda.graphql.query_fields_count.increment() end |
#platform_authorized_key(type) ⇒ Object
We don’t use these yet, but graphql-ruby require us to declare them
91 92 93 |
# File 'lib/yabeda/graphql/yabeda_tracing.rb', line 91 def (type) "#{type.graphql_name}.authorized" end |
#platform_field_key(type, field) ⇒ Object
85 86 87 |
# File 'lib/yabeda/graphql/yabeda_tracing.rb', line 85 def platform_field_key(type, field) "#{type.graphql_name}.#{field.graphql_name}" end |
#platform_resolve_type_key(type) ⇒ Object
95 96 97 |
# File 'lib/yabeda/graphql/yabeda_tracing.rb', line 95 def platform_resolve_type_key(type) "#{type.graphql_name}.resolve_type" end |
#platform_trace(platform_key, key, data, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/yabeda/graphql/yabeda_tracing.rb', line 20 def platform_trace(platform_key, key, data, &block) start = ::Process.clock_gettime ::Process::CLOCK_MONOTONIC result = block.call duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start case key when "execute_field", "execute_field_lazy" field, path, query = extract_field_trace_data(data) = (field) if path.length == 1 return result if key == "execute_field" && query.schema.lazy?(result) if query.query? instrument_query_execution() elsif query.mutation? instrument_mutation_execution() elsif query.subscription? # Not implemented yet end else instrument_field_execution(query, path, , duration) end end result end |