/
types.go
107 lines (91 loc) · 2.9 KB
/
types.go
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package telemetry
import (
"sync"
"time"
"contrib.go.opencensus.io/exporter/prometheus"
"go.opencensus.io/plugin/ochttp/propagation/b3"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace/propagation"
)
// Attributes recorded on the span for the requests.
// Only trace exporters will need them.
const (
HostAttribute = "http.host"
MethodAttribute = "http.method"
PathAttribute = "http.path"
UserAgentAttribute = "http.user_agent"
)
// DefaultFormat used by observability as: observability.DefaultFormat.SpanContextToRequest
var DefaultFormat propagation.HTTPFormat = &b3.HTTPFormat{}
// Configuration is the global tracing configuration
type Configuration struct {
TracingEnabled bool `toml:"tracingEnabled" json:"tracingEnabled"`
Exporters struct {
Jaeger struct {
ServiceName string `toml:"serviceName" default:"" json:"serviceName"`
CollectorEndpoint string `toml:"collectorEndpoint" default:"http://localhost:14268/api/traces" json:"collectorEndpoint"`
SamplingProbability float64 `toml:"samplingProbability" json:"metricSamplingProbability"`
} `json:"jaeger"`
Prometheus struct {
ReporteringPeriod int `toml:"ReporteringPeriod" default:"10" json:"reporteringPeriod"`
} `json:"prometheus"`
} `json:"exporter"`
}
var (
// DefaultSizeDistribution 25k, 100k, 250, 500, 1M, 1.5M, 5M, 10M,
DefaultSizeDistribution = view.Distribution(25*1024, 100*1024, 250*1024, 500*1024, 1024*1024, 1.5*1024*1024, 5*1024*1024, 10*1024*1024)
// DefaultLatencyDistribution 100ms, ...
DefaultLatencyDistribution = view.Distribution(100, 200, 300, 400, 500, 750, 1000, 2000, 5000)
)
const (
Host = "http.host"
StatusCode = "http.status"
Path = "http.path"
Method = "http.method"
Handler = "http.handler"
RequestID = "http.request-id"
)
type ExposedView struct {
Name string `json:"name"`
Description string `json:"description"`
Tags []string `json:"tags"`
Dimension string `json:"dimension"`
Aggregation string `json:"aggregagtion"`
}
type HTTPExporter struct {
*prometheus.Exporter `json:"-"`
ExposedViews []ExposedView `json:"-"`
exposedViewMutex sync.Mutex `json:"-"`
Views []HTTPExporterView
}
type HTTPExporterView struct {
Name string `json:"name"`
Tags map[string]string `json:"tags"`
Value float64 `json:"value"`
Date time.Time `json:"date"`
}
type contextKey int
const (
contextTraceExporter contextKey = iota
contextStatsExporter
)
type Service interface {
Name() string
Type() string
}
// B3 headers that OpenCensus understands.
const (
TraceIDHeader = "X-B3-TraceId"
SpanIDHeader = "X-B3-SpanId"
SampledHeader = "X-B3-Sampled"
ContextTraceIDHeader contextKey = iota
ContextSpanIDHeader
ContextSampledHeader
ContextMainSpan
)
//Options is the options struct for a new tracing span
type Options struct {
Init bool
Name string
SpanKind int
}