Skip to content

Redis tracing #1693

@lewispb

Description

@lewispb

Describe the idea

Similar to the existing Sentry Performance support for Active Record database tracing, we've found it useful to view the time taken to execute Redis commands.

I've created a simple custom Redis instrumenter and tracing subscriber. With this enabled, we can inspect traces including Redis commands:

sentry-performance-with-redis

Why do you think it's beneficial to most of the users

Redis is a popular and widely-used database.

Possible implementation

We would add the following to the "sentry-rails" gem:

I considered a new gem "sentry-redis", but it appears that the Performance product with tracing is only available for Rails apps.

Instrumentation example

class Redis
  module Instrumentation
    def logging(commands, &block)
      ActiveSupport::Notifications.instrument("command.redis", commands: commands, server: "#{host}:#{port}/#{db}") do
        return super(commands, &block)
      end
    end
  end
end

Redis::Client.prepend(Redis::Instrumentation)

Subscriber example

The first command and key is instrumented, but not the value.

require "sentry/rails/tracing/abstract_subscriber"

module Sentry
  module Rails
    module Tracing
      class RedisSubscriber < AbstractSubscriber
        def self.subscribe!
          subscribe_to_event([ "command.redis" ]) do |event_name, duration, payload|
            description = payload.dig(:commands, 0).take(2).join(" ")

            record_on_current_span(
              op: event_name,
              start_timestamp: payload[START_TIMESTAMP_NAME],
              description: description,
              duration: duration
            ) do |span|
              span.set_data(:redis_server, payload[:server])
            end
          end
        end
      end
    end
  end
end

I'm happy to implement this if the approach is acceptable. Thanks!

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions