tracing

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package tracing contains tracing related functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigMapName

func ConfigMapName() string

ConfigMapName gets the name of the tracing ConfigMap

func RestfulFilter

func RestfulFilter(serviceName string, ignorePaths ...string) restful.FilterFunction

RestfulFilter Set the tracing middleware for go-restful web service framework. If ignorePaths param is specified, these paths will not be sampled.

func SetupDynamicPublishing

func SetupDynamicPublishing(tracing *Tracing, configMapWatcher configmap.DefaultingWatcher) error

SetupDynamicPublishing sets up trace publishing for the process, by watching a ConfigMap for the configuration. Note that other pieces still need to generate the traces, this just ensures that if generated, they are collected appropriately. This is normally done by using tracing.HTTPSpanMiddleware as a middleware HTTP handler. The configuration will be dynamically updated when the ConfigMap is updated.

func WrapTransport

func WrapTransport(rt http.RoundTripper) http.RoundTripper

WrapTransport Wrap Transport for Tracing When rt is nil, default transport will be used

func WrapTransportForRestyClient

func WrapTransportForRestyClient(client *resty.Client)

WrapTransportForRestyClient Specifically wrapped for the go-resty client for tracking Warning: Because some methods in go-resty (such as SetTLSClientConfig、SetProxy) rely on *http.Transport, this method must be called after initialization.

correct example:

restyClient := resty.New()
restyClient.SetTLSClientConfig(&tls.Config{
	InsecureSkipVerify: true,
})
tracing.WrapTransportForRestyClient(restyClient)

wrong example:

		restyClient := resty.New()
     tracing.WrapTransportForRestyClient(restyClient)
		restyClient.SetTLSClientConfig(&tls.Config{
			InsecureSkipVerify: true,
		})

Types

type Config

type Config struct {
	// Enable Controls whether to enable tracing.
	// default false.
	Enable bool `json:"enable" yaml:"enable"`

	// SamplingRatio Control the rate of sampling.
	// SamplingRatio >= 1 will always sample.
	// SamplingRatio <= 0 will never sample.
	// default 0.
	SamplingRatio float64 `json:"sampling_ratio" yaml:"samplingRatio"`

	// Backend The type of exporter backend
	Backend ExporterBackend `json:"backend" yaml:"backend"`

	// Jaeger The configuration used by jaeger backend
	Jaeger JaegerConfig `json:"jaeger" yaml:"jaeger"`

	// Zipkin The configuration used by zipkin backend
	Zipkin ZipkinConfig `json:"zipkin" yaml:"zipkin"`

	// Custom The configuration used by custom backend
	Custom string `json:"custom" yaml:"custom"`
}

Config tracing config

type ExporterBackend

type ExporterBackend string

ExporterBackend Built-in supported export types

var (
	ExporterBackendJaeger ExporterBackend = "jaeger"
	ExporterBackendZipkin ExporterBackend = "zipkin"
	ExporterBackendCustom ExporterBackend = "custom"
)

type ExporterConstructor

type ExporterConstructor func(config *Config) (trace.SpanExporter, error)

ExporterConstructor Construct exporter by the specified config

type JaegerConfig

type JaegerConfig struct {
	// Host The host of jaeger backend.
	Host string `json:"host" yaml:"host"`

	// Port the port of jaeger backend.
	Port string `json:"port" yaml:"port"`

	// MaxPacketSize The maximum UDP packet size for transport to the Jaeger agent.
	MaxPacketSize int `json:"max_packet_size" yaml:"maxPacketSize"`

	// DisableAttemptReconnecting Disable reconnecting udp client.
	DisableAttemptReconnecting bool `json:"disable_attempt_reconnecting" yaml:"disableAttemptReconnecting"`

	// AttemptReconnectInterval The interval between attempts to re resolve agent endpoint.
	AttemptReconnectInterval time.Duration `json:"attempt_reconnect_interval" yaml:"attemptReconnectInterval"`
}

JaegerConfig The configuration used by Jaeger backend

type ResourceConstructor

type ResourceConstructor func(config *Config) (*resource.Resource, error)

ResourceConstructor Construct resource by the specified config

type TraceOption

type TraceOption func(tracing *Tracing)

TraceOption optional setting of Tracing instance

func WithExporter

func WithExporter(f ExporterConstructor) TraceOption

WithExporter Configures the exporter backend for `Tracing` instance.

func WithResource

func WithResource(f ResourceConstructor) TraceOption

WithResource Configures the resource for `Tracing` instance.

func WithServiceName

func WithServiceName(name string) TraceOption

WithServiceName Configures the service name for Tracing instance

func WithTextMapPropagator

func WithTextMapPropagator(ops ...propagation.TextMapPropagator) TraceOption

WithTextMapPropagator Configures the propagator options for traceProvider

func WithTraceProvider

func WithTraceProvider(f TraceProviderConstructor) TraceOption

WithTraceProvider Configures the TraceProvider for `Tracing` instance If `TraceProvider` is specified, `WithExporter` and `WithResource` function will not work.

func WithTracerProviderOption

func WithTracerProviderOption(ops ...trace.TracerProviderOption) TraceOption

WithTracerProviderOption Configures the options for built-in traceProvider

type TraceProviderConstructor

type TraceProviderConstructor func(config *Config) (*trace.TracerProvider, error)

TraceProviderConstructor Construct `TraceProvider` by the specified config

type Tracing

type Tracing struct {
	ServiceName   string
	ConfigMapName string

	Propagators []propagation.TextMapPropagator
	// contains filtered or unexported fields
}

Tracing describe an entity that watching configuration file changes and maintain the global tracing.

func NewTracing

func NewTracing(logger *zap.SugaredLogger, ops ...TraceOption) *Tracing

NewTracing construct `Tracing` instance `TraceOption` can be used to customize settings.

func (*Tracing) ApplyConfig

func (t *Tracing) ApplyConfig(cfg *Config)

ApplyConfig Apply configuration and reinitialize global tracing. This method will be triggered when the configuration changes. If an error occurs, the initialization process will be skipped.

type Transport

type Transport struct {
	*otelhttp.Transport
	// contains filtered or unexported fields
}

Transport for tracing

func (*Transport) CancelRequest

func (t *Transport) CancelRequest(req *http.Request)

CancelRequest cancels an in-flight request by closing its connection. It works when the original RoundTripper implementation canceler interface.

func (*Transport) RoundTrip

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

RoundTrip creates a Span and propagates its context via the provided request's headers before handing the request to the configured base RoundTripper. The created span will end when the response body is closed or when a read from the body returns io.EOF.

type ZipkinConfig

type ZipkinConfig struct {
	// Url The collector url of zipkin backend
	Url string `json:"url" yaml:"url"`
}

ZipkinConfig The configuration used by zipkin backend

Jump to

Keyboard shortcuts

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