Browse Source

Update deprecated otel functions

Use new `noop.NewTracerProvider` function.

Signed-off-by: SuperQ <superq@gmail.com>
pull/13236/head
SuperQ 12 months ago
parent
commit
d91ebffb30
No known key found for this signature in database
GPG Key ID: C646B23C9E3245F1
  1. 3
      tracing/tracing.go
  2. 6
      tracing/tracing_test.go

3
tracing/tracing.go

@ -32,6 +32,7 @@ import (
tracesdk "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
"google.golang.org/grpc/credentials"
"github.com/prometheus/prometheus/config"
@ -87,7 +88,7 @@ func (m *Manager) ApplyConfig(cfg *config.Config) error {
if cfg.TracingConfig.Endpoint == "" {
m.config = cfg.TracingConfig
m.shutdownFunc = nil
otel.SetTracerProvider(trace.NewNoopTracerProvider())
otel.SetTracerProvider(noop.NewTracerProvider())
level.Info(m.logger).Log("msg", "Tracing provider uninstalled.")
return nil
}

6
tracing/tracing_test.go

@ -20,7 +20,7 @@ import (
config_util "github.com/prometheus/common/config"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
"github.com/prometheus/prometheus/config"
)
@ -105,7 +105,7 @@ func TestUninstallingTracerProvider(t *testing.T) {
}
require.NoError(t, m.ApplyConfig(&cfg))
require.NotEqual(t, trace.NewNoopTracerProvider(), otel.GetTracerProvider())
require.NotEqual(t, noop.NewTracerProvider(), otel.GetTracerProvider())
// Uninstall by passing empty config.
cfg2 := config.Config{
@ -114,7 +114,7 @@ func TestUninstallingTracerProvider(t *testing.T) {
require.NoError(t, m.ApplyConfig(&cfg2))
// Make sure we get a no-op tracer provider after uninstallation.
require.Equal(t, trace.NewNoopTracerProvider(), otel.GetTracerProvider())
require.Equal(t, noop.NewTracerProvider(), otel.GetTracerProvider())
}
func TestTracerProviderShutdown(t *testing.T) {

Loading…
Cancel
Save