-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
69 lines (58 loc) · 2.2 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
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
// Copyright 2022 Outreach Corporation. All Rights Reserved.
// Description: This file implements configuration types and helpers for
// configuring tracing.
package trace
import (
"github.com/getoutreach/gobox/pkg/cfg"
)
// Config is the tracing config that gets read from trace.yaml
type Config struct {
Otel `yaml:"OpenTelemetry"`
LogFile LogFile `yaml:"LogFile"`
GlobalTags `yaml:"GlobalTags,omitempty"`
// LogCallByDefault determines info logs for non-error instances of
// `trace.StartCall`. The behavior can be overridden by providing
// explicit options to specific `trace.StartCall` invocations. A
// `trace.StartCall` that ends in an error will always be logged.
LogCallsByDefault bool `yaml:"LogCallsByDefault"`
}
// GlobalTags are tags that get included with every span
type GlobalTags struct {
DevEmail string `yaml:"DevEmail,omitempty"`
}
// MarshalLog ensures that GlobalTags have a valid value included
func (g *GlobalTags) MarshalLog(addField func(key string, v interface{})) {
if g.DevEmail != "" {
addField("dev.email", g.DevEmail)
}
}
// Otel is the configuration for OpenTelemetry based tracing
type Otel struct {
// Enabled determines whether to turn on tracing
Enabled bool `yaml:"Enabled"`
// Endpoint for the tracing backend
Endpoint string `yaml:"Endpoint"`
// CollectorEndpoint endpoint for the opentelemetry collector for tracing
CollectorEndpoint string `yaml:"CollectorEndpoint"`
// Dataset the honeycomb grouping of traces
Dataset string `yaml:"Dataset"`
// SamplePercent the rate at which to sample
SamplePercent float64 `yaml:"SamplePercent"`
// Debug allows printing debug statements for traces
Debug bool `yaml:"Debug"`
// Stdout also outputs traces to stdout
Stdout bool `yaml:"Stdout"`
// APIKey used for authentication with the backend at Endpoint
APIKey cfg.Secret `yaml:"APIKey"`
}
// LogFile is the configuration for log file based tracing
type LogFile struct {
// Enabled determines whether to turn on tracing to a log file
Enabled bool `yaml:"Enabled"`
// Port is the port used by the the logfile trace server
Port int `yaml:"Port"`
}
// Load loads the configuration from trace.yaml
func (c *Config) Load() error {
return cfg.Load("trace.yaml", c)
}