tracing

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//RequestHeaderAnnotationPrefix is a prefix which is added to each request header attribute
	RequestHeaderAnnotationPrefix = "request.header."

	//RequestTrailerAnnotationPrefix is a prefix which is added to each request trailer attribute
	RequestTrailerAnnotationPrefix = "request.trailer."

	//ResponseHeaderAnnotationPrefix is a prefix which is added to each response header attribute
	ResponseHeaderAnnotationPrefix = "response.header."

	//ResponseTrailerAnnotationPrefix is a prefix which is added to each response header attribute
	ResponseTrailerAnnotationPrefix = "request.trailer."

	//RequestPayloadAnnotationKey is a key under which request payload stored in span
	RequestPayloadAnnotationKey = "request.payload"

	//ResponsePayloadAnnotationKey is a key under which response payload stored in span
	ResponsePayloadAnnotationKey = "response.payload"

	//ResponseErrorKey is a key under which response error will be stored in span
	ResponseErrorKey = "response.error"

	//DefaultMaxPayloadSize represent max payload size which will be added to span
	DefaultMaxPayloadSize = 1024 * 1024

	//TruncatedMarkerKey is a key for annotation which will be presented in span in case payload was truncated
	TruncatedMarkerKey = "payload.truncated"

	//TruncatedMarkerValue is a value for annotation which will be presented in span in case payload was truncated
	TruncatedMarkerValue = "true"

	//ObfuscationFactor is a percent of value which will be omitted from obfuscated value
	ObfuscationFactor = 0.80
)

Variables

View Source
var (
	//ErrSpanNotFound is an error which signal that there is no currently active spans
	ErrSpanNotFound = errors.New("there is no currently active spans")
)

Functions

func AddErrorCurrentSpan

func AddErrorCurrentSpan(ctx context.Context, err error) error

AddErrorCurrentSpan get current span from context and adds error into it

func AddErrorSpan

func AddErrorSpan(span *trace.Span, err error) error

AddErrorSpan adds error into span

func AddMessageCurrentSpan

func AddMessageCurrentSpan(ctx context.Context, message string, attrs ...trace.Attribute) error

AddMessageCurrentSpan get current span from context and adds message into it

func AddMessageSpan

func AddMessageSpan(span *trace.Span, message string, attrs ...trace.Attribute)

AddMessageSpan adds message into span

func AlwaysGRPC

func AlwaysGRPC(_ context.Context, _ stats.RPCStats) bool

AlwaysGRPC for each call returns true

func AlwaysHTTP

func AlwaysHTTP(_ *http.Request) bool

AlwaysHTTP for each request returns true

func CurrentSpan

func CurrentSpan(ctx context.Context) (*trace.Span, error)

CurrentSpan returns current span

func Exporter

func Exporter(address string, serviceName string, sampler trace.Sampler) error

Exporter creates a new OC Agent exporter and configure for tracing

func NewMiddleware

func NewMiddleware(ops ...HTTPOption) func(http.Handler) http.Handler

NewMiddleware wrap handler

func SamplerForFraction

func SamplerForFraction(fraction float64) trace.Sampler

SamplerForFraction init sampler for specified fraction

func SpanContextAnnotator

func SpanContextAnnotator(ctx context.Context, req *http.Request) metadata.MD

SpanContextAnnotator retrieve information about current span from context or HTTP headers and propogate in binary format to gRPC service

func StartSpan

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

StartSpan starts span with name

func TagCurrentSpan

func TagCurrentSpan(ctx context.Context, attrs ...trace.Attribute) error

TagCurrentSpan get current span from context and tag it

func TagSpan

func TagSpan(span *trace.Span, attrs ...trace.Attribute)

TagSpan tags span

Types

type GRPCOption

type GRPCOption func(*gRPCOptions)

GRPCOption allows extending handler with additional functionality

func WithGRPCPayloadAnnotation

func WithGRPCPayloadAnnotation(f func(context.Context, stats.RPCStats) bool) GRPCOption

WithGRPCPayloadAnnotation add Inbound/Outbound payload as an attribute to span if f returns true

func WithGRPCPayloadLimit

func WithGRPCPayloadLimit(limit int) GRPCOption

WithGRPCPayloadLimit limit payload size propogated to span in case payload exceeds limit, payload truncated and annotation payload.truncated=true added into span

func WithMetadataAnnotation

func WithMetadataAnnotation(f func(context.Context, stats.RPCStats) bool) GRPCOption

WithMetadataAnnotation annotate span with request metadata

func WithMetadataMatcher

func WithMetadataMatcher(f func(string) (string, bool)) GRPCOption

WithMetadataMatcher set metadata matcher to filterout or preprocess metadata

type HTTPOption

type HTTPOption func(*httpOptions)

HTTPOption allows extending handler with additional functionality

func WithHTTPPayloadSize

func WithHTTPPayloadSize(maxSize int) HTTPOption

WithHTTPPayloadSize limit payload size propogated to span in case payload exceeds limit, payload truncated and annotation payload.truncated=true added into span

func WithHeaderMatcher

func WithHeaderMatcher(f func(string) (string, bool)) HTTPOption

WithHeaderMatcher set header matcher to filterout or preprocess headers

func WithHeadersAnnotation

func WithHeadersAnnotation(f func(*http.Request) bool) HTTPOption

WithHeadersAnnotation annotate span with http headers

func WithPayloadAnnotation

func WithPayloadAnnotation(f func(*http.Request) bool) HTTPOption

WithPayloadAnnotation add request/response body as an attribute to span if f returns true

type Handler

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

Handler is a opencensus http plugin wrapper which do some usefull things to reach traces

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ServerHandler

type ServerHandler struct {
	ocgrpc.ServerHandler
	// contains filtered or unexported fields
}

ServerHandler is a wrapper over ocgrpc.ServerHandler wrapper extends metadata added into the span

func NewServerHandler

func NewServerHandler(ops ...GRPCOption) *ServerHandler

NewServerHandler returns wrapper over ocgrpc.ServerHandler

func (*ServerHandler) HandleRPC

func (s *ServerHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)

HandleRPC implements per-RPC tracing and stats instrumentation.

Jump to

Keyboard shortcuts

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