lib/sentry/redis.rb in sentry-ruby-5.5.0 vs lib/sentry/redis.rb in sentry-ruby-5.6.0

- old
+ new

@@ -1,43 +1,36 @@ # frozen_string_literal: true module Sentry # @api private class Redis - OP_NAME = "db.redis.command" + OP_NAME = "db.redis" LOGGER_NAME = :redis_logger def initialize(commands, host, port, db) @commands, @host, @port, @db = commands, host, port, db end def instrument return yield unless Sentry.initialized? - record_span do + Sentry.with_child_span(op: OP_NAME, start_timestamp: Sentry.utc_now.to_f) do |span| yield.tap do record_breadcrumb + + if span + span.set_description(commands_description) + span.set_data(:server, server_description) + end end end end private attr_reader :commands, :host, :port, :db - def record_span - return yield unless (transaction = Sentry.get_current_scope.get_transaction) && transaction.sampled - - sentry_span = transaction.start_child(op: OP_NAME, start_timestamp: Sentry.utc_now.to_f) - - yield.tap do - sentry_span.set_description(commands_description) - sentry_span.set_data(:server, server_description) - sentry_span.set_timestamp(Sentry.utc_now.to_f) - end - end - def record_breadcrumb return unless Sentry.configuration.breadcrumbs_logger.include?(LOGGER_NAME) Sentry.add_breadcrumb( Sentry::Breadcrumb.new( @@ -59,13 +52,18 @@ end def parsed_commands commands.map do |statement| command, key, *arguments = statement + command_set = { command: command.to_s.upcase, key: key } - { command: command.to_s.upcase, key: key }.tap do |command_set| - command_set[:arguments] = arguments.join(" ") if Sentry.configuration.send_default_pii + if Sentry.configuration.send_default_pii + command_set[:arguments] = arguments + .select { |a| Utils::EncodingHelper.valid_utf_8?(a) } + .join(" ") end + + command_set end end def server_description "#{host}:#{port}/#{db}"