Documentation ¶
Overview ¶
Package otelgocql instruments the github.com/gocql/gocql package.
Index ¶
- Constants
- func CassBatchQueries(num int) attribute.KeyValue
- func CassBatchQueryOperation() attribute.KeyValue
- func CassConnectOperation() attribute.KeyValue
- func CassDBSystem() attribute.KeyValue
- func CassErrMsg(msg string) attribute.KeyValue
- func CassHostID(id string) attribute.KeyValue
- func CassHostState(state string) attribute.KeyValue
- func CassKeyspace(keyspace string) attribute.KeyValue
- func CassPeerIP(ip string) attribute.KeyValue
- func CassPeerName(name string) attribute.KeyValue
- func CassPeerPort(port int) attribute.KeyValue
- func CassQueryAttempts(num int) attribute.KeyValue
- func CassRowsReturned(rows int) attribute.KeyValue
- func CassStatement(stmt string) attribute.KeyValue
- func CassVersion(version string) attribute.KeyValue
- func HostOrIP(hostnameAndPort string) attribute.KeyValue
- func NewSessionWithTracing(ctx context.Context, cluster *gocql.ClusterConfig, options ...Option) (*gocql.Session, error)
- func SemVersion() stringdeprecated
- func Version() string
- type OTelBatchObserver
- type OTelConnectObserver
- type OTelQueryObserver
- type Option
- func WithBatchInstrumentation(enabled bool) Option
- func WithBatchObserver(observer gocql.BatchObserver) Option
- func WithConnectInstrumentation(enabled bool) Option
- func WithConnectObserver(observer gocql.ConnectObserver) Option
- func WithMeterProvider(provider metric.MeterProvider) Option
- func WithQueryInstrumentation(enabled bool) Option
- func WithQueryObserver(observer gocql.QueryObserver) Option
- func WithTracerProvider(provider trace.TracerProvider) Option
Examples ¶
Constants ¶
const ( // CassVersionKey is the key for the attribute/label describing // the cql version. CassVersionKey = attribute.Key("db.cassandra.version") // CassHostIDKey is the key for the attribute/label describing the id // of the host being queried. CassHostIDKey = attribute.Key("db.cassandra.host.id") // CassHostStateKey is the key for the attribute/label describing // the state of the casssandra server hosting the node being queried. CassHostStateKey = attribute.Key("db.cassandra.host.state") // CassBatchQueriesKey is the key for the attribute describing // the number of queries contained within the batch statement. CassBatchQueriesKey = attribute.Key("db.cassandra.batch.queries") // CassErrMsgKey is the key for the attribute/label describing // the error message from an error encountered when executing a query, batch, // or connection attempt to the cassandra server. CassErrMsgKey = attribute.Key("db.cassandra.error.message") // CassRowsReturnedKey is the key for the span attribute describing the number of rows // returned on a query to the database. CassRowsReturnedKey = attribute.Key("db.cassandra.rows.returned") // CassQueryAttemptsKey is the key for the span attribute describing the number of attempts // made for the query in question. CassQueryAttemptsKey = attribute.Key("db.cassandra.attempts") // CassBatchQueryName is the batch operation span name. CassBatchQueryName = "Batch Query" // CassConnectName is the connect operation span name. CassConnectName = "New Connection" // InstrumentationName is the name of the instrumentation package. InstrumentationName = "go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql/otelgocql" )
Variables ¶
This section is empty.
Functions ¶
func CassBatchQueries ¶
CassBatchQueries returns the number of queries in a batch query as a KeyValue pair.
func CassBatchQueryOperation ¶
CassBatchQueryOperation returns the batch query operation as a semconv KeyValue pair (db.operation). This is used in lieu of a db.statement, which is not feasible to include in a span for a batch query because there can be n different query statements in a batch query.
func CassConnectOperation ¶
CassConnectOperation returns the connect operation as a semconv KeyValue pair (db.operation). This is used in lieu of a db.statement since connection creation does not have a CQL statement.
func CassDBSystem ¶
CassDBSystem returns the name of the DB system, cassandra, as a KeyValue pair (db.system).
func CassErrMsg ¶
CassErrMsg returns the KeyValue pair of an error message encountered when executing a query, batch query, or error.
func CassHostID ¶
CassHostID returns the id of the cassandra host as a KeyValue pair.
func CassHostState ¶
CassHostState returns the state of the cassandra host as a KeyValue pair.
func CassKeyspace ¶
CassKeyspace returns the keyspace of the session as a semconv KeyValue pair (db.name).
func CassPeerIP ¶
CassPeerIP returns the IP address of the cassandra server as a semconv KeyValue pair (net.peer.ip).
func CassPeerName ¶
CassPeerName returns the hostname of the cassandra server as a semconv KeyValue pair (net.peer.name).
func CassPeerPort ¶
CassPeerPort returns the port number of the cassandra server as a semconv KeyValue pair (net.peer.port).
func CassQueryAttempts ¶
CassQueryAttempts returns the KeyValue pair of the number of attempts made for a query.
func CassRowsReturned ¶
CassRowsReturned returns the KeyValue pair of the number of rows returned from a query.
func CassStatement ¶
CassStatement returns the statement made to the cassandra database as a semconv KeyValue pair (db.statement).
func CassVersion ¶
CassVersion returns the cql version as a KeyValue pair.
func HostOrIP ¶
HostOrIP returns a KeyValue pair for the hostname retrieved from gocql.HostInfo.HostnameAndPort(). If the hostname is returned as a resolved IP address (as is the case for localhost), then the KeyValue will have the key net.peer.ip. If the hostname is the proper DNS name, then the key will be net.peer.name.
func NewSessionWithTracing ¶
func NewSessionWithTracing( ctx context.Context, cluster *gocql.ClusterConfig, options ...Option, ) (*gocql.Session, error)
NewSessionWithTracing creates a new session using the given cluster configuration enabling tracing for queries, batch queries, and connection attempts. You may use additional observers and disable specific tracing using the provided `TracedSessionOption`s.
Example ¶
// Create a cluster host := "localhost" cluster := gocql.NewCluster(host) // Create a session with tracing _, err := NewSessionWithTracing( context.Background(), cluster, // Include any options here ) if err != nil { log.Fatalf("failed to create session, %v", err) } // Begin using the session
Output:
func SemVersion
deprecated
Types ¶
type OTelBatchObserver ¶
type OTelBatchObserver struct {
// contains filtered or unexported fields
}
OTelBatchObserver implements the gocql.BatchObserver interface to provide instrumentation to gocql batch queries.
func (*OTelBatchObserver) ObserveBatch ¶
func (o *OTelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocql.ObservedBatch)
ObserveBatch is called once per batch query, and provides instrumentation for it.
type OTelConnectObserver ¶
type OTelConnectObserver struct {
// contains filtered or unexported fields
}
OTelConnectObserver implements the gocql.ConnectObserver interface to provide instrumentation to connection attempts made by the session.
func (*OTelConnectObserver) ObserveConnect ¶
func (o *OTelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConnect)
ObserveConnect is called once per connection attempt, and provides instrumentation for it.
type OTelQueryObserver ¶
type OTelQueryObserver struct {
// contains filtered or unexported fields
}
OTelQueryObserver implements the gocql.QueryObserver interface to provide instrumentation to gocql queries.
func (*OTelQueryObserver) ObserveQuery ¶
func (o *OTelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocql.ObservedQuery)
ObserveQuery is called once per query, and provides instrumentation for it.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option applies a configuration option.
func WithBatchInstrumentation ¶
WithBatchInstrumentation will enable and disable insturmentation of batch queries. Defaults to enabled.
func WithBatchObserver ¶
func WithBatchObserver(observer gocql.BatchObserver) Option
WithBatchObserver sets an additional BatchObserver to the session configuration. Use this if there is an existing BatchObserver that you would like called. It will be called after the OpenTelemetry implementation, if it is not nil. Defaults to nil.
func WithConnectInstrumentation ¶
WithConnectInstrumentation will enable and disable instrumentation of connection attempts. Defaults to enabled.
func WithConnectObserver ¶
func WithConnectObserver(observer gocql.ConnectObserver) Option
WithConnectObserver sets an additional ConnectObserver to the session configuration. Use this if there is an existing ConnectObserver that you would like called. It will be called after the OpenTelemetry implementation, if it is not nil. Defaults to nil.
func WithMeterProvider ¶
func WithMeterProvider(provider metric.MeterProvider) Option
WithMeterProvider will set the meter provider used to get a meter for creating instruments. Defaults to global.GetMeterProvider().
func WithQueryInstrumentation ¶
WithQueryInstrumentation will enable and disable instrumentation of queries. Defaults to enabled.
func WithQueryObserver ¶
func WithQueryObserver(observer gocql.QueryObserver) Option
WithQueryObserver sets an additional QueryObserver to the session configuration. Use this if there is an existing QueryObserver that you would like called. It will be called after the OpenTelemetry implementation, if it is not nil. Defaults to nil.
func WithTracerProvider ¶
func WithTracerProvider(provider trace.TracerProvider) Option
WithTracerProvider will set the trace provider used to get a tracer for creating spans. Defaults to TracerProvider().