File: tracer_options.go

package info (click to toggle)
golang-github-go-kit-kit 0.13.0-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,784 kB
  • sloc: sh: 22; makefile: 11
file content (70 lines) | stat: -rw-r--r-- 2,121 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package opencensus

import (
	"go.opencensus.io/plugin/ochttp/propagation/b3"
	"go.opencensus.io/trace"
	"go.opencensus.io/trace/propagation"
)

// defaultHTTPPropagate holds OpenCensus' default HTTP propagation format which
// currently is Zipkin's B3.
var defaultHTTPPropagate propagation.HTTPFormat = &b3.HTTPFormat{}

// TracerOption allows for functional options to our OpenCensus tracing
// middleware.
type TracerOption func(o *TracerOptions)

// WithTracerConfig sets all configuration options at once.
func WithTracerConfig(options TracerOptions) TracerOption {
	return func(o *TracerOptions) {
		*o = options
	}
}

// WithSampler sets the sampler to use by our OpenCensus Tracer.
func WithSampler(sampler trace.Sampler) TracerOption {
	return func(o *TracerOptions) {
		o.Sampler = sampler
	}
}

// WithName sets the name for an instrumented transport endpoint. If name is omitted
// at tracing middleware creation, the method of the transport or transport rpc
// name is used.
func WithName(name string) TracerOption {
	return func(o *TracerOptions) {
		o.Name = name
	}
}

// IsPublic should be set to true for publicly accessible servers and for
// clients that should not propagate their current trace metadata.
// On the server side a new trace will always be started regardless of any
// trace metadata being found in the incoming request. If any trace metadata
// is found, it will be added as a linked trace instead.
func IsPublic(isPublic bool) TracerOption {
	return func(o *TracerOptions) {
		o.Public = isPublic
	}
}

// WithHTTPPropagation sets the propagation handlers for the HTTP transport
// middlewares. If used on a non HTTP transport this is a noop.
func WithHTTPPropagation(p propagation.HTTPFormat) TracerOption {
	return func(o *TracerOptions) {
		if p == nil {
			// reset to default OC HTTP format
			o.HTTPPropagate = defaultHTTPPropagate
			return
		}
		o.HTTPPropagate = p
	}
}

// TracerOptions holds configuration for our tracing middlewares
type TracerOptions struct {
	Sampler       trace.Sampler
	Name          string
	Public        bool
	HTTPPropagate propagation.HTTPFormat
}