tracing

package module
v0.0.0-...-c495ead Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

README

Configuring tracing in your application

This package can be used to configure tracing in your application which is compatible with Istio and Aspen Mesh. It sets the global opentracing tracer which can be used by applications to propagate tracing headers or create new spans.

import (
  "log"

  "github.com/spf13/cobra"
  "github.com/spf13/viper"

  "github.com/aspenmesh/tracing-go"
)

func setupTracing() {
	// Configure Tracing
	tOpts := &tracing.Options{
		ZipkinURL:     viper.GetString("trace_zipkin_url"),
		JaegerURL:     viper.GetString("trace_jaeger_url"),
		LogTraceSpans: viper.GetBool("trace_log_spans"),
	}
	if err := tOpts.Validate(); err != nil {
		log.Fatal("Invalid options for tracing: ", err)
	}
	var tracer io.Closer
	if tOpts.TracingEnabled() {
		tracer, err = tracing.Configure("myapp", tOpts)
		if err != nil {
			tracer.Close()
			log.Fatal("Failed to configure tracing: ", err)
		} else {
			defer tracer.Close()
		}
	}
}

Note that most of this package is derived from the Istio tracing package.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachCobraFlags

func AttachCobraFlags(cmd *cobra.Command)

AttachCobraFlags attaches a set of Cobra flags to the given Cobra command.

This command attaches the necessary set of flags to expose a CLI to let the user control all tracing options.

func Configure

func Configure(serviceName string, options *Options) (io.Closer, error)

Configure initializes Istio's tracing subsystem.

You typically call this once at process startup. Once this call returns, the tracing system is ready to accept data.

Types

type Options

type Options struct {
	// URL of zipkin collector (example: 'http://zipkin:9411/api/v1/spans'). This enables tracing for Mixer itself.
	ZipkinURL string

	// URL of jaeger HTTP collector (example: 'http://jaeger:14268/api/traces?format=jaeger.thrift'). This enables tracing for Mixer itself.
	JaegerURL string

	// Whether or not to emit trace spans as log records.
	LogTraceSpans bool
}

Options defines the set of options supported by Istio's component tracing package.

func (*Options) TracingEnabled

func (o *Options) TracingEnabled() bool

TracingEnabled returns whether the given options enable tracing to take place.

func (*Options) Validate

func (o *Options) Validate() error

Validate returns whether the options have been configured correctly or an error

Jump to

Keyboard shortcuts

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