Update deprecated otel functions

Use new `noop.NewTracerProvider` function.

Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
SuperQ 2023-12-07 15:50:21 +01:00
parent 9e90b90eb3
commit d91ebffb30
No known key found for this signature in database
GPG key ID: C646B23C9E3245F1
2 changed files with 5 additions and 4 deletions

View file

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

View file

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