Plugins: Support for distributed tracing in backend plugins SDK (#63714)

* 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
This commit is contained in:
Giuseppe Guerra
2023-03-30 23:31:14 +02:00
committed by GitHub
parent 55947cee8f
commit 09078b14e1
11 changed files with 327 additions and 50 deletions

View File

@ -0,0 +1,38 @@
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
}