traefik/pkg/tracing/instana/instana.go

62 lines
2.1 KiB
Go
Raw Normal View History

2019-02-18 15:52:04 +00:00
package instana
import (
"io"
2019-03-04 15:40:05 +00:00
instana "github.com/instana/go-sensor"
2019-02-18 15:52:04 +00:00
"github.com/opentracing/opentracing-go"
2022-11-21 17:36:05 +00:00
"github.com/rs/zerolog/log"
2023-02-03 14:24:05 +00:00
"github.com/traefik/traefik/v3/pkg/logs"
2019-02-18 15:52:04 +00:00
)
2020-05-11 10:06:07 +00:00
// Name sets the name of this tracer.
2019-02-18 15:52:04 +00:00
const Name = "instana"
// Config provides configuration settings for an instana tracer.
2019-02-18 15:52:04 +00:00
type Config struct {
LocalAgentHost string `description:"Sets the Instana Agent host." json:"localAgentHost,omitempty" toml:"localAgentHost,omitempty" yaml:"localAgentHost,omitempty"`
LocalAgentPort int `description:"Sets the Instana Agent port." json:"localAgentPort,omitempty" toml:"localAgentPort,omitempty" yaml:"localAgentPort,omitempty"`
LogLevel string `description:"Sets the log level for the Instana tracer. ('error','warn','info','debug')" json:"logLevel,omitempty" toml:"logLevel,omitempty" yaml:"logLevel,omitempty" export:"true"`
EnableAutoProfile bool `description:"Enables automatic profiling for the Traefik process." json:"enableAutoProfile,omitempty" toml:"enableAutoProfile,omitempty" yaml:"enableAutoProfile,omitempty" export:"true"`
2019-02-18 15:52:04 +00:00
}
// SetDefaults sets the default values.
func (c *Config) SetDefaults() {
c.LocalAgentPort = 42699
c.LogLevel = "info"
}
2020-05-11 10:06:07 +00:00
// Setup sets up the tracer.
2019-02-18 15:52:04 +00:00
func (c *Config) Setup(serviceName string) (opentracing.Tracer, io.Closer, error) {
// set default logLevel
logLevel := instana.Info
// check/set logLevel overrides
switch c.LogLevel {
case "error":
logLevel = instana.Error
case "warn":
logLevel = instana.Warn
case "debug":
logLevel = instana.Debug
}
2022-11-21 17:36:05 +00:00
logger := log.With().Str(logs.TracingProviderName, Name).Logger()
instana.SetLogger(logs.NewInstanaLogger(logger))
2019-02-18 15:52:04 +00:00
tracer := instana.NewTracerWithOptions(&instana.Options{
Service: serviceName,
LogLevel: logLevel,
AgentPort: c.LocalAgentPort,
AgentHost: c.LocalAgentHost,
EnableAutoProfile: c.EnableAutoProfile,
2019-02-18 15:52:04 +00:00
})
// Without this, child spans are getting the NOOP tracer
opentracing.SetGlobalTracer(tracer)
2022-11-21 17:36:05 +00:00
logger.Debug().Msg("Instana tracer configured")
2019-02-18 15:52:04 +00:00
return tracer, nil, nil
}