config

package
Version: v2.29.1+incompatible Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: Apache-2.0 Imports: 17 Imported by: 1,154

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaggageRestrictionsConfig

type BaggageRestrictionsConfig struct {
	// DenyBaggageOnInitializationFailure controls the startup failure mode of the baggage restriction
	// manager. If true, the manager will not allow any baggage to be written until baggage restrictions have
	// been retrieved from jaeger-agent. If false, the manager wil allow any baggage to be written until baggage
	// restrictions have been retrieved from jaeger-agent.
	DenyBaggageOnInitializationFailure bool `yaml:"denyBaggageOnInitializationFailure"`

	// HostPort is the hostPort of jaeger-agent's baggage restrictions server
	HostPort string `yaml:"hostPort"`

	// RefreshInterval controls how often the baggage restriction manager will poll
	// jaeger-agent for the most recent baggage restrictions.
	RefreshInterval time.Duration `yaml:"refreshInterval"`
}

BaggageRestrictionsConfig configures the baggage restrictions manager which can be used to whitelist certain baggage keys. All fields are optional.

type Configuration

type Configuration struct {
	// ServiceName specifies the service name to use on the tracer.
	// Can be provided by FromEnv() via the environment variable named JAEGER_SERVICE_NAME
	ServiceName string `yaml:"serviceName"`

	// Disabled makes the config return opentracing.NoopTracer.
	// Value can be provided by FromEnv() via the environment variable named JAEGER_DISABLED.
	Disabled bool `yaml:"disabled"`

	// RPCMetrics enables generations of RPC metrics (requires metrics factory to be provided).
	// Value can be provided by FromEnv() via the environment variable named JAEGER_RPC_METRICS
	RPCMetrics bool `yaml:"rpc_metrics"`

	// Gen128Bit instructs the tracer to generate 128-bit wide trace IDs, compatible with W3C Trace Context.
	// Value can be provided by FromEnv() via the environment variable named JAEGER_TRACEID_128BIT.
	Gen128Bit bool `yaml:"traceid_128bit"`

	// Tags can be provided by FromEnv() via the environment variable named JAEGER_TAGS
	Tags []opentracing.Tag `yaml:"tags"`

	Sampler             *SamplerConfig             `yaml:"sampler"`
	Reporter            *ReporterConfig            `yaml:"reporter"`
	Headers             *jaeger.HeadersConfig      `yaml:"headers"`
	BaggageRestrictions *BaggageRestrictionsConfig `yaml:"baggage_restrictions"`
	Throttler           *ThrottlerConfig           `yaml:"throttler"`
}

Configuration configures and creates Jaeger Tracer

func FromEnv

func FromEnv() (*Configuration, error)

FromEnv uses environment variables to set the tracer's Configuration

Example
package main

import (
	"log"

	opentracing "github.com/opentracing/opentracing-go"
	jaegercfg "github.com/uber/jaeger-client-go/config"
)

func main() {
	cfg, err := jaegercfg.FromEnv()
	if err != nil {
		// parsing errors might happen here, such as when we get a string where we expect a number
		log.Printf("Could not parse Jaeger env vars: %s", err.Error())
		return
	}

	tracer, closer, err := cfg.NewTracer()
	if err != nil {
		log.Printf("Could not initialize jaeger tracer: %s", err.Error())
		return
	}
	defer closer.Close()

	opentracing.SetGlobalTracer(tracer)
	// continue main()
}
Output:

Example (Override)
package main

import (
	"log"
	"os"

	opentracing "github.com/opentracing/opentracing-go"
	jaegercfg "github.com/uber/jaeger-client-go/config"
)

func main() {
	os.Setenv("JAEGER_SERVICE_NAME", "not-effective")

	cfg, err := jaegercfg.FromEnv()
	if err != nil {
		// parsing errors might happen here, such as when we get a string where we expect a number
		log.Printf("Could not parse Jaeger env vars: %s", err.Error())
		return
	}

	cfg.ServiceName = "this-will-be-the-service-name"

	tracer, closer, err := cfg.NewTracer()
	if err != nil {
		log.Printf("Could not initialize jaeger tracer: %s", err.Error())
		return
	}
	defer closer.Close()

	opentracing.SetGlobalTracer(tracer)
	// continue main()
}
Output:

