trace

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

type Hook struct {
	*Options

	Tracer trace.Tracer
}

func New

func New(options ...Option) *Hook

func (*Hook) After

func (h *Hook) After(ctx context.Context, evt *otsql.Event)

func (*Hook) Before

func (hook *Hook) Before(ctx context.Context, evt *otsql.Event) context.Context

type Option

type Option func(*Options)

Option allows for managing trace configuration using functional options.

func WithAllowRoot

func WithAllowRoot(b bool) Option

WithAllowRoot if set to true, will allow hook to create root spans in absence of exisiting spans or even context. Default is to not trace sql calls if no existing parent span is found in context or when using methods not taking context.

func WithDefaultAttributes

func WithDefaultAttributes(attrs ...attribute.KeyValue) Option

WithDefaultAttributes will be set to each span as default.

func WithInstanceName

func WithInstanceName(instanceName string) Option

WithInstanceName sets database instance name.

func WithLastInsertId

func WithLastInsertId(b bool) Option

WithLastInsertID if set to true, will enable the creation of spans on LastInsertId calls.

func WithOptions

func WithOptions(options Options) Option

WithOptions sets our hook tracing middleware options through a single Options object.

func WithPing

func WithPing(b bool) Option

WithPing if set to true, will enable the creation of spans on Ping requests.

func WithQuery

func WithQuery(b bool) Option

WithQuery if set to true, will enable recording of sql queries in spans. Only allow this if it is safe to have queries recorded with respect to security.

func WithQueryParams

func WithQueryParams(b bool) Option

WithQueryParams if set to true, will enable recording of parameters used with parametrized queries. Only allow this if it is safe to have parameters recorded with respect to security. This setting is a noop if the Query option is set to false.

func WithResetRession

func WithResetRession(b bool) Option

WithResetSession if seto to true, will enable the creation of spans on ResetSession calls.

func WithRowsAffected

func WithRowsAffected(b bool) Option

WithRowsAffected if set to true, will enable the creation of spans on RowsAffected calls.

func WithRowsClose

func WithRowsClose(b bool) Option

WithRowsClose if set to true, will enable the creation of spans on RowsClose calls.

func WithRowsNext

func WithRowsNext(b bool) Option

WithRowsNext if set to true, will enable the creation of spans on RowsNext calls. This can result in many spans.

func WithSpanNameFormatter

func WithSpanNameFormatter(formatter func(context.Context, string, string) string) Option

WithSpanNameFormatter sets name for each span.

type Options

type Options struct {
	// AllowRoot, if set to true, will allow hook to create root spans in
	// absence of existing spans or even context.
	// Default is to not trace calls if no existing parent span is found
	// in context or when using methods not taking context.
	AllowRoot bool

	// Query, if set to true, will enable recording of sql queries in spans.
	// Only allow this if it is safe to have queries recorded with respect to
	// security.
	Query bool

	// QueryParams, if set to true, will enable recording of parameters used
	// with parametrized queries. Only allow this if it is safe to have
	// parameters recorded with respect to security.
	// This setting is a noop if the Query option is set to false.
	QueryParams bool

	// Ping, if set to true, will enable the creation of spans on Ping requests.
	Ping bool

	// RowsAffected, if set to true, will enable the creation of spans on
	// RowsAffected calls.
	RowsAffected bool

	// LastInsertId, if set to true, will enable the creation of spans on
	// LastInsertId calls.
	LastInsertId bool

	// RowsNext, if set to true, will enable the creation of spans on RowsNext
	// calls. This can result in many spans.
	RowsNext bool

	// RowsClose, if set to true, will enable the creation of spans on RowsClose
	// calls.
	RowsClose bool

	// ResetSession, if set to true, will enable the creation of spans on ResetSession
	// calls
	ResetSession bool

	// SpanNameFormatter will be called to produce span's name.
	// Default use method as span name
	SpanNameFormatter func(ctx context.Context, method string, query string) string

	// DefaultAttributes will be set to each span as default.
	DefaultAttributes []attribute.KeyValue

	// InstanceName identifies database.
	InstanceName string
}

Options holds configuration of our tracing hook. By default all options are set to false intentionally when creating a wrapped driver and provide the most sensible default with both performance and security in mind.

Jump to

Keyboard shortcuts

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