Plugins: Use a Grafana specific SDK tracer implementation for core plugins (#75388)

pull/75449/head
Marcus Efraimsson 2 years ago committed by GitHub
parent af3ea54d0e
commit 534e3ebf0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      pkg/api/plugin_resource_test.go
  2. 4
      pkg/infra/tracing/test_helper.go
  3. 7
      pkg/infra/tracing/tracing.go
  4. 8
      pkg/plugins/backendplugin/coreplugin/registry.go
  5. 2
      pkg/services/pluginsintegration/plugins_integration_test.go

@ -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)

Loading…
Cancel
Save