Skip to content

Commit

Permalink
chore!: Upgrade to Ruby 3.1 minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraichen committed Feb 29, 2024
1 parent 3b441a8 commit faabf79
Show file tree
Hide file tree
Showing 28 changed files with 129 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AllCops:
TargetRubyVersion: 2.7
TargetRubyVersion: 3.1
Exclude:
- 'vendor/**/*'
- 'gemfiles/**/*'
Expand Down
2 changes: 1 addition & 1 deletion lib/mnemosyne/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/mnemosyne/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/mnemosyne/instrumenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions lib/mnemosyne/middleware/rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down
12 changes: 7 additions & 5 deletions lib/mnemosyne/middleware/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
8 changes: 6 additions & 2 deletions lib/mnemosyne/probes/acfs/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/mnemosyne/probes/action_controller/process_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions lib/mnemosyne/probes/action_controller/renderers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/mnemosyne/probes/action_view/render_partial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/mnemosyne/probes/action_view/render_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/mnemosyne/probes/active_job/perform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/mnemosyne/probes/active_record/instantiation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/mnemosyne/probes/active_record/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/mnemosyne/probes/grape/endpoint_render.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/mnemosyne/probes/grape/endpoint_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/mnemosyne/probes/grape/endpoint_run_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/mnemosyne/probes/mnemosyne/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/mnemosyne/probes/msgr/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] ||= {}
Expand Down
8 changes: 5 additions & 3 deletions lib/mnemosyne/probes/msgr/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
7 changes: 5 additions & 2 deletions lib/mnemosyne/probes/responder/respond.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/mnemosyne/probes/restify/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
2 changes: 1 addition & 1 deletion lib/mnemosyne/probes/sidekiq/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/mnemosyne/probes/view_component/render_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/mnemosyne/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions lib/mnemosyne/trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
Expand Down
Loading

0 comments on commit faabf79

Please sign in to comment.