package trace

Import Path
	go.opencensus.io/trace (on go.dev)

Dependency Relation
	imports 13 packages, and imported by 15 packages

Involved Source Files basetypes.go config.go Package trace contains support for OpenCensus distributed tracing. The following assumes a basic familiarity with OpenCensus concepts. See http://opencensus.io Exporting Traces To export collected tracing data, register at least one exporter. You can use one of the provided exporters or write your own. trace.RegisterExporter(exporter) By default, traces will be sampled relatively rarely. To change the sampling frequency for your entire program, call ApplyConfig. Use a ProbabilitySampler to sample a subset of traces, or use AlwaysSample to collect a trace on every run: trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}) Be careful about using trace.AlwaysSample in a production application with significant traffic: a new trace will be started and exported for every request. Adding Spans to a Trace A trace consists of a tree of spans. In Go, the current span is carried in a context.Context. It is common to want to capture all the activity of a function call in a span. For this to work, the function must take a context.Context as a parameter. Add these two lines to the top of the function: ctx, span := trace.StartSpan(ctx, "example.com/Run") defer span.End() StartSpan will create a new top-level span if the context doesn't contain another span, otherwise it will create a child span. evictedqueue.go export.go lrumap.go sampling.go spanbucket.go spanstore.go status_codes.go trace.go trace_go11.go
Package-Level Type Names (total 28, in which 20 are exported)
/* sort exporteds by: | */
Annotation represents a text annotation with a set of attributes and a timestamp. Attributes map[string]interface{} Message string Time time.Time
Attribute represents a key-value pair on a span, link or annotation. Construct with one of: BoolAttribute, Int64Attribute, or StringAttribute. func BoolAttribute(key string, value bool) Attribute func Float64Attribute(key string, value float64) Attribute func Int64Attribute(key string, value int64) Attribute func StringAttribute(key string, value string) Attribute func (*Span).AddAttributes(attributes ...Attribute) func (*Span).Annotate(attributes []Attribute, str string) func (*Span).Annotatef(attributes []Attribute, format string, a ...interface{}) func contrib.go.opencensus.io/integrations/ocsql.WithDefaultAttributes(attrs ...Attribute) ocsql.TraceOption
Config represents the global tracing configuration. DefaultSampler is the default sampler used when creating new spans. IDGenerator is for internal use only. MaxAnnotationEventsPerSpan is max number of annotation events per span MaxAnnotationEventsPerSpan is max number of attributes per span MaxLinksPerSpan is max number of links per span MaxMessageEventsPerSpan is max number of message events per span func ApplyConfig(cfg Config)
Exporter is a type for functions that receive sampled trace spans. The ExportSpan method should be safe for concurrent use and should return quickly; if an Exporter takes a significant amount of time to process a SpanData, that work should be done on another goroutine. The SpanData should not be modified, but a pointer to it can be kept. ( T) ExportSpan(s *SpanData) *contrib.go.opencensus.io/exporter/stackdriver.Exporter func RegisterExporter(e Exporter) func UnregisterExporter(e Exporter)
LinkType specifies the relationship between the span that had the link added, and the linked span. const LinkTypeChild const LinkTypeParent const LinkTypeUnspecified
MessageEvent represents an event describing a message sent or received on the network. CompressedByteSize int64 EventType MessageEventType MessageID int64 Time time.Time UncompressedByteSize int64
MessageEventType specifies the type of message event. const MessageEventTypeRecv const MessageEventTypeSent const MessageEventTypeUnspecified
Sampler decides whether a trace should be sampled and exported. func AlwaysSample() Sampler func NeverSample() Sampler func ProbabilitySampler(fraction float64) Sampler func WithSampler(sampler Sampler) StartOption
SamplingDecision is the value returned by a Sampler. Sample bool
SamplingParameters contains the values passed to a Sampler. HasRemoteParent bool Name string ParentContext SpanContext SpanID SpanID TraceID TraceID
Span represents a span of a trace. It has an associated SpanContext, and stores data accumulated while the span is active. Ideally users should interact with Spans by calling the functions in this package that take a Context parameter. AddAttributes sets attributes in the span. Existing attributes whose keys appear in the attributes parameter are overwritten. AddLink adds a link to the span. AddMessageReceiveEvent adds a message receive event to the span. messageID is an identifier for the message, which is recommended to be unique in this span and the same between the send event and the receive event (this allows to identify a message between the sender and receiver). For example, this could be a sequence id. AddMessageSendEvent adds a message send event to the span. messageID is an identifier for the message, which is recommended to be unique in this span and the same between the send event and the receive event (this allows to identify a message between the sender and receiver). For example, this could be a sequence id. Annotate adds an annotation with attributes. Attributes can be nil. Annotatef adds an annotation with attributes. End ends the span. IsRecordingEvents returns true if events are being recorded for this span. Use this check to avoid computing expensive annotations when they will never be used. SetName sets the name of the span, if it is recording events. SetStatus sets the status of the span, if it is recording events. SpanContext returns the SpanContext of the span. (*T) String() string *T : expvar.Var *T : fmt.Stringer func FromContext(ctx context.Context) *Span func StartSpan(ctx context.Context, name string, o ...StartOption) (context.Context, *Span) func StartSpanWithRemoteParent(ctx context.Context, name string, parent SpanContext, o ...StartOption) (context.Context, *Span) func NewContext(parent context.Context, s *Span) context.Context func go.opencensus.io/plugin/ochttp.NewSpanAnnotatingClientTrace(_ *http.Request, s *Span) *httptrace.ClientTrace func go.opencensus.io/plugin/ochttp.NewSpanAnnotator(r *http.Request, s *Span) *httptrace.ClientTrace
SpanContext contains the state that must propagate across process boundaries. SpanContext is not an implementation of context.Context. TODO: add reference to external Census docs for SpanContext. SpanID SpanID TraceID TraceID TraceOptions TraceOptions Tracestate *tracestate.Tracestate IsSampled returns true if the span will be exported. func (*Span).SpanContext() SpanContext func go.opencensus.io/trace/propagation.FromBinary(b []byte) (sc SpanContext, ok bool) func go.opencensus.io/trace/propagation.HTTPFormat.SpanContextFromRequest(req *http.Request) (sc SpanContext, ok bool) func go.opencensus.io/plugin/ochttp/propagation/b3.(*HTTPFormat).SpanContextFromRequest(req *http.Request) (sc SpanContext, ok bool) func google.golang.org/api/transport/http/internal/propagation.(*HTTPFormat).SpanContextFromRequest(req *http.Request) (sc SpanContext, ok bool) func StartSpanWithRemoteParent(ctx context.Context, name string, parent SpanContext, o ...StartOption) (context.Context, *Span) func go.opencensus.io/trace/propagation.Binary(sc SpanContext) []byte func go.opencensus.io/trace/propagation.HTTPFormat.SpanContextToRequest(sc SpanContext, req *http.Request) func go.opencensus.io/plugin/ochttp/propagation/b3.(*HTTPFormat).SpanContextToRequest(sc SpanContext, req *http.Request) func google.golang.org/api/transport/http/internal/propagation.(*HTTPFormat).SpanContextToRequest(sc SpanContext, req *http.Request)
SpanData contains all the information collected by a Span. Annotations []Annotation The values of Attributes each have type string, bool, or int64. ChildSpanCount holds the number of child span created for this span. DroppedAnnotationCount int DroppedAttributeCount int DroppedLinkCount int DroppedMessageEventCount int The wall clock time of EndTime will be adjusted to always be offset from StartTime by the duration of the span. HasRemoteParent bool Links []Link MessageEvents []MessageEvent Name string ParentSpanID SpanID SpanContext SpanContext SpanContext.SpanID SpanID SpanContext.TraceID TraceID SpanContext.TraceOptions TraceOptions SpanContext.Tracestate *tracestate.Tracestate SpanKind int StartTime time.Time Status Status Code is a status code. Zero indicates success. If Code will be propagated to Google APIs, it ideally should be a value from https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto . Status.Message string IsSampled returns true if the span will be exported. func Exporter.ExportSpan(s *SpanData) func contrib.go.opencensus.io/exporter/stackdriver.(*Exporter).ExportSpan(sd *SpanData) func contrib.go.opencensus.io/exporter/stackdriver.(*Exporter).PushTraceSpans(ctx context.Context, node *commonpb.Node, rsc *resourcepb.Resource, spans []*SpanData) (int, error)
SpanID is an 8-byte identifier for a single span. ( T) String() string T : expvar.Var T : fmt.Stringer func go.opencensus.io/plugin/ochttp/propagation/b3.ParseSpanID(sid string) (spanID SpanID, ok bool)
StartOption apply changes to StartOptions. func WithSampler(sampler Sampler) StartOption func WithSpanKind(spanKind int) StartOption func StartSpan(ctx context.Context, name string, o ...StartOption) (context.Context, *Span) func StartSpanWithRemoteParent(ctx context.Context, name string, parent SpanContext, o ...StartOption) (context.Context, *Span)
StartOptions contains options concerning how a span is started. Sampler to consult for this Span. If provided, it is always consulted. If not provided, then the behavior differs based on whether the parent of this Span is remote, local, or there is no parent. In the case of a remote parent or no parent, the default sampler (see Config) will be consulted. Otherwise, when there is a non-remote parent, no new sampling decision will be made: we will preserve the sampling of the parent. SpanKind represents the kind of a span. If none is set, SpanKindUnspecified is used.
Status is the status of a Span. Code is a status code. Zero indicates success. If Code will be propagated to Google APIs, it ideally should be a value from https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto . Message string func go.opencensus.io/plugin/ochttp.TraceStatus(httpStatusCode int, statusLine string) Status func (*Span).SetStatus(status Status)
TraceID is a 16-byte identifier for a set of spans. ( T) String() string T : expvar.Var T : fmt.Stringer func go.opencensus.io/plugin/ochttp/propagation/b3.ParseTraceID(tid string) (TraceID, bool)
TraceOptions contains options associated with a trace span. IsSampled returns true if the span will be exported. func go.opencensus.io/plugin/ochttp/propagation/b3.ParseSampled(sampled string) (TraceOptions, bool)
Package-Level Functions (total 30, in which 16 are exported)
AlwaysSample returns a Sampler that samples every trace. Be careful about using this sampler in a production application with significant traffic: a new trace will be started and exported for every request.
ApplyConfig applies changes to the global tracing configuration. Fields not provided in the given config are going to be preserved.
BoolAttribute returns a bool-valued attribute.
Float64Attribute returns a float64-valued attribute.
FromContext returns the Span stored in a context, or nil if there isn't one.
Int64Attribute returns an int64-valued attribute.
NeverSample returns a Sampler that samples no traces.
NewContext returns a new context with the given Span attached.
ProbabilitySampler returns a Sampler that samples a given fraction of traces. It also samples spans whose parents are sampled.
RegisterExporter adds to the list of Exporters that will receive sampled trace spans. Binaries can register exporters, libraries shouldn't register exporters.
StartSpan starts a new child span of the current span in the context. If there is no span in the context, creates a new trace and span. Returned context contains the newly created span. You can use it to propagate the returned span in process.
StartSpanWithRemoteParent starts a new child span of the span from the given parent. If the incoming context contains a parent, it ignores. StartSpanWithRemoteParent is preferred for cases where the parent is propagated via an incoming request. Returned context contains the newly created span. You can use it to propagate the returned span in process.
StringAttribute returns a string-valued attribute.
UnregisterExporter removes from the list of Exporters the Exporter that was registered with the given name.
WithSampler makes new spans to be be created with a custom sampler. Otherwise, the global sampler is used.
WithSpanKind makes new spans to be created with the given kind.
Package-Level Variables (total 7, none are exported)
Package-Level Constants (total 34, in which 30 are exported)
DefaultMaxAnnotationEventsPerSpan is default max number of annotation events per span
DefaultMaxAttributesPerSpan is default max number of attributes per span
DefaultMaxLinksPerSpan is default max number of links per span
DefaultMaxMessageEventsPerSpan is default max number of message events per span
LinkType values.
LinkType values.
LinkType values.
MessageEventType values.
MessageEventType values.
MessageEventType values.
All available span kinds. Span kind must be either one of these values.
All available span kinds. Span kind must be either one of these values.
All available span kinds. Span kind must be either one of these values.
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
Status codes for use with Span.SetStatus. These correspond to the status codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto