Documentation
¶
Overview ¶
Package nrgocqlx instruments https://github.com/scylladb/gocqlx/
Use this package to instrument your ScyllaDB calls using the gocqlx package.
To instrument your database operations, set the *gocql.ClusterConfig.QueryObserver and/or the *gocql.ClusterConfig.BatchObserver to an instrumented observer. These will be nrgocqlx.NewQueryObserver and nrgocqlx.NewBatchObserver respectively.
After setting the observer, call nrgocqlx.NRGoCQLXWrapSession(cluster). This returns a wrapped *gocqlx.Session which can be used to execute queries. Only ContextBatch and ContextQuery on the wrapped session record database operations; all other *gocqlx.Session methods pass through unchanged.
NOTE: Calls to ContextQuery return a *nrgocqlx.NRGocqlxQueryxWrapper which wraps a *gocqlx.Queryx, and calls to ContextBatch return a *nrgocqlx.NRGocqlxBatchWrapper which wraps a *gocqlx.Batch. Both wrappers allow chaining, but only the methods reimplemented on the wrapper produce segments — chaining off any other method silently drops instrumentation.
For example:
import (
"log"
gocql "github.com/gocql/gocql"
"github.com/newrelic/go-agent/v3/integrations/nrgocqlx"
)
func main() {
cluster := gocql.NewCluster("127.0.0.1")
// Set the New Relic observers
cluster.QueryObserver = nrgocqlx.NewQueryObserver(nil)
cluster.BatchObserver = nrgocqlx.NewBatchObserver(nil)
session, err := nrgocqlx.NRGoCQLXWrapSession(cluster)
if err != nil {
log.Fatal(err)
}
defer session.Close()
// This will record a database operation because BindStruct is implemented by *nrgocqlx.NRGocqlxQueryxWrapper.
insertQuery := session.ContextQuery(ctx, stmt, names).BindStruct(insertStruct)
if err := insertQuery.ExecRelease(); err != nil {
log.Fatal(err)
}
// This will NOT record a database operation because DefaultTimestamp is not implemented by *nrgocqlx.NRGocqlxQueryxWrapper.
_ = session.ContextQuery(ctx, stmt, names).DefaultTimestamp(true)
}
Index ¶
- func NewBatchObserver(original interface{ ... }) *batchObserver
- func NewQueryObserver(original interface{ ... }) *queryObserver
- type NRGocqlxBatchWrapper
- func (b *NRGocqlxBatchWrapper) Bind(qry *NRGocqlxQueryxWrapper, args ...any) error
- func (b *NRGocqlxBatchWrapper) BindMap(qry *NRGocqlxQueryxWrapper, arg map[string]any) error
- func (b *NRGocqlxBatchWrapper) BindStruct(qry *NRGocqlxQueryxWrapper, arg any) error
- func (b *NRGocqlxBatchWrapper) BindStructMap(qry *NRGocqlxQueryxWrapper, arg0 any, arg1 map[string]any) error
- func (b *NRGocqlxBatchWrapper) DefaultTimestamp(enable bool) *NRGocqlxBatchWrapper
- func (b *NRGocqlxBatchWrapper) Exec() error
- func (b *NRGocqlxBatchWrapper) Observer(observer gocql.BatchObserver) *NRGocqlxBatchWrapper
- func (b *NRGocqlxBatchWrapper) Query(stmt string, args ...any) *NRGocqlxBatchWrapper
- func (b *NRGocqlxBatchWrapper) RetryPolicy(policy gocql.RetryPolicy) *NRGocqlxBatchWrapper
- func (b *NRGocqlxBatchWrapper) SerialConsistency(cons gocql.Consistency) *NRGocqlxBatchWrapper
- func (b *NRGocqlxBatchWrapper) SetHostID(hostID string) *NRGocqlxBatchWrapper
- func (b *NRGocqlxBatchWrapper) SetRequestTimeout(timeout time.Duration) *NRGocqlxBatchWrapper
- func (b *NRGocqlxBatchWrapper) SpeculativeExecutionPolicy(policy gocql.SpeculativeExecutionPolicy) *NRGocqlxBatchWrapper
- func (b *NRGocqlxBatchWrapper) Trace(trace gocql.Tracer) *NRGocqlxBatchWrapper
- func (b *NRGocqlxBatchWrapper) WithContext(ctx context.Context) *NRGocqlxBatchWrapper
- func (b *NRGocqlxBatchWrapper) WithTimestamp(timestamp int64) *NRGocqlxBatchWrapper
- type NRGocqlxQueryxWrapper
- func (x *NRGocqlxQueryxWrapper) Bind(v ...any) *NRGocqlxQueryxWrapper
- func (x *NRGocqlxQueryxWrapper) BindMap(arg map[string]any) *NRGocqlxQueryxWrapper
- func (x *NRGocqlxQueryxWrapper) BindStruct(arg any) *NRGocqlxQueryxWrapper
- func (x *NRGocqlxQueryxWrapper) BindStructMap(arg0 any, arg1 map[string]any) *NRGocqlxQueryxWrapper
- func (x *NRGocqlxQueryxWrapper) Exec() error
- func (x *NRGocqlxQueryxWrapper) ExecCAS() (bool, error)
- func (x *NRGocqlxQueryxWrapper) ExecCASRelease() (bool, error)
- func (x *NRGocqlxQueryxWrapper) ExecRelease() error
- func (x *NRGocqlxQueryxWrapper) Get(dest any) error
- func (x *NRGocqlxQueryxWrapper) GetCAS(dest any) (bool, error)
- func (x *NRGocqlxQueryxWrapper) GetCASRelease(dest any) (bool, error)
- func (x *NRGocqlxQueryxWrapper) GetRelease(dest any) error
- func (x *NRGocqlxQueryxWrapper) Scan(v ...any) error
- func (x *NRGocqlxQueryxWrapper) Select(dest any) error
- func (x *NRGocqlxQueryxWrapper) SelectRelease(dest any) error
- type NRGocqlxSessionWrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewBatchObserver ¶
func NewBatchObserver(original interface {
ObserveBatch(ctx context.Context, batch gocql.ObservedBatch)
}) *batchObserver
NewBatchObserver returns a gocql.BatchObserver that creates newrelic.DatastoreSegment for each database batch query. If provided, the original gocql.BatchObserver will be called as well.
func NewQueryObserver ¶
func NewQueryObserver(original interface {
ObserveQuery(ctx context.Context, query gocql.ObservedQuery)
}) *queryObserver
NewQueryObserver returns a gocql.QueryObserver that creates newrelic.DatastoreSegment for each database query. If provided, the original gocql.QueryObserver will be called as well.
Types ¶
type NRGocqlxBatchWrapper ¶
type NRGocqlxBatchWrapper struct {
*gocqlx.Batch
CASSegmentRunner func(fn func() (bool, error)) (bool, error)
// contains filtered or unexported fields
}
Wrapper for gocqlx.Batch that implements gocqlx.Batch functions: Bind, BindMap, BindStruct, BindStructMap, Query, Exec, WithContext, SetRequestTimeout, SetHostID, DefaultTimestamp, WithTimestamp, Observer, RetryPolicy, SerialConsistency, SpeculativeExecutionPolicy and Trace. All other gocqlx.Batch functions are accessible through this struct's embedded field *gocqlx.Batch. NOTE: In order to properly instrument with New Relic, you must use only the implemented functions for NRGocqlxBatchWrapper, especially if you are chaining.
func (*NRGocqlxBatchWrapper) Bind ¶
func (b *NRGocqlxBatchWrapper) Bind(qry *NRGocqlxQueryxWrapper, args ...any) error
Binds query positional parameters to values from args. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to add a statement to the batch. If you use gocqlx.Batch.Bind, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) BindMap ¶
func (b *NRGocqlxBatchWrapper) BindMap(qry *NRGocqlxQueryxWrapper, arg map[string]any) error
Binds query named parameters to values from a map. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to add a statement to the batch. If you use gocqlx.Batch.BindMap, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) BindStruct ¶
func (b *NRGocqlxBatchWrapper) BindStruct(qry *NRGocqlxQueryxWrapper, arg any) error
Binds query named parameters to values from a struct. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to add a statement to the batch. If you use gocqlx.Batch.BindStruct, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) BindStructMap ¶
func (b *NRGocqlxBatchWrapper) BindStructMap(qry *NRGocqlxQueryxWrapper, arg0 any, arg1 map[string]any) error
Binds query named parameters to values from a struct and a map. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to add a statement to the batch. If you use gocqlx.Batch.BindStructMap, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) DefaultTimestamp ¶
func (b *NRGocqlxBatchWrapper) DefaultTimestamp(enable bool) *NRGocqlxBatchWrapper
Enables or disables the default timestamp flag on the batch and returns the wrapper for chaining. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to configure the timestamp behavior. If you use gocqlx.Batch.DefaultTimestamp, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) Exec ¶
func (b *NRGocqlxBatchWrapper) Exec() error
Executes the batch. This function calls execOriginal with a function that calls gocqlx.Batch.Exec with updated context.
func (*NRGocqlxBatchWrapper) Observer ¶
func (b *NRGocqlxBatchWrapper) Observer(observer gocql.BatchObserver) *NRGocqlxBatchWrapper
Sets a batch-level observer and returns the wrapper for chaining. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to attach an observer. If you use gocqlx.Batch.Observer, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) Query ¶
func (b *NRGocqlxBatchWrapper) Query(stmt string, args ...any) *NRGocqlxBatchWrapper
Adds a raw statement with positional arguments to the batch and returns the wrapper for chaining. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to add a statement to the batch. If you use gocqlx.Batch.Query, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) RetryPolicy ¶
func (b *NRGocqlxBatchWrapper) RetryPolicy(policy gocql.RetryPolicy) *NRGocqlxBatchWrapper
Sets the retry policy for the batch and returns the wrapper for chaining. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to configure retries. If you use gocqlx.Batch.RetryPolicy, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) SerialConsistency ¶
func (b *NRGocqlxBatchWrapper) SerialConsistency(cons gocql.Consistency) *NRGocqlxBatchWrapper
Sets the serial consistency level for conditional updates in the batch and returns the wrapper for chaining. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to configure serial consistency. If you use gocqlx.Batch.SerialConsistency, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) SetHostID ¶
func (b *NRGocqlxBatchWrapper) SetHostID(hostID string) *NRGocqlxBatchWrapper
Pins the batch to a specific host by ID and returns the wrapper for chaining. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to set the host. If you use gocqlx.Batch.SetHostID, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) SetRequestTimeout ¶
func (b *NRGocqlxBatchWrapper) SetRequestTimeout(timeout time.Duration) *NRGocqlxBatchWrapper
Sets the time the driver waits for a server response and returns the wrapper for chaining. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to configure the timeout. If you use gocqlx.Batch.SetRequestTimeout, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) SpeculativeExecutionPolicy ¶
func (b *NRGocqlxBatchWrapper) SpeculativeExecutionPolicy(policy gocql.SpeculativeExecutionPolicy) *NRGocqlxBatchWrapper
Sets the speculative execution policy for the batch and returns the wrapper for chaining. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to configure speculative execution. If you use gocqlx.Batch.SpeculativeExecutionPolicy, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) Trace ¶
func (b *NRGocqlxBatchWrapper) Trace(trace gocql.Tracer) *NRGocqlxBatchWrapper
Enables tracing on the batch and returns the wrapper for chaining. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to attach a tracer. If you use gocqlx.Batch.Trace, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) WithContext ¶
func (b *NRGocqlxBatchWrapper) WithContext(ctx context.Context) *NRGocqlxBatchWrapper
Returns a shallow copy of the batch with its context set to ctx and returns the wrapper for chaining. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to set the context. If you use gocqlx.Batch.WithContext, you will not be able to instrument with New Relic.
func (*NRGocqlxBatchWrapper) WithTimestamp ¶
func (b *NRGocqlxBatchWrapper) WithTimestamp(timestamp int64) *NRGocqlxBatchWrapper
Sets an explicit timestamp on the batch and returns the wrapper for chaining. Use this function, which belongs to the wrapper NRGocqlxBatchWrapper, to set the timestamp. If you use gocqlx.Batch.WithTimestamp, you will not be able to instrument with New Relic.
type NRGocqlxQueryxWrapper ¶
type NRGocqlxQueryxWrapper struct {
*gocqlx.Queryx
CASSegmentRunner func(fn func() (bool, error)) (bool, error)
// contains filtered or unexported fields
}
Wrapper for gocqlx.Queryx that implements gocqlx.Queryx functions: Bind, BindMap, BindStruct, BindStructMap, SelectRelease, Select, GetRelease, Get, GetCAS, GetCASRelease, ExecRelease, Exec, ExecCAS, ExecCASRelease and Scan. All other gocqlx.Queryx functions are accessible through this struct's embedded field *gocqlx.Queryx. This wrapper does not implement any gocql.Query functions, however those functions are also accessible through embedded fields. NOTE: In order to properly instrument with New Relic, you must use only the implemented functions for NRGocqlxQueryxWrapper, especially if you are chaining.
func (*NRGocqlxQueryxWrapper) Bind ¶
func (x *NRGocqlxQueryxWrapper) Bind(v ...any) *NRGocqlxQueryxWrapper
Sets the arguments of a query. Use this function, which belongs to the wrapper NRGocqlxQueryxWrapper, to set the arguments and return a NRGocqlxQueryxWrapper. If you use gocqlx.Queryx.Bind, you will not be able to instrument with New Relic.
func (*NRGocqlxQueryxWrapper) BindMap ¶
func (x *NRGocqlxQueryxWrapper) BindMap(arg map[string]any) *NRGocqlxQueryxWrapper
Sets the arguments of a query using a map. Use this function, which belongs to the wrapper NRGocqlxQueryxWrapper, to set the arguments and return a NRGocqlxQueryxWrapper. If you use gocqlx.Queryx.BindMap, you will not be able to instrument with New Relic.
func (*NRGocqlxQueryxWrapper) BindStruct ¶
func (x *NRGocqlxQueryxWrapper) BindStruct(arg any) *NRGocqlxQueryxWrapper
Sets the arguments of a query using a struct. Use this function, which belongs to the wrapper NRGocqlxQueryxWrapper, to set the arguments and return a NRGocqlxQueryxWrapper. If you use gocqlx.Queryx.BindStruct, you will not be able to instrument with New Relic.
func (*NRGocqlxQueryxWrapper) BindStructMap ¶
func (x *NRGocqlxQueryxWrapper) BindStructMap(arg0 any, arg1 map[string]any) *NRGocqlxQueryxWrapper
Sets the arguments of a struct on a map. Use this function, which belongs to the wrapper NRGocqlxQueryxWrapper, to set the arguments and return a NRGocqlxQueryxWrapper. If you use gocqlx.Queryx.BindStructMap, you will not be able to instrument with New Relic.
func (*NRGocqlxQueryxWrapper) Exec ¶
func (x *NRGocqlxQueryxWrapper) Exec() error
Run an Exec query. This function calls execOriginal with a function that calls gocqlx.Queryx.Exec with updated context.
func (*NRGocqlxQueryxWrapper) ExecCAS ¶
func (x *NRGocqlxQueryxWrapper) ExecCAS() (bool, error)
Run an Exec lightweight transaction. This function calls execOriginalCAS with a function that calls gocqlx.Queryx.ExecCAS with updated context.
func (*NRGocqlxQueryxWrapper) ExecCASRelease ¶
func (x *NRGocqlxQueryxWrapper) ExecCASRelease() (bool, error)
Run an Exec lightweight transaction and release it immediately after. Released queries cannot be reused. This function calls execOriginalCAS with a function that calls gocqlx.Queryx.ExecCASRelease with updated context.
func (*NRGocqlxQueryxWrapper) ExecRelease ¶
func (x *NRGocqlxQueryxWrapper) ExecRelease() error
Run an Exec query and release it immediately after. Released queries cannot be reused. This function calls execOriginal with a function that calls gocqlx.Queryx.ExecRelease with updated context.
func (*NRGocqlxQueryxWrapper) Get ¶
func (x *NRGocqlxQueryxWrapper) Get(dest any) error
Run a Get query. This function calls execOriginal with a function that calls gocqlx.Queryx.Get with updated context.
func (*NRGocqlxQueryxWrapper) GetCAS ¶
func (x *NRGocqlxQueryxWrapper) GetCAS(dest any) (bool, error)
Run a Get lightweight transaction. This function calls execOriginalCAS with a function that calls gocqlx.Queryx.GetCAS with updated context.
func (*NRGocqlxQueryxWrapper) GetCASRelease ¶
func (x *NRGocqlxQueryxWrapper) GetCASRelease(dest any) (bool, error)
Run a Get lightweight transaction and release it immediately after. Released queries cannot be reused. This function calls execOriginalCAS with a function that calls gocqlx.Queryx.GetCASRelease with updated context.
func (*NRGocqlxQueryxWrapper) GetRelease ¶
func (x *NRGocqlxQueryxWrapper) GetRelease(dest any) error
Run a Get query and release it immediately after. Released queries cannot be reused. This function calls execOriginal with a function that calls gocqlx.Queryx.Get with updated context.
func (*NRGocqlxQueryxWrapper) Scan ¶
func (x *NRGocqlxQueryxWrapper) Scan(v ...any) error
Run a query and copies the columns of the first selected row into the values pointed at by dest and discards the rest. This function calls execOriginal with a function that calls gocqlx.Queryx.Scan with updated context.
func (*NRGocqlxQueryxWrapper) Select ¶
func (x *NRGocqlxQueryxWrapper) Select(dest any) error
Run a Select query. This function calls execOriginal with a function that calls gocqlx.Queryx.Select with updated context.
func (*NRGocqlxQueryxWrapper) SelectRelease ¶
func (x *NRGocqlxQueryxWrapper) SelectRelease(dest any) error
Run a Select query and release it immediately after. Released queries cannot be reused. This function calls execOriginal with a function that calls gocqlx.Queryx.SelectRelease with updated context.
type NRGocqlxSessionWrapper ¶
Wrapper for gocqlx.Session that implements gocqlx.Session.ContextQuery. All other gocqlx.Session functions are accessible through this struct's embedded field *gocqlx.Session. This wrapper does not implement any gocql.Session functions, however those functions are also accessible through embedded fields. The wrapper's implementation of ContextQuery must be used in order to instrument with New Relic properly.
func NRGoCQLXWrapSession ¶
func NRGoCQLXWrapSession(cluster *gocql.ClusterConfig) (*NRGocqlxSessionWrapper, error)
Call that wraps a gocqlx.Session. This function takes a gocql.ClusterConfig and returns a NRGocqlxSessionWrapper.
func (*NRGocqlxSessionWrapper) ContextBatch ¶
func (s *NRGocqlxSessionWrapper) ContextBatch(ctx context.Context, bt gocql.BatchType) *NRGocqlxBatchWrapper
func (*NRGocqlxSessionWrapper) ContextQuery ¶
func (s *NRGocqlxSessionWrapper) ContextQuery(ctx context.Context, stmt string, names []string) *NRGocqlxQueryxWrapper
Returns a wrapper NRGocqlxQueryxWrapper which contains embedded fields and overridden implementations for gocqlx.Queryx.