lib/sequel/extensions/oneapm_instrumentation.rb in oneapm_rpm-1.3.7 vs lib/sequel/extensions/oneapm_instrumentation.rb in oneapm_rpm-1.4.0

- old
+ new

@@ -27,30 +27,33 @@ end return rval end + def generate_metrics(operation, config = {}) + @product ||= database_info(config) + metric_for(@product, operation).compact + end + # Record metrics for the specified +sql+ and +args+ using the specified # +duration+. def record_metrics(sql, args, duration) - primary_metric = primary_metric_for(sql, args) - engine = OneApm::Manager.agent.stats_engine - - metrics = rollup_metrics_for(primary_metric) - metrics << remote_service_metric(*self.opts.values_at(:adapter, :host)) if self.opts.key?(:adapter) - - engine.tl_record_scoped_and_unscoped_metrics(primary_metric, metrics, duration) + operation = operator_metric_for(sql, args) + engine = OneApm::Manager.agent.stats_engine + base, *other_metrics = generate_metrics(operation, self.opts) + engine.tl_record_scoped_and_unscoped_metrics(base, other_metrics, duration) end THREAD_SAFE_CONNECTION_POOL_CLASSES = [ (defined?(::Sequel::ThreadedConnectionPool) && ::Sequel::ThreadedConnectionPool), ].compact.freeze # Record the given +sql+ within a new frame, using the given +start+ and # +finish+ times. def notice_sql(state, sql, args, start, finish) - metric = primary_metric_for(sql, args) + operation = operator_metric_for(sql, args) + base, *other_metrics = generate_metrics(operation, self.opts) agent = OneApm::Manager.agent duration = finish - start stack = state.traced_method_stack begin @@ -62,19 +65,23 @@ OneApm::Manager.logger.log_once(:info, :sequel_explain_skipped, "Not running SQL explains because Sequel is not in recognized multi-threaded mode") nil end end agent.transaction_sampler.notice_sql(sql, self.opts, duration, state, &explainer) - agent.sql_sampler.notice_sql(sql, metric, self.opts, duration, state, &explainer) + agent.sql_sampler.notice_sql(sql, base, self.opts, duration, state, &explainer) ensure stack.pop_frame(state, frame, metric, finish) end end # Derive a primary database metric for the specified +sql+. def primary_metric_for(sql, _) return metric_for_sql(OneApm::Helper.correctly_encoded(sql)) + end + + def operator_metric_for(sql, _) + return operator_for_sql(OneApm::Helper.correctly_encoded(sql)) end end # module OneApmInstrumentation OneApm::Manager.logger.debug "Registering the :oneapm_instrumentation extension."