Documentation ¶
Overview ¶
Package mocktracer provides a mock implementation of the tracer used in testing. It allows querying spans generated at runtime, without having them actually be sent to an agent. It provides a simple way to test that instrumentation is running correctly in your application.
Simply call "Start" at the beginning of your tests to start and obtain an instance of the mock tracer.
Example ¶
package main import ( "github.com/signalfx/signalfx-go-tracing/ddtrace/mocktracer" ) func main() { // Start the mock tracer. mt := mocktracer.Start() defer mt.Stop() // ...run some code with generates spans. // Query the mock tracer for finished spans. spans := mt.FinishedSpans() if len(spans) != 1 { // should only have 1 span } // Run assertions... }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Span ¶
type Span interface { // SpanID returns the span's ID. SpanID() uint64 // TraceID returns the span's trace ID. TraceID() uint64 // ParentID returns the span's parent ID. ParentID() uint64 // StartTime returns the time when the span has started. StartTime() time.Time // FinishTime returns the time when the span has finished. FinishTime() time.Time // OperationName returns the operation name held by this span. OperationName() string // Tag returns the value of the tag at key k. Tag(k string) interface{} // Tags returns a copy of all the tags in this span. Tags() map[string]interface{} // Context returns the span's SpanContext. Context() ddtrace.SpanContext // Stringer allows pretty-printing the span's fields for debugging. fmt.Stringer }
Span is an interface that allows querying a span returned by the mock tracer.
type Tracer ¶
type Tracer interface { // FinishedSpans returns the set of finished spans. FinishedSpans() []Span // Reset resets the spans and services recorded in the tracer. This is // especially useful when running tests in a loop, where a clean start // is desired for FinishedSpans calls. Reset() // Stop deactivates the mock tracer and allows a normal tracer to take over. // It should always be called when testing has finished. Stop() }
Tracer exposes an interface for querying the currently running mock tracer.
Click to show internal directories.
Click to hide internal directories.