instracer

package
v0.0.0-...-05bc493 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package instracer contains helpers for opencesus tracer.

Example:

import (
	"github.com/insolar/assured-ledger/ledger-core/configuration"
	"github.com/insolar/assured-ledger/ledger-core/log"
)

// on client side
//
entryvalue := "entryvalue"
ctx := context.Background()
jaegerflush = instracer.ShouldRegisterJaeger(ctx, "insolard", "localhost:6831", "")
defer jaegerflush() // wait all trace data to send on jaeger server

// serialize clientctx
spanbindata := instracer.MustSerialize(ctx)

// send spanbindata on wire with request
// someSendMethod(ctxdata, request)

// on server side
//
// deserialized from wire
// spanbindata := someRecieverMethod()
ctx := context.Background()
instracer.MustDeserialize(spanbindata)

ctx = instracer.WithParentSpan(ctx, parentspan)
donefn := instracer.ShouldRegisterJaeger(ctx, "server", "localhost:6831", "")
defer donefn()

servctx, servspan := instracer.StartSpan(ctx, "server")
defer servspan.End()
// call subrequests with servctx, and use instracer.StartSpan

Hints:

Use environment variables for log level setup:

INSOLAR_TRACER_JAEGER_AGENTENDPOINT="localhost:6831"

How to run Jaeger locally:

docker run --rm --name jaeger \
	-p 6831:6831/udp \
	-p 16686:16686 \
	jaegertracing/all-in-one:1.7 --log-level=debug

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthSpanData        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowSpanData          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupSpanData = fmt.Errorf("proto: unexpected end of group")
)
View Source
var ErrJaegerConfigEmpty = errors.New("can't create jaeger exporter, config not provided")

ErrJaegerConfigEmpty is returned if jaeger configuration has empty endpoint values.

Functions

func AddError

func AddError(span opentracing.Span, err error)

AddError add error info to span and mark span as errored

func MakeBinarySpan

func MakeBinarySpan(input []byte) []byte

func MakeUintSpan

func MakeUintSpan(input []byte) uint64

func MustSerialize

func MustSerialize(ctx context.Context) []byte

MustSerialize encode baggage entries from bytes, panics on error.

func NewJaegerTracer

func NewJaegerTracer(
	_ context.Context,
	serviceName string,
	nodeRef string,
	agentEndpoint string,
	collectorEndpoint string,
	probabilityRate float64,
) (opentracing.Tracer, io.Closer, error)

NewJaegerTracer creates jaeger exporter and registers it in opencensus trace lib.

func ParentSpanCtx

func ParentSpanCtx(ctx context.Context) (jaeger.SpanContext, context.Context)

func Serialize

func Serialize(ctx context.Context) ([]byte, error)

Serialize encode baggage entries to bytes.

func ShouldRegisterJaeger

func ShouldRegisterJaeger(
	ctx context.Context,
	serviceName string,
	nodeRef string,
	agentEndpoint string,
	collectorEndpoint string,
	probabilityRate float64,
) func()

ShouldRegisterJaeger calls NewJaegerTracer and returns flush function.

func StartSpan

func StartSpan(ctx context.Context, name string, o ...opentracing.StartSpanOption) (context.Context, opentracing.Span)

StartSpan starts span with stored baggage and with parent span if find in context.

func StartSpanWithSpanID

func StartSpanWithSpanID(ctx context.Context, name string, spanID uint64, o ...opentracing.StartSpanOption) (context.Context, opentracing.Span)

func WithParentSpan

func WithParentSpan(ctx context.Context, pspan TraceSpan) context.Context

Types

type LoggingSpan

type LoggingSpan struct {
	opentracing.Span
	// contains filtered or unexported fields
}

func InitWrapper

func InitWrapper(ctx context.Context, span opentracing.Span, name string) *LoggingSpan

func (*LoggingSpan) Finish

func (ls *LoggingSpan) Finish()

type TraceSpan

type TraceSpan struct {
	TraceID []byte `protobuf:"bytes,20,opt,name=TraceID,proto3" json:"TraceID,omitempty"`
	SpanID  []byte `protobuf:"bytes,21,opt,name=SpanID,proto3" json:"SpanID,omitempty"`
}

func Deserialize

func Deserialize(b []byte) (TraceSpan, error)

Deserialize decode baggage entries from bytes.

func MustDeserialize

func MustDeserialize(b []byte) TraceSpan

MustDeserialize decode baggage entries from bytes, panics on error.

func ParentSpan

func ParentSpan(ctx context.Context) (traceSpan TraceSpan, ok bool)

func (*TraceSpan) Descriptor

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

func (*TraceSpan) Equal

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

func (*TraceSpan) GoString

func (this *TraceSpan) GoString() string

func (*TraceSpan) Marshal

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

func (*TraceSpan) MarshalTo

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

func (*TraceSpan) MarshalToSizedBuffer

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

func (*TraceSpan) ProtoMessage

func (*TraceSpan) ProtoMessage()

func (*TraceSpan) Reset

func (m *TraceSpan) Reset()

func (TraceSpan) Serialize

func (ts TraceSpan) Serialize() ([]byte, error)

Serialize method encodes TraceSpan to bytes.

func (*TraceSpan) Size

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

func (*TraceSpan) String

func (this *TraceSpan) String() string

func (*TraceSpan) Unmarshal

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

func (*TraceSpan) XXX_DiscardUnknown

func (m *TraceSpan) XXX_DiscardUnknown()

func (*TraceSpan) XXX_Marshal

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

func (*TraceSpan) XXX_Merge

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

func (*TraceSpan) XXX_Size

func (m *TraceSpan) XXX_Size() int

func (*TraceSpan) XXX_Unmarshal

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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