zipkin

package
v2.21.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

README

Zipkin compatibility features

NewZipkinB3HTTPHeaderPropagator()

Adds support for injecting and extracting Zipkin B3 Propagation HTTP headers, for use with other Zipkin collectors.


// ...
import (
	opentracing "github.com/opentracing/opentracing-go"
	jaeger "github.com/uber/jaeger-client-go"
	"github.com/uber/jaeger-client-go/zipkin"
)

func main() {
	// ...

	zipkinPropagator := zipkin.NewZipkinB3HTTPHeaderPropagator()
	injector := jaeger.TracerOptions.Injector(opentracing.HTTPHeaders, zipkinPropagator)
	extractor := jaeger.TracerOptions.Extractor(opentracing.HTTPHeaders, zipkinPropagator)

	// Zipkin shares span ID between client and server spans; it must be enabled via the following option.
	zipkinSharedRPCSpan := jaeger.TracerOptions.ZipkinSharedRPCSpan(true)

	// create Jaeger tracer
	tracer, closer := jaeger.NewTracer(
		"myService",
		mySampler, // as usual
		myReporter // as usual
		injector,
		extractor,
		zipkinSharedRPCSpan,
	)

	opentracing.SetGlobalTracer(tracer)

    // continue main()
}

If you'd like to follow the official guides from https://godoc.org/github.com/uber/jaeger-client-go/config#example-Configuration-InitGlobalTracer-Production, here is an example.

import (
	"time"

	opentracing "github.com/opentracing/opentracing-go"
	"github.com/uber/jaeger-client-go"
	jaegerClientConfig "github.com/uber/jaeger-client-go/config"
	"github.com/uber/jaeger-client-go/zipkin"
	"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
	 
	// Zipkin shares span ID between client and server spans; it must be enabled via the following option.
	zipkinPropagator := zipkin.NewZipkinB3HTTPHeaderPropagator()
	 
	// Create tracer and then initialize global tracer
	closer, err := cfg.InitGlobalTracer(
	  serviceName,
	  jaegercfg.Logger(jLogger),
	  jaegercfg.Metrics(jMetricsFactory),
	  jaegercfg.Injector(opentracing.HTTPHeaders, zipkinPropagator),
	  jaegercfg.Extractor(opentracing.HTTPHeaders, zipkinPropagator),
	  jaegercfg.ZipkinSharedRPCSpan(true),
	)
	
	if err != nil {
	    log.Printf("Could not initialize jaeger tracer: %s", err.Error())
	    return
	}
	defer closer.Close()
	
	// continue main()
}

Documentation

Overview

Package zipkin comprises Zipkin functionality for Zipkin compatibility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(propagator *Propagator)

Option is a function that sets an option on Propagator

func BaggagePrefix

func BaggagePrefix(prefix string) Option

BaggagePrefix is a function that sets baggage prefix on Propagator

type Propagator

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

Propagator is an Injector and Extractor

func NewZipkinB3HTTPHeaderPropagator

func NewZipkinB3HTTPHeaderPropagator(opts ...Option) Propagator

NewZipkinB3HTTPHeaderPropagator creates a Propagator for extracting and injecting Zipkin HTTP B3 headers into SpanContexts. Baggage is by default enabled and uses prefix 'baggage-'.

func (Propagator) Extract

func (p Propagator) Extract(abstractCarrier interface{}) (jaeger.SpanContext, error)

Extract conforms to the Extractor interface for encoding Zipkin HTTP B3 headers

func (Propagator) Inject

func (p Propagator) Inject(
	sc jaeger.SpanContext,
	abstractCarrier interface{},
) error

Inject conforms to the Injector interface for decoding Zipkin HTTP B3 headers

Jump to

Keyboard shortcuts

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