Documentation ¶
Index ¶
- Constants
- func Extract(ctx context.Context, metadata *metadata.MD, opts ...GRPCOption) ([]label.KeyValue, trace.SpanContext)
- func HostIP() (net.IP, error)
- func Inject(ctx context.Context, metadata *metadata.MD, opts ...GRPCOption)
- func NewTracerFromEnv(options ...Option) (trace.Tracer, error)
- func OpenDB(tracer trace.Tracer, dsn string) (*sqlx.DB, error)
- func TraceId(ctx context.Context) zap.Field
- func UnaryClientInterceptor(tracer trace.Tracer, componentName string) grpc.UnaryClientInterceptor
- func UnaryServerInterceptor(tracer trace.Tracer, componentName string) grpc.UnaryServerInterceptor
- type Configuration
- func (c *Configuration) FromEnv() (*Configuration, error)
- func (c *Configuration) NewHttpMiddleware(options ...HttpOption) (*HttpMiddleware, error)
- func (c *Configuration) NewTracer(options ...Option) (trace.Tracer, error)
- func (c *Configuration) NewTransport(options ...TransportOption) (*Transport, error)
- func (c *Configuration) OpenDB(dsn string) (*sqlx.DB, error)
- type GRPCOption
- type HttpMiddleware
- type HttpOption
- type Option
- type Options
- type Transport
- type TransportOption
Constants ¶
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 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 ¶
NewTracerFromEnv uses environment variables to create the tracer
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)
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 ¶
func (m *HttpMiddleware) Handle(h http.HandlerFunc) http.HandlerFunc
type HttpOption ¶
type HttpOption func(*HttpMiddleware)
func WithHttpComponentName ¶
func WithHttpComponentName(componentName string) HttpOption
WithHttpComponentName set component name
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 ServiceName ¶
ServiceName can be provided to service name.
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)
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