Documentation
¶
Overview ¶
Package nrredis instruments github.com/redis/go-redis/v9.
Use this package to instrument your redis/go-redis/v9 calls without having to manually create DatastoreSegments.
Example (Client) ¶
package main
import (
"context"
"fmt"
nrredis "github.com/newrelic/go-agent/v3/integrations/nrredis-v9"
newrelic "github.com/newrelic/go-agent/v3/newrelic"
redis "github.com/redis/go-redis/v9"
)
func getTransaction() *newrelic.Transaction { return nil }
func main() {
opts := &redis.Options{Addr: "localhost:6379"}
client := redis.NewClient(opts)
//
// Step 1: Add a nrredis.NewHook() to your redis client.
//
client.AddHook(nrredis.NewHook(opts))
//
// Step 2: Ensure that all client calls contain a context with includes
// the transaction.
//
txn := getTransaction()
ctx := newrelic.NewContext(context.Background(), txn)
pong, err := client.Ping(ctx).Result()
fmt.Println(pong, err)
}
Output:
Example (ClusterClient) ¶
package main
import (
"context"
"fmt"
nrredis "github.com/newrelic/go-agent/v3/integrations/nrredis-v9"
newrelic "github.com/newrelic/go-agent/v3/newrelic"
redis "github.com/redis/go-redis/v9"
)
func getTransaction() *newrelic.Transaction { return nil }
func main() {
client := redis.NewClusterClient(&redis.ClusterOptions{
Addrs: []string{":7000", ":7001", ":7002", ":7003", ":7004", ":7005"},
})
//
// Step 1: Add a nrredis.NewHook() to your redis cluster client.
//
client.AddHook(nrredis.NewHook(nil))
//
// Step 2: Ensure that all client calls contain a context with includes
// the transaction.
//
txn := getTransaction()
ctx := newrelic.NewContext(context.Background(), txn)
pong, err := client.Ping(ctx).Result()
fmt.Println(pong, err)
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigDatastoreKeysEnabled ¶ added in v1.1.0
func ConfigDatastoreKeysEnabled(enabled bool) func(*hook)
ConfigDatastoreKeysEnabled controls whether we report the names of keys along with the datastore operations in our telemetry. Since the keys themselves might contain sensitive information in some databases unlike, say, the general case of a parameterized SQL query with placeholders, this is disabled by default. However, if you know your keys are safe to expose in your telemetry data and wish to see them there, call this method on your hook value with a true parameter.
N.B. for Redis database operations, note that for our purposes what we are referring to here as "keys" are in fact merely the 2nd parameter in the operation parameter list being sent to the Redis server. Typically this will be the key or similar ID for the operation at hand, but this will vary based on the particular operation being performed. Take care to ensure that it is acceptable to record this parameter in your telemetry dataset before enabling this option, or restrict the operations for which you wish to expose this data by also specifying the ConfigLimitOperations option.
If the agent has also enabled raw database queries via the ConfigDatastoreRawQuery option, then the full redis operation will be exposed instead of just the operation and following parameter since that option enables the forwarding of the full database command string and all data.
func ConfigLimitOperations ¶ added in v1.1.0
func ConfigLimitOperations(name ...string) func(*hook)
ConfigLimitOperations restricts the set of operations which will report their keys (assuming ConfigDatastoreKeysEnabled is also given with a true value) to only those operations whose names match those passed to this option.
func NewHook ¶
NewHook creates a redis.Hook to instrument Redis calls. Add it to your client, then ensure that all calls contain a context which includes the transaction. The options are optional. Provide them to get instance metrics broken out by host and port. The hook returned can be used with redis.Client, redis.ClusterClient, and redis.Ring.
Types ¶
This section is empty.