Class: GraphQL::Tracing::MonitorTrace::Monitor
- Inherits:
-
Object
- Object
- GraphQL::Tracing::MonitorTrace::Monitor
- Defined in:
- lib/graphql/tracing/monitor_trace.rb
Direct Known Subclasses
AppsignalTrace::AppsignalMonitor, DataDogTrace::DatadogMonitor, NewRelicTrace::NewrelicMonitor, PrometheusTrace::PrometheusMonitor, ScoutTrace::ScoutMonitor, SentryTrace::SentryMonitor, StatsdTrace::StatsdMonitor
Defined Under Namespace
Modules: GraphQLPrefixNames, GraphQLSuffixNames Classes: Event
Instance Method Summary collapse
- #fallback_transaction_name(context) ⇒ Object
-
#initialize(trace:, set_transaction_name:, **_rest) ⇒ Monitor
constructor
A new instance of Monitor.
- #instrument(keyword, object, &block) ⇒ Object
- #name_for(keyword, object) ⇒ Object
- #start_event(keyword, object) ⇒ Object
-
#transaction_name(query) ⇒ Object
Get the transaction name based on the operation type and name if possible, or fall back to a user provided one.
Constructor Details
#initialize(trace:, set_transaction_name:, **_rest) ⇒ Monitor
Returns a new instance of Monitor.
13 14 15 16 17 18 19 20 |
# File 'lib/graphql/tracing/monitor_trace.rb', line 13 def initialize(trace:, set_transaction_name:, **_rest) @trace = trace @set_transaction_name = set_transaction_name @platform_field_key_cache = Hash.new { |h, k| h[k] = platform_field_key(k) }.compare_by_identity @platform_authorized_key_cache = Hash.new { |h, k| h[k] = (k) }.compare_by_identity @platform_resolve_type_key_cache = Hash.new { |h, k| h[k] = platform_resolve_type_key(k) }.compare_by_identity @platform_source_class_key_cache = Hash.new { |h, source_cls| h[source_cls] = platform_source_class_key(source_cls) }.compare_by_identity end |
Instance Method Details
#fallback_transaction_name(context) ⇒ Object
46 47 48 |
# File 'lib/graphql/tracing/monitor_trace.rb', line 46 def fallback_transaction_name(context) context[:tracing_fallback_transaction_name] end |
#instrument(keyword, object, &block) ⇒ Object
22 23 24 |
# File 'lib/graphql/tracing/monitor_trace.rb', line 22 def instrument(keyword, object, &block) raise "Implement #{self.class}#instrument to measure the block" end |
#name_for(keyword, object) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/graphql/tracing/monitor_trace.rb', line 50 def name_for(keyword, object) case keyword when :execute_field @platform_field_key_cache[object] when :authorized @platform_authorized_key_cache[object] when :resolve_type @platform_resolve_type_key_cache[object] when :dataloader_source @platform_source_class_key_cache[object.class] when :parse then self.class.const_get(:PARSE_NAME) when :lex then self.class.const_get(:LEX_NAME) when :execute then self.class.const_get(:EXECUTE_NAME) when :analyze then self.class.const_get(:ANALYZE_NAME) when :validate then self.class.const_get(:VALIDATE_NAME) else raise "No name for #{keyword.inspect}" end end |
#start_event(keyword, object) ⇒ Object
26 27 28 29 30 |
# File 'lib/graphql/tracing/monitor_trace.rb', line 26 def start_event(keyword, object) ev = self.class.const_get(:Event).new(self, keyword, object) ev.start ev end |
#transaction_name(query) ⇒ Object
Get the transaction name based on the operation type and name if possible, or fall back to a user provided one. Useful for anonymous queries.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/graphql/tracing/monitor_trace.rb', line 34 def transaction_name(query) selected_op = query.selected_operation txn_name = if selected_op op_type = selected_op.operation_type op_name = selected_op.name || fallback_transaction_name(query.context) || "anonymous" "#{op_type}.#{op_name}" else "query.anonymous" end "GraphQL/#{txn_name}" end |