Skip to content

Commit

Permalink
Merge pull request #81 from instana/pass_service_name_via_env_var
Browse files Browse the repository at this point in the history
Allow to configure service name via an env variable
  • Loading branch information
Andrew Slotin authored Feb 7, 2020
2 parents eb476ac + 40ab144 commit fdb2ce0
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -44,11 +44,12 @@ func (r *sensorS) setOptions(options *Options) {
}
}

func (r *sensorS) getOptions() *Options {
return r.options
}

func (r *sensorS) configureServiceName() {
if name, ok := os.LookupEnv("INSTANA_SERVICE_NAME"); ok {
r.serviceName = name
return
}

if r.options != nil {
r.serviceName = r.options.Service
}
Expand All @@ -58,19 +59,22 @@ 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 {
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")
}

0 comments on commit fdb2ce0

Please sign in to comment.