Plugins: Use a Grafana specific SDK tracer implementation for core plugins (#75388)
This commit is contained in:
@@ -49,7 +49,7 @@ func TestCallResource(t *testing.T) {
|
||||
}
|
||||
cfg.Azure = &azsettings.AzureSettings{}
|
||||
|
||||
coreRegistry := coreplugin.ProvideCoreRegistry(nil, &cloudwatch.CloudWatchService{}, nil, nil, nil, nil,
|
||||
coreRegistry := coreplugin.ProvideCoreRegistry(tracing.InitializeTracerForTest(), nil, &cloudwatch.CloudWatchService{}, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, testdatasource.ProvideService(), nil, nil, nil, nil, nil, nil)
|
||||
|
||||
textCtx := pluginsintegration.CreateIntegrationTestCtx(t, cfg, coreRegistry)
|
||||
|
||||
@@ -114,6 +114,10 @@ func (t *FakeTracer) Start(ctx context.Context, spanName string, opts ...trace.S
|
||||
func (t *FakeTracer) Inject(ctx context.Context, header http.Header, span Span) {
|
||||
}
|
||||
|
||||
func (t *FakeTracer) OtelTracer() trace.Tracer {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewFakeTracer() *FakeTracer {
|
||||
return &FakeTracer{Spans: []*FakeSpan{}}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,9 @@ type Tracer interface {
|
||||
// Both the context and span must be derived from the same call to
|
||||
// [Tracer.Start].
|
||||
Inject(context.Context, http.Header, Span)
|
||||
|
||||
// OtelTracer returns the trace.Tracer if available or nil.
|
||||
OtelTracer() trace.Tracer
|
||||
}
|
||||
|
||||
// Span defines a time range for an operation. This is equivalent to a
|
||||
@@ -492,6 +495,10 @@ func (ots *Opentelemetry) Inject(ctx context.Context, header http.Header, _ Span
|
||||
otel.GetTextMapPropagator().Inject(ctx, propagation.HeaderCarrier(header))
|
||||
}
|
||||
|
||||
func (ots *Opentelemetry) OtelTracer() trace.Tracer {
|
||||
return ots.tracer
|
||||
}
|
||||
|
||||
func (s OpentelemetrySpan) End() {
|
||||
s.span.End()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ import (
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
sdklog "github.com/grafana/grafana-plugin-sdk-go/backend/log"
|
||||
sdktracing "github.com/grafana/grafana-plugin-sdk-go/backend/tracing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||
"github.com/grafana/grafana/pkg/plugins/log"
|
||||
@@ -81,10 +83,14 @@ func NewRegistry(store map[string]backendplugin.PluginFactoryFunc) *Registry {
|
||||
}
|
||||
}
|
||||
|
||||
func ProvideCoreRegistry(am *azuremonitor.Service, cw *cloudwatch.CloudWatchService, cm *cloudmonitoring.Service,
|
||||
func ProvideCoreRegistry(tracer tracing.Tracer, am *azuremonitor.Service, cw *cloudwatch.CloudWatchService, cm *cloudmonitoring.Service,
|
||||
es *elasticsearch.Service, grap *graphite.Service, idb *influxdb.Service, lk *loki.Service, otsdb *opentsdb.Service,
|
||||
pr *prometheus.Service, t *tempo.Service, td *testdatasource.Service, pg *postgres.Service, my *mysql.Service,
|
||||
ms *mssql.Service, graf *grafanads.Service, pyroscope *pyroscope.Service, parca *parca.Service) *Registry {
|
||||
if otelTracer := tracer.OtelTracer(); otelTracer != nil {
|
||||
sdktracing.InitDefaultTracer(otelTracer)
|
||||
}
|
||||
|
||||
return NewRegistry(map[string]backendplugin.PluginFactoryFunc{
|
||||
CloudWatch: asBackendPlugin(cw.Executor),
|
||||
CloudMonitoring: asBackendPlugin(cm),
|
||||
|
||||
@@ -97,7 +97,7 @@ func TestIntegrationPluginManager(t *testing.T) {
|
||||
graf := grafanads.ProvideService(sv2, nil)
|
||||
pyroscope := pyroscope.ProvideService(hcp, acimpl.ProvideAccessControl(cfg))
|
||||
parca := parca.ProvideService(hcp)
|
||||
coreRegistry := coreplugin.ProvideCoreRegistry(am, cw, cm, es, grap, idb, lk, otsdb, pr, tmpo, td, pg, my, ms, graf, pyroscope, parca)
|
||||
coreRegistry := coreplugin.ProvideCoreRegistry(tracing.InitializeTracerForTest(), am, cw, cm, es, grap, idb, lk, otsdb, pr, tmpo, td, pg, my, ms, graf, pyroscope, parca)
|
||||
|
||||
testCtx := CreateIntegrationTestCtx(t, cfg, coreRegistry)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user