github.com/mier85/go-sensor@v1.30.1-0.20220920111756-9bf41b3bc7e0/options.go (about) 1 // (c) Copyright IBM Corp. 2021 2 // (c) Copyright Instana Inc. 2016 3 4 package instana 5 6 import ( 7 "os" 8 "strconv" 9 ) 10 11 // Options allows the user to configure the to-be-initialized sensor 12 type Options struct { 13 // Service is the global service name that will be used to identify the program in the Instana backend 14 Service string 15 // AgentHost is the Instana host agent host name 16 // 17 // Note: This setting has no effect in serverless environments. To specify the serverless acceptor endpoint, 18 // INSTANA_ENDPOINT_URL env var. See https://www.instana.com/docs/reference/environment_variables/#serverless-monitoring 19 // for more details. 20 AgentHost string 21 // AgentPort is the Instana host agent port 22 // 23 // Note: This setting has no effect in serverless environments. To specify the serverless acceptor endpoint, 24 // INSTANA_ENDPOINT_URL env var. See https://www.instana.com/docs/reference/environment_variables/#serverless-monitoring 25 // for more details. 26 AgentPort int 27 // MaxBufferedSpans is the maximum number of spans to buffer 28 MaxBufferedSpans int 29 // ForceTransmissionStartingAt is the number of spans to collect before flushing the buffer to the agent 30 ForceTransmissionStartingAt int 31 // LogLevel is the initial logging level for the logger used by Instana tracer. The valid log levels are 32 // logger.{Error,Warn,Info,Debug}Level provided by the github.com/mier85/go-sensor/logger package. 33 // 34 // Note: this setting is only used to initialize the default logger and has no effect if a custom logger is set via instana.SetLogger() 35 LogLevel int 36 // EnableAutoProfile enables automatic continuous process profiling when set to true 37 EnableAutoProfile bool 38 // MaxBufferedProfiles is the maximum number of profiles to buffer 39 MaxBufferedProfiles int 40 // IncludeProfilerFrames is whether to include profiler calls into the profile or not 41 IncludeProfilerFrames bool 42 // Tracer contains tracer-specific configuration used by all tracers 43 Tracer TracerOptions 44 45 disableW3CTraceCorrelation bool 46 } 47 48 // DefaultOptions returns the default set of options to configure Instana sensor. 49 // The service name is set to the name of current executable, the MaxBufferedSpans 50 // and ForceTransmissionStartingAt are set to instana.DefaultMaxBufferedSpans and 51 // instana.DefaultForceSpanSendAt correspondigly. The AgentHost and AgentPort are 52 // taken from the env INSTANA_AGENT_HOST and INSTANA_AGENT_PORT if set, and default 53 // to localhost and 42699 otherwise. 54 func DefaultOptions() *Options { 55 opts := &Options{ 56 Tracer: DefaultTracerOptions(), 57 } 58 opts.setDefaults() 59 60 return opts 61 } 62 63 func (opts *Options) setDefaults() { 64 if opts.MaxBufferedSpans == 0 { 65 opts.MaxBufferedSpans = DefaultMaxBufferedSpans 66 } 67 68 if opts.ForceTransmissionStartingAt == 0 { 69 opts.ForceTransmissionStartingAt = DefaultForceSpanSendAt 70 } 71 72 if opts.AgentHost == "" { 73 opts.AgentHost = agentDefaultHost 74 75 if host := os.Getenv("INSTANA_AGENT_HOST"); host != "" { 76 opts.AgentHost = host 77 } 78 } 79 80 if opts.AgentPort == 0 { 81 opts.AgentPort = agentDefaultPort 82 83 if port, err := strconv.Atoi(os.Getenv("INSTANA_AGENT_PORT")); err == nil { 84 opts.AgentPort = port 85 } 86 } 87 88 secretsMatcher, err := parseInstanaSecrets(os.Getenv("INSTANA_SECRETS")) 89 if err != nil { 90 defaultLogger.Warn("invalid INSTANA_SECRETS= env variable value: ", err, ", ignoring") 91 secretsMatcher = opts.Tracer.Secrets 92 } 93 94 if secretsMatcher == nil { 95 secretsMatcher = DefaultSecretsMatcher() 96 } 97 98 opts.Tracer.Secrets = secretsMatcher 99 100 if collectableHeaders, ok := os.LookupEnv("INSTANA_EXTRA_HTTP_HEADERS"); ok { 101 opts.Tracer.CollectableHTTPHeaders = parseInstanaExtraHTTPHeaders(collectableHeaders) 102 } 103 104 opts.disableW3CTraceCorrelation = os.Getenv("INSTANA_DISABLE_W3C_TRACE_CORRELATION") != "" 105 }