gocql

package module
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2020 License: Apache-2.0 Imports: 11 Imported by: 1

README

go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql

This package provides tracing and metrics to the golang cassandra client github.com/gocql/gocql using the ConnectObserver, QueryObserver and BatchObserver interfaces.

To enable tracing in your application:

package main

import (
	"context"

	"github.com/gocql/gocql"
	otelGocql "go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql"
)

func main() {
	// Create a cluster
	host := "localhost"
	cluster := gocql.NewCluster(host)

	// Create a session with tracing
	session, err := otelGocql.NewSessionWithTracing(
		context.Background(),
		cluster,
		// Include any options here
	)

	// Begin using the session

}

You can customize instrumentation by passing any of the following options to NewSessionWithTracing:

Function Description
WithQueryObserver(gocql.QueryObserver) Specify an additional QueryObserver to be called.
WithBatchObserver(gocql.BatchObserver) Specify an additional BatchObserver to be called.
WithConnectObserver(gocql.ConnectObserver) Specify an additional ConnectObserver to be called.
WithTracer(trace.Tracer) The tracer to be used to create spans for the gocql session. If not specified, global.Tracer("go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql") will be used.
WithQueryInstrumentation(bool) To enable/disable tracing and metrics for queries.
WithBatchInstrumentation(bool) To enable/disable tracing and metrics for batch queries.
WithConnectInstrumentation(bool) To enable/disable tracing and metrics for new connections.

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstrumentWithProvider

func InstrumentWithProvider(p metric.Provider)

InstrumentWithProvider will recreate instruments using a meter from the given provider p.

func NewSessionWithTracing

func NewSessionWithTracing(ctx context.Context, cluster *gocql.ClusterConfig, options ...TracedSessionOption) (*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.

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 TracedSessionConfig

type TracedSessionConfig struct {
	// contains filtered or unexported fields
}

TracedSessionConfig provides configuration for sessions created with NewSessionWithTracing.

type TracedSessionOption

type TracedSessionOption interface {
	Apply(*TracedSessionConfig)
}

TracedSessionOption applies a configuration option to the given TracedSessionConfig.

func WithBatchInstrumentation

func WithBatchInstrumentation(enabled bool) TracedSessionOption

WithBatchInstrumentation will enable and disable insturmentation of batch queries. Defaults to enabled.

func WithBatchObserver

func WithBatchObserver(observer gocql.BatchObserver) TracedSessionOption

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

func WithConnectInstrumentation(enabled bool) TracedSessionOption

WithConnectInstrumentation will enable and disable instrumentation of connection attempts. Defaults to enabled.

func WithConnectObserver

func WithConnectObserver(observer gocql.ConnectObserver) TracedSessionOption

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 WithQueryInstrumentation

func WithQueryInstrumentation(enabled bool) TracedSessionOption

WithQueryInstrumentation will enable and disable instrumentation of queries. Defaults to enabled.

func WithQueryObserver

func WithQueryObserver(observer gocql.QueryObserver) TracedSessionOption

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 WithTracer

func WithTracer(tracer trace.Tracer) TracedSessionOption

WithTracer will set tracer to be the tracer used to create spans for query, batch query, and connection instrumentation. Defaults to global.Tracer("go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql").

type TracedSessionOptionFunc

type TracedSessionOptionFunc func(*TracedSessionConfig)

TracedSessionOptionFunc is a function type that applies a particular configuration to the traced session in question.

func (TracedSessionOptionFunc) Apply

Apply will apply the TracedSessionOptionFunc to c, the given TracedSessionConfig.

Directories

Path Synopsis
example module
otelgocql module
example Module
test Module

Jump to

Keyboard shortcuts

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