trace

package
v0.0.0-...-48b9d42 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OTEL_AGENT_ENDPOINT
)

Variables

This section is empty.

Functions

func Extract

func Extract(ctx context.Context, metadata *metadata.MD, opts ...GRPCOption) ([]label.KeyValue, trace.SpanContext)

Extract returns the correlation context and span context that another service encoded in the gRPC metadata object with Inject. This function is meant to be used on incoming requests.

func HostIP

func HostIP() (net.IP, error)

HostIP tries to find an IP that can be used by other machines to reach this machine.

func Inject

func Inject(ctx context.Context, metadata *metadata.MD, opts ...GRPCOption)

Inject injects correlation context and span context into the gRPC metadata object. This function is meant to be used on outgoing requests.

func NewTracerFromEnv

func NewTracerFromEnv(options ...Option) (trace.Tracer, error)

NewTracerFromEnv uses environment variables to create the tracer

func OpenDB

func OpenDB(tracer trace.Tracer, dsn string) (*sqlx.DB, error)

OpenDB open driver

func TraceId

func TraceId(ctx context.Context) zap.Field

TraceId add trace Id that gets trace id from the context to the logger

func UnaryClientInterceptor

func UnaryClientInterceptor(tracer trace.Tracer, componentName string) grpc.UnaryClientInterceptor

UnaryClientInterceptor returns a grpc.UnaryClientInterceptor suitable for use in a grpc.Dial call.

For example:

tracer := global.Tracer("client-tracer")
s := grpc.NewServer(
    grpc.WithUnaryInterceptor(grpctrace.UnaryClientInterceptor(tracer)),
    ...,  // (existing DialOptions))

func UnaryServerInterceptor

func UnaryServerInterceptor(tracer trace.Tracer, componentName string) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a grpc.UnaryServerInterceptor suitable for use in a grpc.NewServer call.

For example:

tracer := global.Tracer("client-tracer")
s := grpc.Dial(
    grpc.UnaryInterceptor(grpctrace.UnaryServerInterceptor(tracer)),
    ...,  // (existing ServerOptions))

Types

type Configuration

type Configuration struct {
	// ServiceName specifies the service name to use on the tracer.
	// Can be provided via environment variable named TRACE_SERVICE_NAME
	ServiceName string

	// AgentEndpoint is agent address of collecting trace message, host:port
	// Can be provided via environment variable named OTLP_AGENT_EDNPOINT
	AgentEndpoint string

	// Enabled can be provided via environment variable named TRACE_ENABLED
	Enabled bool
}

Configuration configures and creates Tracer

func FromEnv

func FromEnv() (*Configuration, error)

FromEnv uses environment variables to set the tracer's Configuration

func (*Configuration) FromEnv

func (c *Configuration) FromEnv() (*Configuration, error)

FromEnv uses environment variables and overrides existing tracer's Configuration

func (*Configuration) NewHttpMiddleware

func (c *Configuration) NewHttpMiddleware(options ...HttpOption) (*HttpMiddleware, error)

func (*Configuration) NewTracer

func (c *Configuration) NewTracer(options ...Option) (trace.Tracer, error)

NewTracer create a new tracer

func (*Configuration) NewTransport

func (c *Configuration) NewTransport(options ...TransportOption) (*Transport, error)

func (*Configuration) OpenDB

func (c *Configuration) OpenDB(dsn string) (*sqlx.DB, error)

type GRPCOption

type GRPCOption func(*config)

GRPCOption is a function that allows configuration of the grpctrace Extract() and Inject() functions

func WithPropagators

func WithPropagators(props propagation.Propagators) GRPCOption

WithPropagators sets the propagators to use for Extraction and Injection

type HttpMiddleware

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

HttpMiddleware is http middleware about trace

func NewHttpMiddleware

func NewHttpMiddleware(tracer trace.Tracer, opts ...HttpOption) (*HttpMiddleware, error)

func (*HttpMiddleware) Handle

type HttpOption

type HttpOption func(*HttpMiddleware)

func WithHttpComponentName

func WithHttpComponentName(componentName string) HttpOption

WithHttpComponentName set component name

func WithHttpLogger

func WithHttpLogger(logger *zap.Logger) HttpOption

WithHttpLogger set logger

func WithHttpOpNameFunc

func WithHttpOpNameFunc(fn func(r *http.Request) string) HttpOption

WithHttpOpNameFunc set function to get operation name for span

type Option

type Option func(c *Options)

Option is a function that sets some option on the client.

func Logger

func Logger(logger *zap.Logger) Option

Logger can be provided to logger.

func ServiceName

func ServiceName(serviceName string) Option

ServiceName can be provided to service name.

type Options

type Options struct {
	ServiceName string
	Logger      *zap.Logger
}

Options control behavior of the client.

type Transport

type Transport struct {
	// The actual RoundTripper to use for the request. A nil
	// RoundTripper defaults to http.DefaultTransport.
	http.RoundTripper
	// contains filtered or unexported fields
}

Transport wraps a RoundTripper. If a request is being traced with Tracer, Transport will inject the current span into the headers, and set HTTP related tags on the span.

func NewTransport

func NewTransport(tracer trace.Tracer, options ...TransportOption) (*Transport, error)

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

type TransportOption

type TransportOption func(*Transport)

func WithTransportComponentName

func WithTransportComponentName(componentName string) TransportOption

func WithTransportLogger

func WithTransportLogger(logger *zap.Logger) TransportOption

func WithTransportOpNameFunc

func WithTransportOpNameFunc(opNameFunc func(*http.Request) string) TransportOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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