func (*Configuration) FromEnv

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

FromEnv uses environment variables and overrides existing tracer's Configuration

func (Configuration) InitGlobalTracer

func (c Configuration) InitGlobalTracer(
	serviceName string,
	options ...Option,
) (io.Closer, error)

InitGlobalTracer creates a new Jaeger Tracer, and sets it as global OpenTracing Tracer. It returns a closer func that can be used to flush buffers before shutdown.

Example (Production)
package main

import (
	"log"

	jaegercfg "github.com/uber/jaeger-client-go/config"
	jaegerlog "github.com/uber/jaeger-client-go/log"
	"github.com/uber/jaeger-lib/metrics"
)

func main() {
	// Recommended configuration for production.
	cfg := jaegercfg.Configuration{}

	// Example logger and metrics factory. Use github.com/uber/jaeger-client-go/log
	// and github.com/uber/jaeger-lib/metrics respectively to bind to real logging and metrics
	// frameworks.
	jLogger := jaegerlog.StdLogger
	jMetricsFactory := metrics.NullFactory

	// Initialize tracer with a logger and a metrics factory
	closer, err := cfg.InitGlobalTracer(
		"serviceName",
		jaegercfg.Logger(jLogger),
		jaegercfg.Metrics(jMetricsFactory),
	)
	if err != nil {
		log.Printf("Could not initialize jaeger tracer: %s", err.Error())
		return
	}
	defer closer.Close()

	// continue main()
}
Output:

Example (Testing)
// Sample configuration for testing. Use constant sampling to sample every trace
// and enable LogSpan to log every span via configured Logger.
cfg := jaegercfg.Configuration{
	Sampler: &jaegercfg.SamplerConfig{
		Type:  jaeger.SamplerTypeConst,
		Param: 1,
	},
	Reporter: &jaegercfg.ReporterConfig{
		LogSpans: true,
	},
}

// Example logger and metrics factory. Use github.com/uber/jaeger-client-go/log
// and github.com/uber/jaeger-lib/metrics respectively to bind to real logging and metrics
// frameworks.
jLogger := jaegerlog.StdLogger
jMetricsFactory := metrics.NullFactory

// Initialize tracer with a logger and a metrics factory
closer, err := cfg.InitGlobalTracer(
	"serviceName",
	jaegercfg.Logger(jLogger),
	jaegercfg.Metrics(jMetricsFactory),
)
if err != nil {
	log.Printf("Could not initialize jaeger tracer: %s", err.Error())
	return
}
defer closer.Close()

// continue main()
Output:

func (Configuration) New deprecated

func (c Configuration) New(
	serviceName string,
	options ...Option,
) (opentracing.Tracer, io.Closer, error)

New creates a new Jaeger Tracer, and a closer func that can be used to flush buffers before shutdown.

Deprecated: use NewTracer() function

func (Configuration) NewTracer

func (c Configuration) NewTracer(options ...Option) (opentracing.Tracer, io.Closer, error)

NewTracer returns a new tracer based on the current configuration, using the given options, and a closer func that can be used to flush buffers before shutdown.

type Option

type Option func(c *Options)

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

func ContribObserver

func ContribObserver(observer jaeger.ContribObserver) Option

ContribObserver can be registered with the Tracer to receive notifications about new spans.

func Extractor

func Extractor(format interface{}, extractor jaeger.Extractor) Option

Extractor registers an Extractor with the given format.

func Gen128Bit

func Gen128Bit(gen128Bit bool) Option

Gen128Bit specifies whether to generate 128bit trace IDs.

func Injector

func Injector(format interface{}, injector jaeger.Injector) Option

Injector registers an Injector with the given format.

func Logger

func Logger(logger jaeger.Logger) Option

Logger can be provided to log Reporter errors, as well as to log spans if Reporter.LogSpans is set to true.

func MaxTagValueLength

func MaxTagValueLength(maxTagValueLength int) Option

MaxTagValueLength can be provided to override the default max tag value length.

func Metrics

func Metrics(factory metrics.Factory) Option

Metrics creates an Option that initializes Metrics in the tracer, which is used to emit statistics about spans.

