From 44ab1028ce52866832ef9c39a0d567d2167c2ebe Mon Sep 17 00:00:00 2001 From: Andrey Slotin Date: Wed, 5 Feb 2020 13:57:00 +0100 Subject: [PATCH 1/5] Fix typos in code comments --- sensor.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sensor.go b/sensor.go index d40785df1..dcdc3fd11 100644 --- a/sensor.go +++ b/sensor.go @@ -20,7 +20,7 @@ type sensorS struct { var sensor *sensorS func (r *sensorS) init(options *Options) { - //sensor can be initialized explicit or implicit through OpenTracing global init + // sensor can be initialized explicitly or implicitly through OpenTracing global init if r.meter == nil { r.setOptions(options) r.configureServiceName() @@ -58,7 +58,7 @@ func (r *sensorS) configureServiceName() { } } -// InitSensor Intializes the sensor (without tracing) to begin collecting +// InitSensor intializes the sensor (without tracing) to begin collecting // and reporting metrics. func InitSensor(options *Options) { if sensor == nil { From f3b35a5e88abfdfd163e83a5df3f0ec481bbd5be Mon Sep 17 00:00:00 2001 From: Andrey Slotin Date: Wed, 5 Feb 2020 13:57:19 +0100 Subject: [PATCH 2/5] Return early from instana.InitSensor() if sensor has already been initialized --- sensor.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/sensor.go b/sensor.go index dcdc3fd11..59a241929 100644 --- a/sensor.go +++ b/sensor.go @@ -61,16 +61,19 @@ func (r *sensorS) configureServiceName() { // InitSensor intializes the sensor (without tracing) to begin collecting // and reporting metrics. func InitSensor(options *Options) { - if sensor == nil { - sensor = new(sensorS) - // If this environment variable is set, then override log level - _, ok := os.LookupEnv("INSTANA_DEBUG") - if ok { - options.LogLevel = Debug - } + if sensor != nil { + return + } + + sensor = &sensorS{} - sensor.initLog() - sensor.init(options) - log.debug("initialized sensor") + // If this environment variable is set, then override log level + _, ok := os.LookupEnv("INSTANA_DEBUG") + if ok { + options.LogLevel = Debug } + + sensor.initLog() + sensor.init(options) + log.debug("initialized sensor") } From 9176d36bfedaf33c9025c2c16adf1fc2916d6c4b Mon Sep 17 00:00:00 2001 From: Andrey Slotin Date: Wed, 5 Feb 2020 13:59:42 +0100 Subject: [PATCH 3/5] Remove unused options getter from instana.Sensor --- sensor.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sensor.go b/sensor.go index 59a241929..14a1d792a 100644 --- a/sensor.go +++ b/sensor.go @@ -44,10 +44,6 @@ func (r *sensorS) setOptions(options *Options) { } } -func (r *sensorS) getOptions() *Options { - return r.options -} - func (r *sensorS) configureServiceName() { if r.options != nil { r.serviceName = r.options.Service From cdd70111bfa6f1101c9017216548e2a87b02307e Mon Sep 17 00:00:00 2001 From: Andrey Slotin Date: Wed, 5 Feb 2020 14:33:57 +0100 Subject: [PATCH 4/5] Use the value of INSTANA_SERVICE_NAME env var as a default service name Allow to configure the service name via env variable instead of falling back to the binary name immediately. --- sensor.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sensor.go b/sensor.go index 14a1d792a..99d3fae05 100644 --- a/sensor.go +++ b/sensor.go @@ -49,6 +49,10 @@ func (r *sensorS) configureServiceName() { r.serviceName = r.options.Service } + if r.serviceName == "" { + r.serviceName = os.Getenv("INSTANA_SERVICE_NAME") + } + if r.serviceName == "" { r.serviceName = filepath.Base(os.Args[0]) } From 40ab14401a470f3939a3e400c7bc3ce8ccf8f716 Mon Sep 17 00:00:00 2001 From: Andrey Slotin Date: Wed, 5 Feb 2020 15:43:15 +0100 Subject: [PATCH 5/5] Prioritize service name passed through the env over the Options configuration --- sensor.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sensor.go b/sensor.go index 99d3fae05..afda3bab8 100644 --- a/sensor.go +++ b/sensor.go @@ -45,12 +45,13 @@ func (r *sensorS) setOptions(options *Options) { } func (r *sensorS) configureServiceName() { - if r.options != nil { - r.serviceName = r.options.Service + if name, ok := os.LookupEnv("INSTANA_SERVICE_NAME"); ok { + r.serviceName = name + return } - if r.serviceName == "" { - r.serviceName = os.Getenv("INSTANA_SERVICE_NAME") + if r.options != nil { + r.serviceName = r.options.Service } if r.serviceName == "" {