tracing

package module
v0.0.0-...-6f9744f Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: Apache-2.0 Imports: 16 Imported by: 4

README

go-tracing

go-tracing is a lightweight, simple, easy-to-use request tracing library. You can use it to see what parts of your system take a long time, and which parts are quicker. There are more complex implementations of a tracer that can export to different services, etc, but this one aims to be straightforward and not require any other service setup, and run on your computer.

It consists of 2 parts:

  • The tracing package at github.com/jamesrr39/go-tracing. You call this part in your application. This then writes the traces to a file (or other writer). It uses the streamtostorage format, more info here: Code | GoDoc.
  • The tracingviz/tracingviz-main.go application. This reads the file, and converts it into an html file. This html file can then be opened and you can see all of your traces. This file is designed to be portable, so you can copy it between computers.

Tracing using the tracing package relies heavily on the context, so you must have added the tracer and that specific trace to the context. The provided Middleware function will do that for you, if you want to use it for an HTTP server. If you want to use it for something, you can look at the Middleware function and adapt it for what you want.

Installation

# get the library to instrument your code
go get github.com/jamesrr39/go-tracing

# install the program to generate HTML visualisations of the trace outputs
go get github.com/jamesrr39/go-tracing/tracingviz

To run the example:

  • go run example/example_http_server.go (this will print out the location of the newly-creating tracer file)
  • go run tracingviz/tracingviz-main.go <path-to-tracer-file> <desired-html-output-file-path> (or tracingviz <path-to-tracer-file> <desired-html-output-file-path> if you used installed tracingviz with go get/go install)
  • open <desired-html-output-file-path> with a modern web browser.

What you should see: Selection_097

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TraceCtxKey  key = 1
	TracerCtxKey key = 2
)
View Source
var (
	ErrInvalidLengthTracing        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowTracing          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupTracing = fmt.Errorf("proto: unexpected end of group")
)

Functions

func Middleware

func Middleware(tracer *Tracer) func(http.Handler) http.Handler

Types

type Span

type Span struct {
	Name           string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	StartTimeNanos int64  `protobuf:"varint,2,opt,name=start_time_nanos,json=startTimeNanos,proto3" json:"startTimeNanos"`
	EndTimeNanos   int64  `protobuf:"varint,3,opt,name=end_time_nanos,json=endTimeNanos,proto3" json:"endTimeNanos"`
}

func StartSpan

func StartSpan(ctx context.Context, name string) *Span

func (*Span) Descriptor

func (*Span) Descriptor() ([]byte, []int)

func (*Span) End

func (span *Span) End(ctx context.Context)

func (*Span) Equal

func (this *Span) Equal(that interface{}) bool

func (*Span) GetEndTimeNanos

func (m *Span) GetEndTimeNanos() int64

func (*Span) GetName

func (m *Span) GetName() string

func (*Span) GetStartTimeNanos

func (m *Span) GetStartTimeNanos() int64

func (*Span) GoString

func (this *Span) GoString() string

func (*Span) Marshal

func (m *Span) Marshal() (dAtA []byte, err error)

func (*Span) MarshalTo

func (m *Span) MarshalTo(dAtA []byte) (int, error)

func (*Span) MarshalToSizedBuffer

func (m *Span) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Span) ProtoMessage

func (*Span) ProtoMessage()

func (*Span) Reset

func (m *Span) Reset()

func (*Span) Size

func (m *Span) Size() (n int)

func (*Span) String

func (this *Span) String() string

func (*Span) Unmarshal

func (m *Span) Unmarshal(dAtA []byte) error

func (*Span) XXX_DiscardUnknown

func (m *Span) XXX_DiscardUnknown()

func (*Span) XXX_Marshal

func (m *Span) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Span) XXX_Merge

func (m *Span) XXX_Merge(src proto.Message)

func (*Span) XXX_Size

func (m *Span) XXX_Size() int

func (*Span) XXX_Unmarshal

func (m *Span) XXX_Unmarshal(b []byte) error

type Trace

type Trace struct {
	Name           string  `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Summary        string  `protobuf:"bytes,2,opt,name=summary,proto3" json:"summary,omitempty"`
	StartTimeNanos int64   `protobuf:"varint,3,opt,name=start_time_nanos,json=startTimeNanos,proto3" json:"startTimeNanos"`
	EndTimeNanos   int64   `protobuf:"varint,4,opt,name=end_time_nanos,json=endTimeNanos,proto3" json:"endTimeNanos"`
	Spans          []*Span `protobuf:"bytes,5,rep,name=spans,proto3" json:"spans,omitempty"`
}

func StartTrace

func StartTrace(tracer *Tracer, name string) *Trace

func (*Trace) Descriptor

func (*Trace) Descriptor() ([]byte, []int)

func (*Trace) Equal

func (this *Trace) Equal(that interface{}) bool

func (*Trace) GetEndTimeNanos

func (m *Trace) GetEndTimeNanos() int64

func (*Trace) GetName

func (m *Trace) GetName() string

func (*Trace) GetSpans

func (m *Trace) GetSpans() []*Span

func (*Trace) GetStartTimeNanos

func (m *Trace) GetStartTimeNanos() int64

func (*Trace) GetSummary

func (m *Trace) GetSummary() string

func (*Trace) GoString

func (this *Trace) GoString() string

func (*Trace) Marshal

func (m *Trace) Marshal() (dAtA []byte, err error)

func (*Trace) MarshalTo

func (m *Trace) MarshalTo(dAtA []byte) (int, error)

func (*Trace) MarshalToSizedBuffer

func (m *Trace) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Trace) ProtoMessage

func (*Trace) ProtoMessage()

func (*Trace) Reset

func (m *Trace) Reset()

func (*Trace) Size

func (m *Trace) Size() (n int)

func (*Trace) String

func (this *Trace) String() string

func (*Trace) Unmarshal

func (m *Trace) Unmarshal(dAtA []byte) error

func (*Trace) XXX_DiscardUnknown

func (m *Trace) XXX_DiscardUnknown()

func (*Trace) XXX_Marshal

func (m *Trace) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Trace) XXX_Merge

func (m *Trace) XXX_Merge(src proto.Message)

func (*Trace) XXX_Size

func (m *Trace) XXX_Size() int

func (*Trace) XXX_Unmarshal

func (m *Trace) XXX_Unmarshal(b []byte) error

type Tracer

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

func NewTracer

func NewTracer(writer io.Writer) *Tracer

func (*Tracer) EndTrace

func (tracer *Tracer) EndTrace(trace *Trace, summary string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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