func NoDebugFlagOnForcedSampling

func NoDebugFlagOnForcedSampling(noDebugFlagOnForcedSampling bool) Option

NoDebugFlagOnForcedSampling can be used to decide whether debug flag will be set or not when calling span.setSamplingPriority to force sample a span.

func Observer

func Observer(observer jaeger.Observer) Option

Observer can be registered with the Tracer to receive notifications about new Spans.

func PoolSpans

func PoolSpans(poolSpans bool) Option

PoolSpans specifies whether to pool spans

func Reporter

func Reporter(reporter jaeger.Reporter) Option

Reporter can be provided explicitly to override the configuration. Useful for testing, e.g. by passing InMemoryReporter.

func Sampler

func Sampler(sampler jaeger.Sampler) Option

Sampler can be provided explicitly to override the configuration.

func Tag

func Tag(key string, value interface{}) Option

Tag creates an option that adds a tracer-level tag.

func WithRandomNumber

func WithRandomNumber(f func() uint64) Option

WithRandomNumber supplies a random number generator function to the Tracer used to generate trace and span IDs.

func ZipkinSharedRPCSpan

func ZipkinSharedRPCSpan(zipkinSharedRPCSpan bool) Option

ZipkinSharedRPCSpan creates an option that enables sharing span ID between client and server spans a la zipkin. If false, client and server spans will be assigned different IDs.

type Options

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

Options control behavior of the client.

type ReporterConfig

type ReporterConfig struct {
	// QueueSize controls how many spans the reporter can keep in memory before it starts dropping
	// new spans. The queue is continuously drained by a background go-routine, as fast as spans
	// can be sent out of process.
	// Can be provided by FromEnv() via the environment variable named JAEGER_REPORTER_MAX_QUEUE_SIZE
	QueueSize int `yaml:"queueSize"`

	// BufferFlushInterval controls how often the buffer is force-flushed, even if it's not full.
	// It is generally not useful, as it only matters for very low traffic services.
	// Can be provided by FromEnv() via the environment variable named JAEGER_REPORTER_FLUSH_INTERVAL
	BufferFlushInterval time.Duration

	// LogSpans, when true, enables LoggingReporter that runs in parallel with the main reporter
	// and logs all submitted spans. Main Configuration.Logger must be initialized in the code
	// for this option to have any effect.
	// Can be provided by FromEnv() via the environment variable named JAEGER_REPORTER_LOG_SPANS
	LogSpans bool `yaml:"logSpans"`

	// LocalAgentHostPort instructs reporter to send spans to jaeger-agent at this address.
	// Can be provided by FromEnv() via the environment variable named JAEGER_AGENT_HOST / JAEGER_AGENT_PORT
	LocalAgentHostPort string `yaml:"localAgentHostPort"`

	// DisableAttemptReconnecting when true, disables udp connection helper that periodically re-resolves
	// the agent's hostname and reconnects if there was a change. This option only
	// applies if LocalAgentHostPort is specified.
	// Can be provided by FromEnv() via the environment variable named JAEGER_REPORTER_ATTEMPT_RECONNECTING_DISABLED
	DisableAttemptReconnecting bool `yaml:"disableAttemptReconnecting"`

	// AttemptReconnectInterval controls how often the agent client re-resolves the provided hostname
	// in order to detect address changes. This option only applies if DisableAttemptReconnecting is false.
	// Can be provided by FromEnv() via the environment variable named JAEGER_REPORTER_ATTEMPT_RECONNECT_INTERVAL
	AttemptReconnectInterval time.Duration

	// CollectorEndpoint instructs reporter to send spans to jaeger-collector at this URL.
	// Can be provided by FromEnv() via the environment variable named JAEGER_ENDPOINT
	CollectorEndpoint string `yaml:"collectorEndpoint"`

	// User instructs reporter to include a user for basic http authentication when sending spans to jaeger-collector.
	// Can be provided by FromEnv() via the environment variable named JAEGER_USER
	User string `yaml:"user"`

	// Password instructs reporter to include a password for basic http authentication when sending spans to
	// jaeger-collector.
	// Can be provided by FromEnv() via the environment variable named JAEGER_PASSWORD
	Password string `yaml:"password"`

	// HTTPHeaders instructs the reporter to add these headers to the http request when reporting spans.
	// This field takes effect only when using HTTPTransport by setting the CollectorEndpoint.
	HTTPHeaders map[string]string `yaml:"http_headers"`
}

