Plugins: Refactoring: Move plugins tracing env vars to separate func (#66170)

This commit is contained in:
Giuseppe Guerra 2023-04-07 17:11:47 +02:00 committed by GitHub
parent 536fad5b61
commit 652c6dbd22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,25 +67,30 @@ func (i *Initializer) envVars(plugin *plugins.Plugin) []string {
hostEnv = append(hostEnv, i.awsEnvVars()...)
hostEnv = append(hostEnv, i.secureSocksProxyEnvVars()...)
hostEnv = append(hostEnv, azsettings.WriteToEnvStr(i.cfg.Azure)...)
hostEnv = append(hostEnv, i.tracingEnvVars(plugin)...)
// Tracing
ev := getPluginSettings(plugin.ID, i.cfg).asEnvVar("GF_PLUGIN", hostEnv)
return ev
}
func (i *Initializer) tracingEnvVars(plugin *plugins.Plugin) []string {
var pluginTracingEnabled bool
if v, exists := i.cfg.PluginSettings[plugin.ID]["tracing"]; exists {
pluginTracingEnabled = v == "true"
}
if i.cfg.Tracing.IsEnabled() && pluginTracingEnabled {
if plugin.Info.Version != "" {
hostEnv = append(hostEnv, fmt.Sprintf("GF_PLUGIN_VERSION=%s", plugin.Info.Version))
}
hostEnv = append(
hostEnv,
fmt.Sprintf("GF_INSTANCE_OTLP_ADDRESS=%s", i.cfg.Tracing.OpenTelemetry.Address),
fmt.Sprintf("GF_INSTANCE_OTLP_PROPAGATION=%s", i.cfg.Tracing.OpenTelemetry.Propagation),
)
if !i.cfg.Tracing.IsEnabled() || !pluginTracingEnabled {
return nil
}
ev := getPluginSettings(plugin.ID, i.cfg).asEnvVar("GF_PLUGIN", hostEnv)
return ev
var vars []string
if plugin.Info.Version != "" {
vars = append(vars, fmt.Sprintf("GF_PLUGIN_VERSION=%s", plugin.Info.Version))
}
return append(
vars,
fmt.Sprintf("GF_INSTANCE_OTLP_ADDRESS=%s", i.cfg.Tracing.OpenTelemetry.Address),
fmt.Sprintf("GF_INSTANCE_OTLP_PROPAGATION=%s", i.cfg.Tracing.OpenTelemetry.Propagation),
)
}
func (i *Initializer) awsEnvVars() []string {