apmtest

package
Version: v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DiscardTracer *apm.Tracer

DiscardTracer is an apm.Tracer that discards all events.

This tracer may be used by multiple tests, and so should not be modified or closed.

Importing apmttest will close apm.DefaultTracer, and update it to this value.

Functions

func NewDiscardTracer added in v1.5.0

func NewDiscardTracer() *apm.Tracer

NewDiscardTracer returns a new apm.Tracer that discards all events.

func WithTransaction

func WithTransaction(f func(ctx context.Context)) (model.Transaction, []model.Span, []model.Error)

WithTransaction is equivalent to calling WithTransactionOptions with a zero TransactionOptions.

func WithTransactionOptions added in v1.1.0

func WithTransactionOptions(opts apm.TransactionOptions, f func(ctx context.Context)) (model.Transaction, []model.Span, []model.Error)

WithTransactionOptions calls f with a new context containing a transaction and transaction options, flushes the transaction to a test server, and returns the decoded transaction and any associated spans and errors.

func WriteTraceTable added in v1.15.0

func WriteTraceTable(writer io.Writer, tx model.Transaction, spans []model.Span)

WriteTraceTable displays the trace as a table which can be used on tests to aid debugging.

func WriteTraceWaterfall added in v1.15.0

func WriteTraceWaterfall(w io.Writer, tx model.Transaction, spans []model.Span)

WriteTraceWaterfall the trace waterfall "console output" to the specified writer sorted by timestamp.

Types

type HTTPTestSuite

type HTTPTestSuite struct {
	suite.Suite

	// Handler holds an instrumented HTTP handler. Handler must
	// support the following routes:
	//
	//   GET /implicit_write (no explicit write on the response)
	//   GET /panic_before_write (panic without writing response)
	//   GET /panic_after_write (panic after writing response)
	//	 POST /explicit_error_capture (explicit CaptureError call)
	//
	Handler http.Handler

	// Tracer is the apm.Tracer used to instrument Handler.
	//
	// HTTPTestSuite will close the tracer when all tests have
	// been completed.
	Tracer *apm.Tracer

	// Recorder is the transport used as the transport for Tracer.
	Recorder *transporttest.RecorderTransport
	// contains filtered or unexported fields
}

HTTPTestSuite is a test suite for HTTP instrumentation modules.

func (*HTTPTestSuite) SetupSuite

func (s *HTTPTestSuite) SetupSuite()

SetupSuite runs before the tests in the suite are run.

func (*HTTPTestSuite) SetupTest

func (s *HTTPTestSuite) SetupTest()

SetupTest runs before each test.

func (*HTTPTestSuite) TearDownSuite

func (s *HTTPTestSuite) TearDownSuite()

TearDownSuite runs after the tests in the suite are run.

func (*HTTPTestSuite) TestExplicitErrorCapture added in v1.12.0

func (s *HTTPTestSuite) TestExplicitErrorCapture()

TestExplicitErrorCapture tests that a CaptureError explicit call inside an HTTP request transaction captures the request body

func (*HTTPTestSuite) TestImplicitWrite

func (s *HTTPTestSuite) TestImplicitWrite()

TestImplicitWrite tests the behaviour of instrumented handlers for routes which do not explicitly write a response, but instead leave it to the framework to write an empty 200 response.

func (*HTTPTestSuite) TestPanicAfterWrite

func (s *HTTPTestSuite) TestPanicAfterWrite()

TestPanicAfterWrite tests the behaviour of instrumented handlers for routes which panic after writing headers. The handler is expected to recover the panic without otherwise affecting the response.

func (*HTTPTestSuite) TestPanicBeforeWrite

func (s *HTTPTestSuite) TestPanicBeforeWrite()

TestPanicBeforeWrite tests the behaviour of instrumented handlers for routes which panic before any headers are written. The handler is expected to recover the panic and write an empty 500 response.

type LogRecord added in v1.5.0

type LogRecord struct {
	// Level is the log level: "debug", "error", or "warning".
	Level string

	// Format is the log message format, like "Thingy did foo %d times".
	Format string

	// Message is the formatted message.
	Message string
}

LogRecord holds the details of a log record.

type LogfLogger

type LogfLogger interface {
	Logf(string, ...interface{})
}

LogfLogger is an interface with the a Logf method, implemented by *testing.T and *testing.B.

type RecordLogger added in v1.5.0

type RecordLogger struct {
	Records []LogRecord
}

RecordLogger is an implementation of apm.Logger, recording log entries.

func (*RecordLogger) Debugf added in v1.5.0

func (l *RecordLogger) Debugf(format string, args ...interface{})

Debugf logs debug messages.

func (*RecordLogger) Errorf added in v1.5.0

func (l *RecordLogger) Errorf(format string, args ...interface{})

Errorf logs error messages.

func (*RecordLogger) Warningf added in v1.5.0

func (l *RecordLogger) Warningf(format string, args ...interface{})

Warningf logs error messages.

type RecordingTracer added in v1.5.0

type RecordingTracer struct {
	*apm.Tracer
	transporttest.RecorderTransport
}

RecordingTracer holds an apm.Tracer and transporttest.RecorderTransport.

func NewRecordingTracer added in v1.5.0

func NewRecordingTracer() *RecordingTracer

NewRecordingTracer returns a new RecordingTracer, containing a new Tracer using the RecorderTransport stored inside.

func (*RecordingTracer) WithTransaction added in v1.5.0

func (rt *RecordingTracer) WithTransaction(f func(ctx context.Context)) (model.Transaction, []model.Span, []model.Error)

WithTransaction calls rt.WithTransactionOptions with a zero apm.TransactionOptions.

func (*RecordingTracer) WithTransactionOptions added in v1.5.0

func (rt *RecordingTracer) WithTransactionOptions(opts apm.TransactionOptions, f func(ctx context.Context)) (model.Transaction, []model.Span, []model.Error)

WithTransactionOptions starts a transaction with the given options, calls f with the transaction in the provided context, ends the transaction and flushes the tracer, and then returns the resulting events.

type TestLogger

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

TestLogger is an implementation of apm.Logger, logging to a testing.T.

func NewTestLogger

func NewTestLogger(l LogfLogger) TestLogger

NewTestLogger returns a new TestLogger that logs messages to l.

func (TestLogger) Debugf

func (t TestLogger) Debugf(format string, args ...interface{})

Debugf logs debug messages.

func (TestLogger) Errorf

func (t TestLogger) Errorf(format string, args ...interface{})

Errorf logs error messages.

type WatchConfigFunc added in v1.5.0

type WatchConfigFunc func(context.Context, apmconfig.WatchParams) <-chan apmconfig.Change

WatchConfigFunc is a function type that implements apmconfig.Watcher.

func (WatchConfigFunc) WatchConfig added in v1.5.0

func (f WatchConfigFunc) WatchConfig(ctx context.Context, params apmconfig.WatchParams) <-chan apmconfig.Change

WatchConfig returns f(ctx, params).

Jump to

Keyboard shortcuts

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