Class: GraphQL::Tracing::MonitorTrace::Monitor
- Inherits:
-
Object
- Object
- GraphQL::Tracing::MonitorTrace::Monitor
show all
- Defined in:
- lib/graphql/tracing/monitor_trace.rb
Defined Under Namespace
Modules: GraphQLPrefixNames, GraphQLSuffixNames
Classes: Event
Instance Method Summary
collapse
Constructor Details
#initialize(trace:, set_transaction_name:, **_rest) ⇒ Monitor
11
12
13
14
15
16
17
18
|
# File 'lib/graphql/tracing/monitor_trace.rb', line 11
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] = platform_authorized_key(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
44
45
46
|
# File 'lib/graphql/tracing/monitor_trace.rb', line 44
def fallback_transaction_name(context)
context[:tracing_fallback_transaction_name]
end
|
#instrument(keyword, object, &block) ⇒ Object
20
21
22
|
# File 'lib/graphql/tracing/monitor_trace.rb', line 20
def instrument(keyword, object, &block)
raise "Implement #{self.class}#instrument to measure the block"
end
|
#name_for(keyword, object) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/graphql/tracing/monitor_trace.rb', line 48
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::PARSE_NAME
when :lex then self.class::LEX_NAME
when :execute then self.class::EXECUTE_NAME
when :analyze then self.class::ANALYZE_NAME
when :validate then self.class::VALIDATE_NAME
else
raise "No name for #{keyword.inspect}"
end
end
|
#start_event(keyword, object) ⇒ Object
24
25
26
27
28
|
# File 'lib/graphql/tracing/monitor_trace.rb', line 24
def start_event(keyword, object)
ev = self.class::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.
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/graphql/tracing/monitor_trace.rb', line 32
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
|