/
options.go
78 lines (61 loc) · 1.26 KB
/
options.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
package datadog
import (
"net"
"os"
"github.com/americanas-go/config"
"github.com/jvitoroc/ignite/net/http/client"
)
type Options struct {
Service string
Env string
Enabled bool
Tags map[string]string
Host string
Port string
LambdaMode bool
Analytics bool
AnalyticsRate float64
DebugMode bool
DebugStack bool
HttpClient client.Options
Version string
Log struct {
Level string
}
Addr string
}
func NewOptionsWithPath(path string) (opts *Options, err error) {
opts, err = NewOptions()
if err != nil {
return nil, err
}
err = config.UnmarshalWithPath(path, opts)
if err != nil {
return nil, err
}
return opts, nil
}
func NewOptions() (*Options, error) {
opts := &Options{}
err := config.UnmarshalWithPath(root, opts)
if err != nil {
return nil, err
}
if v := os.Getenv("DD_SERVICE"); v != "" {
opts.Service = v
}
if v := os.Getenv("DD_AGENT_HOST"); v != "" {
opts.Host = v
}
if v := os.Getenv("DD_TRACE_AGENT_PORT"); v != "" {
opts.Port = v
}
if v := os.Getenv("DD_ENV"); v != "" {
opts.Env = v
}
if v := os.Getenv("DD_VERSION"); v != "" {
opts.Version = v
}
opts.Addr = net.JoinHostPort(opts.Host, opts.Port)
return opts, nil
}