Documentation ¶
Overview ¶
Package gocql provides functions to trace the gocql/gocql package (https://github.com/gocql/gocql).
Example ¶
To trace Cassandra commands, use our query wrapper WrapQuery.
package main import ( "context" "github.com/gocql/gocql" 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 Cassandra session as usual, create a query. cluster := gocql.NewCluster("127.0.0.1") 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 tracedQuery := gocqltrace.WrapQuery(query, gocqltrace.WithServiceName("ServiceName")) tracedQuery.WithContext(ctx) // Execute your query as usual tracedQuery.Exec() }
Output:
Index ¶
- type Iter
- type Query
- func (tq *Query) Exec() error
- func (tq *Query) Iter() *Iter
- func (tq *Query) MapScan(m map[string]interface{}) error
- func (tq *Query) PageState(state []byte) *Query
- func (tq *Query) Scan(dest ...interface{}) error
- func (tq *Query) ScanCAS(dest ...interface{}) (applied bool, err error)
- func (tq *Query) WithContext(ctx context.Context) *Query
- type WrapOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Query ¶ added in v1.0.0
Query inherits from gocql.Query, it keeps the tracer and the context.
func WrapQuery ¶ added in v1.0.0
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.
func (*Query) PageState ¶ added in v1.0.0
PageState rewrites the original function so that spans are aware of the change.
type WrapOption ¶ added in v1.0.0
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 WithResourceName ¶ added in v1.0.0
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 ¶ added in v1.0.0
func WithServiceName(name string) WrapOption
WithServiceName sets the given service name for the returned query.