From faabf7942e042bd8b76696d9b08989504f6d8577 Mon Sep 17 00:00:00 2001 From: Jan Graichen Date: Thu, 29 Feb 2024 13:54:04 +0100 Subject: [PATCH] chore!: Upgrade to Ruby 3.1 minimum --- .rubocop.yml | 2 +- lib/mnemosyne/client.rb | 2 +- lib/mnemosyne/global.rb | 8 ++++++-- lib/mnemosyne/instrumenter.rb | 2 +- lib/mnemosyne/middleware/rack.rb | 12 +++++++----- lib/mnemosyne/middleware/sidekiq.rb | 12 +++++++----- lib/mnemosyne/probes/acfs/request.rb | 8 ++++++-- .../probes/action_controller/process_action.rb | 8 ++++++-- .../probes/action_controller/renderers.rb | 9 ++++++--- lib/mnemosyne/probes/action_view/render_partial.rb | 8 ++++++-- .../probes/action_view/render_template.rb | 8 ++++++-- lib/mnemosyne/probes/active_job/perform.rb | 8 ++++++-- .../probes/active_record/instantiation.rb | 8 ++++++-- lib/mnemosyne/probes/active_record/query.rb | 8 ++++++-- lib/mnemosyne/probes/grape/endpoint_render.rb | 7 +++++-- lib/mnemosyne/probes/grape/endpoint_run.rb | 8 ++++++-- lib/mnemosyne/probes/grape/endpoint_run_filters.rb | 7 +++++-- lib/mnemosyne/probes/mnemosyne/tracer.rb | 8 ++++++-- lib/mnemosyne/probes/msgr/client.rb | 2 +- lib/mnemosyne/probes/msgr/consumer.rb | 8 +++++--- lib/mnemosyne/probes/responder/respond.rb | 7 +++++-- lib/mnemosyne/probes/restify/base.rb | 2 +- lib/mnemosyne/probes/sidekiq/client.rb | 2 +- .../probes/view_component/render_component.rb | 8 ++++++-- lib/mnemosyne/span.rb | 10 +++++----- lib/mnemosyne/trace.rb | 14 +++++++------- mnemosyne-ruby.gemspec | 4 ++-- spec/spec_helper.rb | 8 +++----- 28 files changed, 129 insertions(+), 69 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index a48b362..537fa23 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - TargetRubyVersion: 2.7 + TargetRubyVersion: 3.1 Exclude: - 'vendor/**/*' - 'gemfiles/**/*' diff --git a/lib/mnemosyne/client.rb b/lib/mnemosyne/client.rb index d6c9640..a2c9ed8 100644 --- a/lib/mnemosyne/client.rb +++ b/lib/mnemosyne/client.rb @@ -15,7 +15,7 @@ def connection logger.info "[Mnemosyne] Connect to #{@config.server}..." connection = ::Bunny.new @config.amqp, - logger: logger, + logger:, heartbeat: :server connection.start diff --git a/lib/mnemosyne/global.rb b/lib/mnemosyne/global.rb index e7cef7a..8a59052 100644 --- a/lib/mnemosyne/global.rb +++ b/lib/mnemosyne/global.rb @@ -3,8 +3,12 @@ module Mnemosyne module Global def trace(name, meta: {}, &block) - ::ActiveSupport::Notifications.instrument 'trace.mnemosyne', - name: name, meta: meta, &block + ::ActiveSupport::Notifications.instrument( + 'trace.mnemosyne', + name:, + meta:, + &block + ) end def attach_error(err) diff --git a/lib/mnemosyne/instrumenter.rb b/lib/mnemosyne/instrumenter.rb index 6238789..31864eb 100644 --- a/lib/mnemosyne/instrumenter.rb +++ b/lib/mnemosyne/instrumenter.rb @@ -66,7 +66,7 @@ def start!(config = nil) client = Client.new(config) - @instance = new(config: config, client: client) + @instance = new(config:, client:) end rescue StandardError => e ::Mnemosyne::Logging.logger.warn(Mnemosyne) do diff --git a/lib/mnemosyne/middleware/rack.rb b/lib/mnemosyne/middleware/rack.rb index 6cde1c0..ab3b5a3 100644 --- a/lib/mnemosyne/middleware/rack.rb +++ b/lib/mnemosyne/middleware/rack.rb @@ -16,9 +16,9 @@ def respond_to_missing?(*args) @body.respond_to?(*args) end - def method_missing(*args, &block) + def method_missing(*args, &) super if args.first && args.first.to_s == 'to_ary' - @body.__send__(*args, &block) + @body.__send__(*args, &) end def close @@ -64,9 +64,11 @@ def call(env) ::SecureRandom.uuid end - trace = ::Mnemosyne::Instrumenter.trace 'app.web.request.rack', - transaction: transaction, - origin: origin + trace = ::Mnemosyne::Instrumenter.trace( + 'app.web.request.rack', + transaction:, + origin: + ) if trace trace.start! diff --git a/lib/mnemosyne/middleware/sidekiq.rb b/lib/mnemosyne/middleware/sidekiq.rb index 637c9bf..7dcd0aa 100644 --- a/lib/mnemosyne/middleware/sidekiq.rb +++ b/lib/mnemosyne/middleware/sidekiq.rb @@ -9,15 +9,17 @@ def call(worker, job, queue) meta = { raw: job, - queue: queue, + queue:, worker: worker.class.name, arguments: job['args'] } - trace = ::Mnemosyne::Instrumenter.trace 'app.job.perform.sidekiq', - transaction: transaction, - origin: origin, - meta: meta + trace = ::Mnemosyne::Instrumenter.trace( + 'app.job.perform.sidekiq', + transaction:, + origin:, + meta: + ) trace&.start! diff --git a/lib/mnemosyne/probes/acfs/request.rb b/lib/mnemosyne/probes/acfs/request.rb index b58df97..c242b63 100644 --- a/lib/mnemosyne/probes/acfs/request.rb +++ b/lib/mnemosyne/probes/acfs/request.rb @@ -25,8 +25,12 @@ def call(trace, _name, start, finish, _id, _payload) backtrace: callers[1..] } - span = ::Mnemosyne::Span.new 'external.run.acfs', - start: start, finish: finish, meta: meta + span = ::Mnemosyne::Span.new( + 'external.run.acfs', + start:, + finish:, + meta: + ) trace << span end diff --git a/lib/mnemosyne/probes/action_controller/process_action.rb b/lib/mnemosyne/probes/action_controller/process_action.rb index c1d3c91..aa74d95 100644 --- a/lib/mnemosyne/probes/action_controller/process_action.rb +++ b/lib/mnemosyne/probes/action_controller/process_action.rb @@ -17,8 +17,12 @@ def call(trace, _name, start, finish, _id, payload) format: payload[:format] } - span = ::Mnemosyne::Span.new 'app.controller.request.rails', - start: start, finish: finish, meta: meta + span = ::Mnemosyne::Span.new( + 'app.controller.request.rails', + start:, + finish:, + meta: + ) trace << span end diff --git a/lib/mnemosyne/probes/action_controller/renderers.rb b/lib/mnemosyne/probes/action_controller/renderers.rb index 9e33252..fb21de3 100644 --- a/lib/mnemosyne/probes/action_controller/renderers.rb +++ b/lib/mnemosyne/probes/action_controller/renderers.rb @@ -17,15 +17,18 @@ def call(trace, _name, start, finish, _id, _payload) start = ::Mnemosyne::Clock.to_tick(start) finish = ::Mnemosyne::Clock.to_tick(finish) - span = ::Mnemosyne::Span.new 'app.controller.renderers.rails', - start: start, finish: finish + span = ::Mnemosyne::Span.new( + 'app.controller.renderers.rails', + start:, + finish: + ) trace << span end end module Instrumentation - def render_to_body(*args, &block) + def render_to_body(*args, &) ::ActiveSupport::Notifications.instrument CATEGORY do super end diff --git a/lib/mnemosyne/probes/action_view/render_partial.rb b/lib/mnemosyne/probes/action_view/render_partial.rb index 7e9d559..e059ff3 100644 --- a/lib/mnemosyne/probes/action_view/render_partial.rb +++ b/lib/mnemosyne/probes/action_view/render_partial.rb @@ -11,8 +11,12 @@ def call(trace, _name, start, finish, _id, payload) start = ::Mnemosyne::Clock.to_tick(start) finish = ::Mnemosyne::Clock.to_tick(finish) - span = ::Mnemosyne::Span.new 'view.render.template.rails', - start: start, finish: finish, meta: payload + span = ::Mnemosyne::Span.new( + 'view.render.template.rails', + start:, + finish:, + meta: payload + ) trace << span end diff --git a/lib/mnemosyne/probes/action_view/render_template.rb b/lib/mnemosyne/probes/action_view/render_template.rb index 63ecd75..5a90f95 100644 --- a/lib/mnemosyne/probes/action_view/render_template.rb +++ b/lib/mnemosyne/probes/action_view/render_template.rb @@ -11,8 +11,12 @@ def call(trace, _name, start, finish, _id, payload) start = ::Mnemosyne::Clock.to_tick(start) finish = ::Mnemosyne::Clock.to_tick(finish) - span = ::Mnemosyne::Span.new 'view.render.template.rails', - start: start, finish: finish, meta: payload + span = ::Mnemosyne::Span.new( + 'view.render.template.rails', + start:, + finish:, + meta: payload + ) trace << span end diff --git a/lib/mnemosyne/probes/active_job/perform.rb b/lib/mnemosyne/probes/active_job/perform.rb index 87f6a3e..a6ae1bf 100644 --- a/lib/mnemosyne/probes/active_job/perform.rb +++ b/lib/mnemosyne/probes/active_job/perform.rb @@ -20,8 +20,12 @@ def call(trace, _name, start, finish, _id, payload) queue: job.queue_name } - span = ::Mnemosyne::Span.new 'app.job.perform.active_job', - start: start, finish: finish, meta: meta + span = ::Mnemosyne::Span.new( + 'app.job.perform.active_job', + start:, + finish:, + meta: + ) trace << span end diff --git a/lib/mnemosyne/probes/active_record/instantiation.rb b/lib/mnemosyne/probes/active_record/instantiation.rb index 31d608d..6ac8133 100644 --- a/lib/mnemosyne/probes/active_record/instantiation.rb +++ b/lib/mnemosyne/probes/active_record/instantiation.rb @@ -16,8 +16,12 @@ def call(trace, _name, start, finish, _id, payload) class_name: payload[:class_name] } - span = ::Mnemosyne::Span.new 'db.instantiation.active_record', - start: start, finish: finish, meta: meta + span = ::Mnemosyne::Span.new( + 'db.instantiation.active_record', + start:, + finish:, + meta: + ) trace << span end diff --git a/lib/mnemosyne/probes/active_record/query.rb b/lib/mnemosyne/probes/active_record/query.rb index 2c390ec..aee25e4 100644 --- a/lib/mnemosyne/probes/active_record/query.rb +++ b/lib/mnemosyne/probes/active_record/query.rb @@ -18,8 +18,12 @@ def call(trace, _name, start, finish, _id, payload) binds: extract_bind_values(payload) } - span = ::Mnemosyne::Span.new 'db.query.active_record', - start: start, finish: finish, meta: meta + span = ::Mnemosyne::Span.new( + 'db.query.active_record', + start:, + finish:, + meta: + ) trace << span end diff --git a/lib/mnemosyne/probes/grape/endpoint_render.rb b/lib/mnemosyne/probes/grape/endpoint_render.rb index 6682a25..7cf714e 100644 --- a/lib/mnemosyne/probes/grape/endpoint_render.rb +++ b/lib/mnemosyne/probes/grape/endpoint_render.rb @@ -14,8 +14,11 @@ def call(trace, _name, start, finish, _id, payload) endpoint = payload[:endpoint] return unless endpoint - span = ::Mnemosyne::Span.new 'view.render.grape', - start: start, finish: finish + span = ::Mnemosyne::Span.new( + 'view.render.grape', + start:, + finish: + ) trace << span end diff --git a/lib/mnemosyne/probes/grape/endpoint_run.rb b/lib/mnemosyne/probes/grape/endpoint_run.rb index 05f46cc..956d7ee 100644 --- a/lib/mnemosyne/probes/grape/endpoint_run.rb +++ b/lib/mnemosyne/probes/grape/endpoint_run.rb @@ -19,8 +19,12 @@ def call(trace, _name, start, finish, _id, payload) format: extract_format(payload[:env]) } - span = ::Mnemosyne::Span.new 'app.controller.request.grape', - start: start, finish: finish, meta: meta + span = ::Mnemosyne::Span.new( + 'app.controller.request.grape', + start:, + finish:, + meta: + ) trace << span end diff --git a/lib/mnemosyne/probes/grape/endpoint_run_filters.rb b/lib/mnemosyne/probes/grape/endpoint_run_filters.rb index cd4647e..b7f4d84 100644 --- a/lib/mnemosyne/probes/grape/endpoint_run_filters.rb +++ b/lib/mnemosyne/probes/grape/endpoint_run_filters.rb @@ -14,8 +14,11 @@ def call(trace, _name, start, finish, _id, payload) endpoint = payload[:endpoint] return unless endpoint - span = ::Mnemosyne::Span.new 'app.controller.filter.grape', - start: start, finish: finish + span = ::Mnemosyne::Span.new( + 'app.controller.filter.grape', + start:, + finish: + ) trace << span end diff --git a/lib/mnemosyne/probes/mnemosyne/tracer.rb b/lib/mnemosyne/probes/mnemosyne/tracer.rb index 5726293..6051633 100644 --- a/lib/mnemosyne/probes/mnemosyne/tracer.rb +++ b/lib/mnemosyne/probes/mnemosyne/tracer.rb @@ -11,8 +11,12 @@ def call(trace, _name, start, finish, _id, payload) start = ::Mnemosyne::Clock.to_tick(start) finish = ::Mnemosyne::Clock.to_tick(finish) - span = ::Mnemosyne::Span.new 'custom.trace', - start: start, finish: finish, meta: payload + span = ::Mnemosyne::Span.new( + 'custom.trace', + start:, + finish:, + meta: payload + ) trace << span end diff --git a/lib/mnemosyne/probes/msgr/client.rb b/lib/mnemosyne/probes/msgr/client.rb index 698c8de..270f080 100644 --- a/lib/mnemosyne/probes/msgr/client.rb +++ b/lib/mnemosyne/probes/msgr/client.rb @@ -16,7 +16,7 @@ module Instrumentation def publish(payload, options = {}) if (trace = ::Mnemosyne::Instrumenter.current_trace) meta = {} - span = ::Mnemosyne::Span.new(NAME, meta: meta) + span = ::Mnemosyne::Span.new(NAME, meta:) span.start! options[:headers] ||= {} diff --git a/lib/mnemosyne/probes/msgr/consumer.rb b/lib/mnemosyne/probes/msgr/consumer.rb index cfbdb46..fe7b244 100644 --- a/lib/mnemosyne/probes/msgr/consumer.rb +++ b/lib/mnemosyne/probes/msgr/consumer.rb @@ -24,9 +24,11 @@ def dispatch(message) ::SecureRandom.uuid end - trace = ::Mnemosyne::Instrumenter.trace NAME, - transaction: transaction, - origin: origin + trace = ::Mnemosyne::Instrumenter.trace( + NAME, + transaction:, + origin: + ) if trace trace.meta[:properties] = { diff --git a/lib/mnemosyne/probes/responder/respond.rb b/lib/mnemosyne/probes/responder/respond.rb index 1a9e130..aad11e6 100644 --- a/lib/mnemosyne/probes/responder/respond.rb +++ b/lib/mnemosyne/probes/responder/respond.rb @@ -16,8 +16,11 @@ def call(trace, _name, start, finish, _id, _payload) start = ::Mnemosyne::Clock.to_tick(start) finish = ::Mnemosyne::Clock.to_tick(finish) - span = ::Mnemosyne::Span.new 'app.responder.respond', - start: start, finish: finish + span = ::Mnemosyne::Span.new( + 'app.responder.respond', + start:, + finish: + ) trace << span end diff --git a/lib/mnemosyne/probes/restify/base.rb b/lib/mnemosyne/probes/restify/base.rb index d24f2c7..4f60ee2 100644 --- a/lib/mnemosyne/probes/restify/base.rb +++ b/lib/mnemosyne/probes/restify/base.rb @@ -13,7 +13,7 @@ module Instrumentation def call(request) if (trace = ::Mnemosyne::Instrumenter.current_trace) meta = {url: request.uri.to_s, method: request.method} - span = ::Mnemosyne::Span.new 'external.http.restify', meta: meta + span = ::Mnemosyne::Span.new('external.http.restify', meta:) span.start! diff --git a/lib/mnemosyne/probes/sidekiq/client.rb b/lib/mnemosyne/probes/sidekiq/client.rb index 2a60f5e..e9b371f 100644 --- a/lib/mnemosyne/probes/sidekiq/client.rb +++ b/lib/mnemosyne/probes/sidekiq/client.rb @@ -24,7 +24,7 @@ def call(_worker, job, _queue, _redis) raw: job.clone } - span = ::Mnemosyne::Span.new('external.job.sidekiq', meta: meta) + span = ::Mnemosyne::Span.new('external.job.sidekiq', meta:) span.finish! oneshot: true job['mnemosyne.transaction'] = trace.transaction diff --git a/lib/mnemosyne/probes/view_component/render_component.rb b/lib/mnemosyne/probes/view_component/render_component.rb index dec69bd..850ce97 100644 --- a/lib/mnemosyne/probes/view_component/render_component.rb +++ b/lib/mnemosyne/probes/view_component/render_component.rb @@ -11,8 +11,12 @@ def call(trace, _name, start, finish, _id, payload) start = ::Mnemosyne::Clock.to_tick(start) finish = ::Mnemosyne::Clock.to_tick(finish) - span = ::Mnemosyne::Span.new 'view.render.component.view_component', - start: start, finish: finish, meta: payload + span = ::Mnemosyne::Span.new( + 'view.render.component.view_component', + start:, + finish:, + meta: payload + ) trace << span end diff --git a/lib/mnemosyne/span.rb b/lib/mnemosyne/span.rb index 5e4be53..95fdf42 100644 --- a/lib/mnemosyne/span.rb +++ b/lib/mnemosyne/span.rb @@ -37,12 +37,12 @@ def finish!(oneshot: false) def serialize { - uuid: uuid, - name: name, - type: type, - start: start, + uuid:, + name:, + type:, + start:, stop: finish, - meta: meta + meta: } end end diff --git a/lib/mnemosyne/trace.rb b/lib/mnemosyne/trace.rb index bec07fc..7682853 100644 --- a/lib/mnemosyne/trace.rb +++ b/lib/mnemosyne/trace.rb @@ -2,7 +2,7 @@ module Mnemosyne class Trace < Span - BT_REGEXP = /^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$/.freeze + BT_REGEXP = /^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$/ attr_reader :uuid, :transaction, :origin, :span, :errors @@ -46,13 +46,13 @@ def release def serialize { - uuid: uuid, - origin: origin, - transaction: transaction, - name: name, - start: start, + uuid:, + origin:, + transaction:, + name:, + start:, stop: finish, - meta: meta, + meta:, span: @span.map(&:serialize), errors: @errors.map(&:serialize) } diff --git a/mnemosyne-ruby.gemspec b/mnemosyne-ruby.gemspec index 8e50f25..98a7514 100644 --- a/mnemosyne-ruby.gemspec +++ b/mnemosyne-ruby.gemspec @@ -26,7 +26,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) } spec.require_paths = %w[lib] - spec.required_ruby_version = '>= 2.7' - spec.add_runtime_dependency 'activesupport', '>= 4' + spec.required_ruby_version = '>= 3.1' + spec.add_runtime_dependency 'activesupport', '>= 6.1' spec.add_runtime_dependency 'bunny' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d49ee15..bbeb63e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -22,17 +22,15 @@ def version_cmp(version1, comp, version2) end module TracingHelper - def with_instrumentation(**kwargs, &block) + def with_instrumentation(**kwargs, &) traces = [] client = ->(trace) { traces << trace } config = ::Mnemosyne::Configuration.new \ 'application' => kwargs.delete(:application) { 'test' } - instrumenter = ::Mnemosyne::Instrumenter.new \ - config: config, - client: client + instrumenter = ::Mnemosyne::Instrumenter.new(config:, client:) - ::Mnemosyne::Instrumenter.with(instrumenter, &block) + ::Mnemosyne::Instrumenter.with(instrumenter, &) traces.first end