Class: GraphQL::Metrics::Tracer
- Inherits:
-
Object
- Object
- GraphQL::Metrics::Tracer
- Defined in:
- lib/graphql/metrics/tracer.rb
Defined Under Namespace
Classes: PreContext
Constant Summary collapse
- GRAPHQL_GEM_EXECUTE_MULTIPLEX_KEY =
NOTE: These constants come from the graphql ruby gem.
'execute_multiplex'
- GRAPHQL_GEM_PARSING_KEY =
'parse'
- GRAPHQL_GEM_VALIDATION_KEY =
'validate'
- GRAPHQL_GEM_ANALYZE_MULTIPLEX_KEY =
'analyze_multiplex'
- GRAPHQL_GEM_ANALYZE_QUERY_KEY =
'analyze_query'
- GRAPHQL_GEM_EXECUTE_QUERY_KEY =
'execute_query'
- GRAPHQL_GEM_TRACING_FIELD_KEYS =
[ GRAPHQL_GEM_TRACING_FIELD_KEY = 'execute_field', GRAPHQL_GEM_TRACING_LAZY_FIELD_KEY = 'execute_field_lazy' ]
Instance Method Summary collapse
Instance Method Details
#trace(key, data, &block) ⇒ Object
18 19 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/graphql/metrics/tracer.rb', line 18 def trace(key, data, &block) # NOTE: Context doesn't exist yet during lexing, parsing. possible_context = data[:query]&.context skip_tracing = possible_context&.fetch(GraphQL::Metrics::SKIP_GRAPHQL_METRICS_ANALYSIS, false) return yield if skip_tracing # NOTE: Not all tracing events are handled here, but those that are are handled in this case statement in # chronological order. case key when GRAPHQL_GEM_EXECUTE_MULTIPLEX_KEY return capture_multiplex_start_time(&block) when GRAPHQL_GEM_PARSING_KEY return capture_parsing_time(&block) when GRAPHQL_GEM_VALIDATION_KEY context = possible_context return capture_validation_time(context, &block) when GRAPHQL_GEM_ANALYZE_MULTIPLEX_KEY # Ensures that we reset potentially long-lived PreContext objects between multiplexs. We reset at this point # since all parsing and validation will be done by this point, and a GraphQL::Query::Context will exist. pre_context.reset return yield when GRAPHQL_GEM_ANALYZE_QUERY_KEY context = possible_context return capture_analysis_time(context, &block) when GRAPHQL_GEM_EXECUTE_QUERY_KEY context = possible_context capture_query_start_time(context, &block) when *GRAPHQL_GEM_TRACING_FIELD_KEYS return yield if data[:query].context[SKIP_FIELD_AND_ARGUMENT_METRICS] return yield unless GraphQL::Metrics.timings_capture_enabled?(data[:query].context) context_key = case key when GRAPHQL_GEM_TRACING_FIELD_KEY GraphQL::Metrics::INLINE_FIELD_TIMINGS when GRAPHQL_GEM_TRACING_LAZY_FIELD_KEY GraphQL::Metrics::LAZY_FIELD_TIMINGS end trace_field(context_key, data, &block) else return yield end end |