-
Notifications
You must be signed in to change notification settings - Fork 4
/
tracer.go
73 lines (57 loc) · 2.03 KB
/
tracer.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the MIT License.
// This product includes software developed at Guance Cloud (https://www.guance.com/).
// Copyright 2021-present Guance, Inc.
// Package tracer defined basic trace wraps.
package tracer
import (
"net"
"github.com/GuanceCloud/cliutils/logger"
"gopkg.in/CodapeWild/dd-trace-go.v1/ddtrace/tracer"
)
var log = logger.DefaultSLogger("ddtrace")
type DiscardLogger struct{}
func (*DiscardLogger) Log(msg string) {}
type StdLogger struct{}
func (*StdLogger) Log(msg string) {
log.Debug(msg)
}
type Tracer struct {
Host string `toml:"host" yaml:"host"` // env: DD_AGENT_HOST
Port string `toml:"port" yaml:"port"` // env: DD_TRACE_AGENT_PORT
Service string `toml:"service" yaml:"service"` // env: DD_SERVICE
Version string `toml:"version" yaml:"version"` // env: DD_VERSION
Env string `toml:"env" yaml:"env"` // env: DD_ENV
agentAddr string
LogsStartup bool `toml:"logs_startup" yaml:"logs_startup"` // env: DD_TRACE_STARTUP_LOGS
Debug bool `toml:"debug" yaml:"debug"` // env: DD_TRACE_DEBUG
TraceEnabled bool `toml:"trace_enabled" yaml:"trace_enabled"` // env: DD_TRACE_ENABLED
Tags map[string]interface{} `toml:"tags" yaml:"tags"` // env: DD_TAGS
}
func (t *Tracer) GetStartOptions(opts ...StartOption) []tracer.StartOption {
if t.Tags == nil {
t.Tags = make(map[string]interface{})
}
for i := range opts {
opts[i](t)
}
if t.Host == "" {
t.Host = "127.0.0.1"
}
if t.Port == "" {
t.Port = "9529"
}
t.agentAddr = net.JoinHostPort(t.Host, t.Port)
startOpts := []tracer.StartOption{
tracer.WithAgentAddr(t.agentAddr),
tracer.WithService(t.Service),
tracer.WithServiceVersion(t.Version),
tracer.WithLogStartup(t.LogsStartup),
tracer.WithDebugMode(t.Debug),
tracer.WithEnv(t.Env),
}
for k, v := range t.Tags {
startOpts = append(startOpts, tracer.WithGlobalTag(k, v))
}
return startOpts
}