config

package
v2.14.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

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 via environment variable named JAEGER_SERVICE_NAME
	ServiceName string `yaml:"serviceName"`

	// Disabled can be provided via environment variable named JAEGER_DISABLED
	Disabled bool `yaml:"disabled"`

	// RPCMetrics can be provided via environment variable named JAEGER_RPC_METRICS
	RPCMetrics bool `yaml:"rpc_metrics"`

	// Tags can be provided via 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) 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"

	"github.com/uber/jaeger-lib/metrics"

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

	jaegerlog "github.com/uber/jaeger-client-go/log"
)

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 recieve 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 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 Observer

func Observer(observer jaeger.Observer) Option

Observer can be registered with the Tracer to receive notifications about new 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 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 set by exporting an 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 set by exporting an 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 set by exporting an 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 set by exporting an environment variable named JAEGER_AGENT_HOST / JAEGER_AGENT_PORT
	LocalAgentHostPort string `yaml:"localAgentHostPort"`
}

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 tcollector

type SamplerConfig

type SamplerConfig struct {
	// Type specifies the type of the sampler: const, probabilistic, rateLimiting, or remote
	// Can be set by exporting an 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 set by exporting an environment variable named JAEGER_SAMPLER_PARAM
	Param float64 `yaml:"param"`

	// SamplingServerURL is the address of jaeger-agent's HTTP sampling server
	// Can be set by exporting an environment variable named JAEGER_SAMPLER_MANAGER_HOST_PORT
	SamplingServerURL string `yaml:"samplingServerURL"`

	// MaxOperations is the maximum number of operations that the sampler
	// 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 set by exporting an environment variable named JAEGER_SAMPLER_MAX_OPERATIONS
	MaxOperations int `yaml:"maxOperations"`

	// SamplingRefreshInterval controls how often the remotely controlled sampler will poll
	// jaeger-agent for the appropriate sampling strategy.
	// Can be set by exporting an environment variable named JAEGER_SAMPLER_REFRESH_INTERVAL
	SamplingRefreshInterval time.Duration `yaml:"samplingRefreshInterval"`
}

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