lib/graphql/metrics/tracer.rb in graphql-metrics-5.0.0 vs lib/graphql/metrics/tracer.rb in graphql-metrics-5.0.1
- old
+ new
@@ -91,26 +91,20 @@
yield
end
def capture_lexing_time
- # GraphQL::Query#result fires `lex` before the `execute_multiplex` event, so sometimes
- # `pre_context.multiplex_start_time_monotonic` isn't set.
- lexing_offset_time = pre_context.multiplex_start_time_monotonic || GraphQL::Metrics.current_time_monotonic
- timed_result = GraphQL::Metrics.time(lexing_offset_time) { yield }
+ timed_result = GraphQL::Metrics.time { yield }
pre_context.lexing_start_time_offset = timed_result.start_time
pre_context.lexing_duration = timed_result.duration
timed_result.result
end
def capture_parsing_time
- # GraphQL::Query#result fires `parse` before the `execute_multiplex` event, so sometimes
- # `pre_context.multiplex_start_time_monotonic` isn't set.
- parsing_offset_time = pre_context.multiplex_start_time_monotonic || GraphQL::Metrics.current_time_monotonic
- timed_result = GraphQL::Metrics.time(parsing_offset_time) { yield }
+ timed_result = GraphQL::Metrics.time { yield }
pre_context.parsing_start_time_offset = timed_result.start_time
pre_context.parsing_duration = timed_result.duration
timed_result.result
@@ -164,20 +158,24 @@
yield
end
def trace_field(context_key, data)
ns = data[:query].context.namespace(CONTEXT_NAMESPACE)
- query_start_time_monotonic = ns[GraphQL::Metrics::QUERY_START_TIME_MONOTONIC]
+ offset_time = ns[GraphQL::Metrics::QUERY_START_TIME_MONOTONIC]
+ start_time = GraphQL::Metrics.current_time_monotonic
- timed_result = GraphQL::Metrics.time(query_start_time_monotonic) { yield }
+ result = yield
+ duration = GraphQL::Metrics.current_time_monotonic - start_time
+ time_since_offset = start_time - offset_time if offset_time
+
path_excluding_numeric_indicies = data[:path].select { |p| p.is_a?(String) }
ns[context_key][path_excluding_numeric_indicies] ||= []
ns[context_key][path_excluding_numeric_indicies] << {
- start_time_offset: timed_result.time_since_offset, duration: timed_result.duration
+ start_time_offset: time_since_offset, duration: duration
}
- timed_result.result
+ result
end
end
end
end