-
Notifications
You must be signed in to change notification settings - Fork 39
/
options.go
111 lines (93 loc) · 3.96 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
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
108
109
110
111
// (c) Copyright IBM Corp. 2021
// (c) Copyright Instana Inc. 2016
package instana
import (
"os"
"strconv"
)
// Options allows the user to configure the to-be-initialized sensor
type Options struct {
// Service is the global service name that will be used to identify the program in the Instana backend
Service string
// AgentHost is the Instana host agent host name
//
// Note: This setting has no effect in serverless environments. To specify the serverless acceptor endpoint,
// INSTANA_ENDPOINT_URL env var. See https://www.instana.com/docs/reference/environment_variables/#serverless-monitoring
// for more details.
AgentHost string
// AgentPort is the Instana host agent port
//
// Note: This setting has no effect in serverless environments. To specify the serverless acceptor endpoint,
// INSTANA_ENDPOINT_URL env var. See https://www.instana.com/docs/reference/environment_variables/#serverless-monitoring
// for more details.
AgentPort int
// MaxBufferedSpans is the maximum number of spans to buffer
MaxBufferedSpans int
// ForceTransmissionStartingAt is the number of spans to collect before flushing the buffer to the agent
ForceTransmissionStartingAt int
// LogLevel is the initial logging level for the logger used by Instana tracer. The valid log levels are
// logger.{Error,Warn,Info,Debug}Level provided by the github.com/instana/go-sensor/logger package.
//
// Note: this setting is only used to initialize the default logger and has no effect if a custom logger is set via instana.SetLogger()
LogLevel int
// EnableAutoProfile enables automatic continuous process profiling when set to true
EnableAutoProfile bool
// MaxBufferedProfiles is the maximum number of profiles to buffer
MaxBufferedProfiles int
// IncludeProfilerFrames is whether to include profiler calls into the profile or not
IncludeProfilerFrames bool
// Tracer contains tracer-specific configuration used by all tracers
Tracer TracerOptions
// AgentClient client to communicate with the agent. In most cases, there is no need to provide it.
// If it is nil the default implementation will be used.
AgentClient AgentClient
// Recorder records and manages spans. When this option is not set, instana.NewRecorder() will be used.
Recorder SpanRecorder
disableW3CTraceCorrelation bool
}
// DefaultOptions returns the default set of options to configure Instana sensor.
// The service name is set to the name of current executable, the MaxBufferedSpans
// and ForceTransmissionStartingAt are set to instana.DefaultMaxBufferedSpans and
// instana.DefaultForceSpanSendAt correspondigly. The AgentHost and AgentPort are
// taken from the env INSTANA_AGENT_HOST and INSTANA_AGENT_PORT if set, and default
// to localhost and 42699 otherwise.
func DefaultOptions() *Options {
opts := &Options{
Tracer: DefaultTracerOptions(),
}
opts.setDefaults()
return opts
}
func (opts *Options) setDefaults() {
if opts.MaxBufferedSpans == 0 {
opts.MaxBufferedSpans = DefaultMaxBufferedSpans
}
if opts.ForceTransmissionStartingAt == 0 {
opts.ForceTransmissionStartingAt = DefaultForceSpanSendAt
}
if opts.AgentHost == "" {
opts.AgentHost = agentDefaultHost
if host := os.Getenv("INSTANA_AGENT_HOST"); host != "" {
opts.AgentHost = host
}
}
if opts.AgentPort == 0 {
opts.AgentPort = agentDefaultPort
if port, err := strconv.Atoi(os.Getenv("INSTANA_AGENT_PORT")); err == nil {
opts.AgentPort = port
}
}
secretsMatcher, err := parseInstanaSecrets(os.Getenv("INSTANA_SECRETS"))
if err != nil {
defaultLogger.Warn("invalid INSTANA_SECRETS= env variable value: ", err, ", ignoring")
secretsMatcher = opts.Tracer.Secrets
}
if secretsMatcher == nil {
secretsMatcher = DefaultSecretsMatcher()
}
opts.Tracer.Secrets = secretsMatcher
if collectableHeaders, ok := os.LookupEnv("INSTANA_EXTRA_HTTP_HEADERS"); ok {
opts.Tracer.CollectableHTTPHeaders = parseInstanaExtraHTTPHeaders(collectableHeaders)
}
opts.disableW3CTraceCorrelation = os.Getenv("INSTANA_DISABLE_W3C_TRACE_CORRELATION") != ""
}