You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Package grpctrace is a package to assist with tracing incoming and outgoing gRPC
requests.
Usage
type ClientStatsHandler
typeClientStatsHandlerstruct{}
ClientStatsHandler is a an implementation of grpc.StatsHandler that can be
passed to grpc.Dial using grpc.WithStatsHandler to enable trace context
propagation and automatic span creation for outgoing gRPC requests.
func NewClientStatsHandler
funcNewClientStatsHandler() *ClientStatsHandler
NewClientStatsHandler returns a StatsHandler that can be passed to grpc.Dial
using grpc.WithStatsHandler to enable trace context propagation and automatic
span creation for outgoing gRPC requests.
TagRPC creates a new trace span for the client side of the RPC.
It returns ctx with the new trace span added and a serialization of the
SpanContext added to the outgoing gRPC metadata.
type ServerStatsHandler
typeServerStatsHandlerstruct{}
ServerStatsHandler is a an implementation of grpc.StatsHandler that can be
passed to grpc.NewServer using grpc.StatsHandler to enable trace context
propagation and automatic span creation for incoming gRPC requests..
func NewServerStatsHandler
funcNewServerStatsHandler() *ServerStatsHandler
NewServerStatsHandler returns a StatsHandler that can be passed to
grpc.NewServer using grpc.StatsHandler to enable trace context propagation and
automatic span creation for incoming gRPC requests.
Package trace contains types for representing trace information, and functions
for global configuration of tracing.
The following assumes a basic familiarity with OpenCensus concepts. See
http://opencensus.io.
Enabling Tracing for a Program
To use OpenCensus tracing, register at least one Exporter. You can use one of
the provided exporters or write your own.
trace.RegisterExporter(anExporter)
By default, traces will be sampled relatively rarely. To change the sampling
frequency for your entire program, call SetDefaultSampler. Use a
ProbabilitySampler to sample a subset of traces, or use AlwaysSample to collect
a trace on every run:
trace.SetDefaultSampler(trace.AlwaysSample())
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, "your choice of name")
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.
As a suggestion, use the fully-qualified function name as the span name, e.g.
"github.com/me/mypackage.Run".
Usage
func RegisterExporter
funcRegisterExporter(eExporter)
RegisterExporter adds to the list of Exporters that will receive sampled trace
spans.
func SetDefaultSampler
funcSetDefaultSampler(samplerSampler)
SetDefaultSampler sets the default sampler used when creating new spans.
WithSpan returns a new context with the given Span attached.
type Annotation
typeAnnotationstruct {
Time time.TimeMessagestringAttributesmap[string]interface{}
}
Annotation represents a text annotation with a set of attributes and a
timestamp.
type Attribute
typeAttributeinterface {
// contains filtered or unexported methods
}
Attribute is an interface for attributes; it is implemented by BoolAttribute,
IntAttribute, and StringAttribute.
type BoolAttribute
typeBoolAttributestruct {
KeystringValuebool
}
BoolAttribute represents a bool-valued attribute.
ErrorBucketSummary is a summary of an error bucket.
type Exporter
typeExporterinterface {
ExportSpan(s*SpanData)
}
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.
type Int64Attribute
typeInt64Attributestruct {
KeystringValueint64
}
Int64Attribute represents an int64-valued attribute.
type Link
typeLinkstruct {
TraceIDTraceIDSpanIDSpanIDTypeLinkType// Attributes is a set of attributes on the link.Attributesmap[string]interface{}
}
Link represents a reference from one span to another span.
type LinkType
typeLinkTypeint32
LinkType specifies the relationship between the span that had the link added,
and the linked span.
const (
LinkTypeUnspecifiedLinkType=iota// The relationship of the two spans is unknown.LinkTypeChild// The current span is a child of the linked span.LinkTypeParent// The current span is the parent of the linked span.
)
LinkType values.
type MessageEvent
typeMessageEventstruct {
Time time.TimeEventTypeMessageEventTypeMessageIDint64UncompressedByteSizeint64CompressedByteSizeint64
}
MessageEvent represents an event describing a message sent or received on the
network.
type MessageEventType
typeMessageEventTypeint32
MessageEventType specifies the type of message event.
const (
MessageEventTypeUnspecifiedMessageEventType=iota// Unknown event type.MessageEventTypeSent// Indicates a sent RPC message.MessageEventTypeRecv// Indicates a received RPC message.
)
MessageEventType values.
PerMethodSummary is a summary of the spans stored for a single span name.
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.
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.
func (SpanContext) IsSampled
func (scSpanContext) IsSampled() bool
IsSampled returns true if the span will be exported.
type SpanData
typeSpanDatastruct {
SpanContextParentSpanIDSpanIDNamestringStartTime time.Time// The wall clock time of EndTime will be adjusted to always be offset// from StartTime by the duration of the span.EndTime time.Time// The values of Attributes each have type string, bool, or int64.Attributesmap[string]interface{}
Annotations []AnnotationMessageEvents []MessageEventStatusLinks []LinkHasRemoteParentbool
}
SpanData contains all the information collected by a Span.
type SpanID
typeSpanID [8]byte
SpanID is an 8-byte identifier for a single span.
func (SpanID) String
func (sSpanID) String() string
type StartOptions
typeStartOptionsstruct {
// RecordEvents indicates whether to record data for this span, and include// the span in a local span store.// Events will also be recorded if the span will be exported.RecordEventsboolSamplerSampler// if non-nil, the Sampler to consult for this span.// RegisterNameForLocalSpanStore indicates that a local span store for spans// of this name should be created, if one does not exist.// If RecordEvents is false, this option has no effect.RegisterNameForLocalSpanStorebool
}
StartOptions contains options concerning how a span is started.
type Status
typeStatusstruct {
// 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 .Codeint32Messagestring
}