gocql

package
v1.65.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 13 Imported by: 4

Documentation

Overview

Package gocql provides functions to trace the gocql/gocql package (https://github.com/gocql/gocql).

Example
package main

import (
	"context"

	gocqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gocql/gocql"
	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

func main() {
	// Initialise a wrapped Cassandra session and create a query.
	cluster := gocqltrace.NewCluster([]string{"127.0.0.1"}, gocqltrace.WithServiceName("ServiceName"))
	session, _ := cluster.CreateSession()
	query := session.Query("CREATE KEYSPACE if not exists trace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor': 1}")

	// Use context to pass information down the call chain
	_, ctx := tracer.StartSpanFromContext(context.Background(), "parent.request",
		tracer.SpanType(ext.SpanTypeCassandra),
		tracer.ServiceName("web"),
		tracer.ResourceName("/home"),
	)

	// Wrap the query to trace it and pass the context for inheritance
	query.WithContext(ctx)
	// Provide any options for the specific query.
	query.WithWrapOptions(gocqltrace.WithResourceName("CREATE KEYSPACE"))

	// Execute your query as usual
	query.Exec()
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch added in v1.36.0

type Batch struct {
	*gocql.Batch
	// contains filtered or unexported fields
}

Batch inherits from gocql.Batch, it keeps the tracer and the context.

func WrapBatch deprecated added in v1.36.0

func WrapBatch(b *gocql.Batch, opts ...WrapOption) *Batch

WrapBatch wraps a gocql.Batch into a traced Batch under the given service name. Note that the returned Batch structure embeds the original gocql.Batch structure. This means that any method returning the batch for chaining that is not part of this package's Batch structure should be called before WrapBatch, otherwise the tracing context could be lost.

To be more specific: it is ok (and recommended) to use and chain the return value of `WithContext` and `WithTimestamp` but not that of `SerialConsistency`, `Trace`, `Observer`, etc.

Deprecated: initialize your ClusterConfig with NewCluster instead.

func (*Batch) ExecuteBatch added in v1.36.0

func (tb *Batch) ExecuteBatch(session *gocql.Session) error

ExecuteBatch calls session.ExecuteBatch on the Batch, tracing the execution.

func (*Batch) WithContext added in v1.36.0

func (tb *Batch) WithContext(ctx context.Context) *Batch

WithContext adds the specified context to the traced Batch structure.

func (*Batch) WithTimestamp added in v1.36.0

func (tb *Batch) WithTimestamp(timestamp int64) *Batch

WithTimestamp will enable the with default timestamp flag on the query like DefaultTimestamp does. But also allows to define value for timestamp. It works the same way as USING TIMESTAMP in the query itself, but should not break prepared query optimization.

func (*Batch) WithWrapOptions added in v1.52.0

func (tb *Batch) WithWrapOptions(opts ...WrapOption) *Batch

WithWrapOptions applies the given set of options to the batch.

type ClusterConfig added in v1.52.0

type ClusterConfig struct {
	*gocql.ClusterConfig
	// contains filtered or unexported fields
}

ClusterConfig embeds gocql.ClusterConfig and keeps information relevant to tracing.

func NewCluster added in v1.52.0

func NewCluster(hosts []string, opts ...WrapOption) *ClusterConfig

NewCluster calls gocql.NewCluster and returns a wrapped instrumented version of it.

func (*ClusterConfig) CreateSession added in v1.52.0

func (c *ClusterConfig) CreateSession() (*Session, error)

CreateSession calls the underlying gocql.ClusterConfig's CreateSession method and returns a new Session augmented with tracing.

type Iter

type Iter struct {
	*gocql.Iter
	// contains filtered or unexported fields
}

Iter inherits from gocql.Iter and contains a span.

func (*Iter) Close

func (tIter *Iter) Close() error

Close closes the Iter and finish the span created on Iter call.

func (*Iter) Scanner added in v1.36.0

func (tIter *Iter) Scanner() gocql.Scanner

Scanner returns a row Scanner which provides an interface to scan rows in a manner which is similar to database/sql. The Iter should NOT be used again after calling this method.

type Query

type Query struct {
	*gocql.Query
	// contains filtered or unexported fields
}

Query inherits from gocql.Query, it keeps the tracer and the context.

func WrapQuery deprecated

func WrapQuery(q *gocql.Query, opts ...WrapOption) *Query

WrapQuery wraps a gocql.Query into a traced Query under the given service name. Note that the returned Query structure embeds the original gocql.Query structure. This means that any method returning the query for chaining that is not part of this package's Query structure should be called before WrapQuery, otherwise the tracing context could be lost.

To be more specific: it is ok (and recommended) to use and chain the return value of `WithContext` and `PageState` but not that of `Consistency`, `Trace`, `Observer`, etc.

Deprecated: initialize your ClusterConfig with NewCluster instead.

func (*Query) Exec

func (tq *Query) Exec() error

Exec is rewritten so that it passes by our custom Iter

func (*Query) Iter

func (tq *Query) Iter() *Iter

Iter starts a new span at query.Iter call.

func (*Query) MapScan

func (tq *Query) MapScan(m map[string]interface{}) error

MapScan wraps in a span query.MapScan call.

func (*Query) PageState

func (tq *Query) PageState(state []byte) *Query

PageState rewrites the original function so that spans are aware of the change.

func (*Query) Scan

func (tq *Query) Scan(dest ...interface{}) error

Scan wraps in a span query.Scan call.

func (*Query) ScanCAS

func (tq *Query) ScanCAS(dest ...interface{}) (applied bool, err error)

ScanCAS wraps in a span query.ScanCAS call.

func (*Query) WithContext

func (tq *Query) WithContext(ctx context.Context) *Query

WithContext adds the specified context to the traced Query structure.

func (*Query) WithWrapOptions added in v1.52.0

func (tq *Query) WithWrapOptions(opts ...WrapOption) *Query

WithWrapOptions applies the given set of options to the query.

type Scanner added in v1.36.0

type Scanner struct {
	gocql.Scanner
	// contains filtered or unexported fields
}

Scanner inherits from a gocql.Scanner derived from an Iter

func (*Scanner) Err added in v1.36.0

func (s *Scanner) Err() error

Err calls the wrapped Scanner.Err, releasing the Scanner resources and closing the span.

type Session added in v1.52.0

type Session struct {
	*gocql.Session
	// contains filtered or unexported fields
}

Session embeds gocql.Session and keeps information relevant to tracing.

func (*Session) NewBatch added in v1.52.0

func (s *Session) NewBatch(typ gocql.BatchType) *Batch

NewBatch calls the underlying gocql.Session's NewBatch method and returns a new Batch augmented with tracing.

func (*Session) Query added in v1.52.0

func (s *Session) Query(stmt string, values ...interface{}) *Query

Query calls the underlying gocql.Session's Query method and returns a new Query augmented with tracing.

type WrapOption

type WrapOption func(*queryConfig)

WrapOption represents an option that can be passed to WrapQuery.

func NoDebugStack added in v1.12.0

func NoDebugStack() WrapOption

NoDebugStack prevents stack traces from being attached to spans finishing with an error. This is useful in situations where errors are frequent and performance is critical.

func WithAnalytics added in v1.11.0

func WithAnalytics(on bool) WrapOption

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate added in v1.11.0

func WithAnalyticsRate(rate float64) WrapOption

WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.

func WithCustomTag added in v1.53.0

func WithCustomTag(key string, value interface{}) WrapOption

WithCustomTag will attach the value to the span tagged by the key.

func WithErrorCheck added in v1.40.0

func WithErrorCheck(fn func(err error) bool) WrapOption

WithErrorCheck specifies a function fn which determines whether the passed error should be marked as an error. The fn is called whenever a CQL request finishes with an error.

func WithResourceName

func WithResourceName(name string) WrapOption

WithResourceName sets a custom resource name to be used with the traced query. By default, the query statement is extracted automatically. This method should be used when a different resource name is desired or in performance critical environments. The gocql library returns the query statement using an fmt.Sprintf call, which can be costly when called repeatedly. Using WithResourceName will avoid that call. Under normal circumstances, it is safe to rely on the default.

func WithServiceName

func WithServiceName(name string) WrapOption

WithServiceName sets the given service name for the returned query.

Jump to

Keyboard shortcuts

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