-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.go
43 lines (38 loc) · 1.11 KB
/
config.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
package trace
import (
"strings"
"time"
"contrib.go.opencensus.io/exporter/stackdriver"
"github.com/rs/zerolog/log"
"go.opencensus.io/trace"
)
var defaultProbabilitySample float64
// Config represents the informations that must be
// set to configure the trace
type Config struct {
Exporter string `default:""`
ProbabilitySample float64 `default:"0"`
Stackdriver struct {
ProjectID string
}
}
// SetupTrace configure a trace exporter, defined in @c
func SetupTrace(c Config) {
switch exporter := strings.ToLower(c.Exporter); exporter {
case "stackdriver":
start := time.Now()
stackdriverExporter, err := stackdriver.NewExporter(stackdriver.Options{
ProjectID: c.Stackdriver.ProjectID,
BundleCountThreshold: 100,
})
if err != nil {
log.Fatal().Err(err).Msg("Failed to create stackdriver trace exporter")
}
trace.RegisterExporter(stackdriverExporter)
log.Info().Dur("took", time.Since(start)).Msg("Stackdriver loaded")
case "":
default:
log.Fatal().Str("exporter", exporter).Msg("This exporter is not supported")
}
defaultProbabilitySample = c.ProbabilitySample
}