09078b14e1
* Tracing: Pass OTLP address and propagation format to plugins * Fix unit tests * Fix indentation * Fix plugin manager integration tests * Goimports * Pass plugin version to plugins * Do not add GF_PLUGIN_VERSION if plugin version is not set, add tests * Allow disabling plugins distributed tracing on a per-plugin basis * Moved disabled plugins to tracing.opentelemetry config section * Pre-allocate DisabledPlugins map to the correct size * Moved disable tracing setting flags in plugin settings * Renamed plugin env vars for tracing endpoint and propagation * Fix plugin initializer tests * Refactoring: Moved OpentelemetryCfg from pkg/infra to pkg/plugins * Changed GetSection to Section in parseSettingsOpentelemetry * Add tests for NewOpentelemetryCfg * Fix test case names in TestNewOpentelemetryCfg * OpenTelemetry: Remove redundant error checks
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
const otlpExporter string = "otlp"
|
|
|
|
// OpentelemetryCfg contains the Opentelemetry address and propagation config values.
|
|
// This is used to export the Opentelemetry (OTLP) config without exposing the whole *setting.Cfg.
|
|
type OpentelemetryCfg struct {
|
|
Address string
|
|
Propagation string
|
|
}
|
|
|
|
// IsEnabled returns true if OTLP tracing is enabled (address set)
|
|
func (c OpentelemetryCfg) IsEnabled() bool {
|
|
return c.Address != ""
|
|
}
|
|
|
|
// NewOpentelemetryCfg creates a new OpentelemetryCfg based on the provided Grafana config.
|
|
// If Opentelemetry (OTLP) is disabled, a zero-value OpentelemetryCfg is returned.
|
|
func NewOpentelemetryCfg(grafanaCfg *setting.Cfg) (OpentelemetryCfg, error) {
|
|
ots, err := tracing.ParseSettingsOpentelemetry(grafanaCfg)
|
|
if err != nil {
|
|
return OpentelemetryCfg{}, fmt.Errorf("parse settings: %w", err)
|
|
}
|
|
if ots.Enabled != otlpExporter {
|
|
return OpentelemetryCfg{}, nil
|
|
}
|
|
return OpentelemetryCfg{
|
|
Address: ots.Address,
|
|
Propagation: ots.Propagation,
|
|
}, nil
|
|
}
|