ReporterConfig configures the reporter. All fields are optional.

func (*ReporterConfig) NewReporter

func (rc *ReporterConfig) NewReporter(
	serviceName string,
	metrics *jaeger.Metrics,
	logger jaeger.Logger,
) (jaeger.Reporter, error)

NewReporter instantiates a new reporter that submits spans to the collector

type SamplerConfig

type SamplerConfig struct {
	// Type specifies the type of the sampler: const, probabilistic, rateLimiting, or remote.
	// Can be provided by FromEnv() via the environment variable named JAEGER_SAMPLER_TYPE
	Type string `yaml:"type"`

	// Param is a value passed to the sampler.
	// Valid values for Param field are:
	// - for "const" sampler, 0 or 1 for always false/true respectively
	// - for "probabilistic" sampler, a probability between 0 and 1
	// - for "rateLimiting" sampler, the number of spans per second
	// - for "remote" sampler, param is the same as for "probabilistic"
	//   and indicates the initial sampling rate before the actual one
	//   is received from the mothership.
	// Can be provided by FromEnv() via the environment variable named JAEGER_SAMPLER_PARAM
	Param float64 `yaml:"param"`

	// SamplingServerURL is the URL of sampling manager that can provide
	// sampling strategy to this service.
	// Can be provided by FromEnv() via the environment variable named JAEGER_SAMPLING_ENDPOINT
	SamplingServerURL string `yaml:"samplingServerURL"`

	// SamplingRefreshInterval controls how often the remotely controlled sampler will poll
	// sampling manager for the appropriate sampling strategy.
	// Can be provided by FromEnv() via the environment variable named JAEGER_SAMPLER_REFRESH_INTERVAL
	SamplingRefreshInterval time.Duration `yaml:"samplingRefreshInterval"`

	// MaxOperations is the maximum number of operations that the PerOperationSampler
	// will keep track of. If an operation is not tracked, a default probabilistic
	// sampler will be used rather than the per operation specific sampler.
	// Can be provided by FromEnv() via the environment variable named JAEGER_SAMPLER_MAX_OPERATIONS.
	MaxOperations int `yaml:"maxOperations"`

	// Opt-in feature for applications that require late binding of span name via explicit
	// call to SetOperationName when using PerOperationSampler. When this feature is enabled,
	// the sampler will return retryable=true from OnCreateSpan(), thus leaving the sampling
	// decision as non-final (and the span as writeable). This may lead to degraded performance
	// in applications that always provide the correct span name on trace creation.
	//
	// For backwards compatibility this option is off by default.
	OperationNameLateBinding bool `yaml:"operationNameLateBinding"`

	// Options can be used to programmatically pass additional options to the Remote sampler.
	Options []jaeger.SamplerOption
}

SamplerConfig allows initializing a non-default sampler. All fields are optional.

func (*SamplerConfig) NewSampler

func (sc *SamplerConfig) NewSampler(
	serviceName string,
	metrics *jaeger.Metrics,
) (jaeger.Sampler, error)

NewSampler creates a new sampler based on the configuration

type ThrottlerConfig

type ThrottlerConfig struct {
	// HostPort of jaeger-agent's credit server.
	HostPort string `yaml:"hostPort"`

	// RefreshInterval controls how often the throttler will poll jaeger-agent
	// for more throttling credits.
	RefreshInterval time.Duration `yaml:"refreshInterval"`

	// SynchronousInitialization determines whether or not the throttler should
	// synchronously fetch credits from the agent when an operation is seen for
	// the first time. This should be set to true if the client will be used by
	// a short lived service that needs to ensure that credits are fetched
	// upfront such that sampling or throttling occurs.
	SynchronousInitialization bool `yaml:"synchronousInitialization"`
}

ThrottlerConfig configures the throttler which can be used to throttle the rate at which the client may send debug requests.

Jump to

Keyboard shortcuts

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