splunkredigo

package module
v1.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

README

Splunk instrumentation for github.com/gomodule/redigo

This package provides OpenTelemetry instrumentation for the github.com/gomodule/redigo module.

Getting Started

This package is designed to instrument an existing redis.Conn so all communication it handles is traced. See example_test.go for more information.

Documentation

Overview

Package splunkredigo provides OpenTelemetry instrumentation for the github.com/gomodule/redigo module.

Example
package main

import (
	"context"
	"time"

	"github.com/gomodule/redigo/redis"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/attribute"

	semconv "go.opentelemetry.io/otel/semconv/v1.17.0"

	"github.com/signalfx/splunk-otel-go/instrumentation/github.com/gomodule/redigo/splunkredigo/option"
	splunkredis "github.com/signalfx/splunk-otel-go/instrumentation/github.com/gomodule/redigo/splunkredigo/redis"
)

func main() {
	// The context used should be propagated from a calling process to ensure
	// trace continuity.
	ctx := context.TODO()

	const db = 15
	// Options passed to Dial* functions can be either redis DialOptions or
	// splunkredigo options.
	conn, err := splunkredis.DialContext(ctx, "tcp", "127.0.0.1:6379",
		redis.DialDatabase(db),
		option.WithAttributes([]attribute.KeyValue{
			attribute.String("tier", "alpha"),
			semconv.DBRedisDBIndexKey.Int(db),
		}),
		redis.DialConnectTimeout(1*time.Minute),
	)
	if err != nil {
		panic(err)
	}

	// Create spans per command by using the Redis connection as usual.
	if _, err := conn.Do("SET", "vehicle", "truck"); err != nil {
		panic(err)
	}

	tracer := otel.Tracer("my-instrumentation.name")
	// Use a context to pass information down the processing chain.
	ctx, root := tracer.Start(ctx, "parent.request")

	// When passed a context as an argument, conn.Do will create a span
	// inheriting from the active span it contains ('parent.request').
	if _, err := conn.Do("SET", "food", "cheese", ctx); err != nil {
		panic(err)
	}
	root.End()
}
Output:

Example (DialURL)
package main

import (
	splunkredis "github.com/signalfx/splunk-otel-go/instrumentation/github.com/gomodule/redigo/splunkredigo/redis"
)

func main() {
	conn, err := splunkredis.DialURL("redis://127.0.0.1:6379/15")
	if err != nil {
		panic(err)
	}
	if _, err := conn.Do("SET", "vehicle", "truck"); err != nil {
		panic(err)
	}
}
Output:

Example (Pool)
package main

import (
	"github.com/gomodule/redigo/redis"

	splunkredis "github.com/signalfx/splunk-otel-go/instrumentation/github.com/gomodule/redigo/splunkredigo/redis"
)

func main() {
	// Set your Dial function when using a redis Pool to trace all Conn.
	pool := &redis.Pool{
		Dial: func() (redis.Conn, error) {
			return splunkredis.Dial("tcp", "127.0.0.1:6379")
		},
	}

	conn := pool.Get()
	if _, err := conn.Do("SET", "vehicle", "truck"); err != nil {
		panic(err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Version

func Version() string

Version returns the version of splunkredigo.

Types

This section is empty.

Directories

Path Synopsis
Package option provides configuration options for the splunkredigo package and its subpackages.
Package option provides configuration options for the splunkredigo package and its subpackages.
Package redis provides tracing functionality for the github.com/gomodule/redigo/redis package.
Package redis provides tracing functionality for the github.com/gomodule/redigo/redis package.
test Module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL