-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split out Instrumentation from Extractor #6
Conversation
extract!
Updated to extract a new boolean via Also introduces a |
tldr: We / other clients can use this to conditionally log, or log differently unused variables. |
(Note to self: Wrap the clock_gettime calls within the gem within something like GraphQLMetrics::TimedBatchExecutor.current_time, so that we can stub that, instead of the stdlib method, with edit: Done. |
@swalkinshaw @eapache At your earliest convenience, please see the latest 2 commits (perhaps start with the changes to README.md in the first commit). This introduces a breaking change (the meaning of -class LoggingExtractor < GraphQLMetrics::Extractor
+class LoggingExtractor < GraphQLMetrics::Instrumentation |
rename to extract!
f9adaee
to
1f474b5
Compare
Thanks! Updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome 🎉
extract!
@swalkinshaw Here's where I settled on the instrumentor/start/end time checks in start_time, end_time = if instrumentor
start_time = instrumentor.ctx_namespace[Instrumentation::START_TIME_KEY]
return unless start_time
[start_time, Instrumentation.current_time]
end |
lib/graphql_metrics/extractor.rb
Outdated
return unless irep_node.definition | ||
|
||
field_extracted( | ||
resolver_times = if instrumentor | ||
instrumentor.ctx_namespace.dig(Instrumentation::TIMING_CACHE_KEY, irep_node.ast_node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be cleaner to move logic like this into a method on the instrumentor, and then define a dummy instrumentor class to use instead of nil?
3cd68f3
to
405df32
Compare
ns[START_TIME_KEY] = Process.clock_gettime(Process::CLOCK_MONOTONIC) | ||
rescue StandardError => ex | ||
handle_extraction_exception(ex) | ||
def instrumentor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is here since I'd rather default again at runtime if an extractor calls instrumentor
, and the extractor overrode initialize
but didn't call super
.
Wrap Process.clock_gettime for easier stubbing pr feedback Update lib/graphql_metrics/extractor.rb Co-Authored-By: chrisbutcher <chrisbutcher@users.noreply.github.com> Refactor of start_time, end_time logic in extract_query Rename used_in_query to more accurate used_in_operation
66d4e26
to
ddedc08
Compare
Introduces a new public method,
GraphQLMetrics::Extractor#extract!
, which takes in aGraphQL::Query
and permits stateful extractors to be created that aren't used as instrumentation. See the test case below for an idea of its usage.Only
field_extracted
,initialize
and anattr_reader
to pull out stored values is needed, but I implemented no-ops for the rest of the Extractor interface to ensure we detect breakage in those due to this or future changes.