mirror of https://github.com/grafana/grafana
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 checkspull/65663/head
parent
55947cee8f
commit
09078b14e1
@ -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 |
||||
} |
@ -0,0 +1,50 @@ |
||||
package config |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"github.com/grafana/grafana/pkg/setting" |
||||
"github.com/stretchr/testify/assert" |
||||
"github.com/stretchr/testify/require" |
||||
) |
||||
|
||||
func TestNewOpentelemetryCfg(t *testing.T) { |
||||
t.Run("empty", func(t *testing.T) { |
||||
cfg := setting.NewCfg() |
||||
|
||||
otelCfg, err := NewOpentelemetryCfg(cfg) |
||||
require.NoError(t, err) |
||||
assert.False(t, otelCfg.IsEnabled(), "otel should be disabled") |
||||
assert.Empty(t, otelCfg.Address) |
||||
assert.Empty(t, otelCfg.Propagation) |
||||
}) |
||||
|
||||
t.Run("enabled", func(t *testing.T) { |
||||
for _, tc := range []struct { |
||||
name string |
||||
propagation string |
||||
}{ |
||||
{"empty", ""}, |
||||
{"jaeger", "jaeger"}, |
||||
{"w3c", "w3c"}, |
||||
{"multiple", "jaeger,w3c"}, |
||||
} { |
||||
t.Run(tc.name, func(t *testing.T) { |
||||
const address = "127.0.0.1:4317" |
||||
|
||||
cfg := setting.NewCfg() |
||||
otlpSect := cfg.Raw.Section("tracing.opentelemetry.otlp") |
||||
otlpSect.Key("address").SetValue(address) |
||||
if tc.propagation != "" { |
||||
otlpSect.Key("propagation").SetValue(tc.propagation) |
||||
} |
||||
|
||||
otelCfg, err := NewOpentelemetryCfg(cfg) |
||||
require.NoError(t, err) |
||||
assert.True(t, otelCfg.IsEnabled(), "otel should be enabled") |
||||
assert.Equal(t, address, otelCfg.Address) |
||||
assert.Equal(t, tc.propagation, otelCfg.Propagation) |
||||
}) |
||||
} |
||||
}) |
||||
} |
Loading…
Reference in new issue