1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-28 06:29:29 +01:00

tracing: test for semconv/SDK version conflicts

This commit is contained in:
Luke Carrier
2025-01-22 21:11:45 +00:00
parent 1a49e116df
commit 9c6604fc51
2 changed files with 22 additions and 1 deletions

View File

@@ -121,7 +121,7 @@ func NewTracerProvider(ctx context.Context, endpoint, caCert, name, namespace st
klog.V(5).InfoS("no name provided, using default service name for tracing", "name", DefaultServiceName) klog.V(5).InfoS("no name provided, using default service name for tracing", "name", DefaultServiceName)
name = DefaultServiceName name = DefaultServiceName
} }
resourceOpts := []sdkresource.Option{sdkresource.WithAttributes(semconv.ServiceNameKey.String(name)), sdkresource.WithSchemaURL(semconv.SchemaURL), sdkresource.WithProcess()} resourceOpts := defaultResourceOpts(name)
if namespace != "" { if namespace != "" {
resourceOpts = append(resourceOpts, sdkresource.WithAttributes(semconv.ServiceNamespaceKey.String(namespace))) resourceOpts = append(resourceOpts, sdkresource.WithAttributes(semconv.ServiceNamespaceKey.String(namespace)))
} }
@@ -141,6 +141,10 @@ func NewTracerProvider(ctx context.Context, endpoint, caCert, name, namespace st
return return
} }
func defaultResourceOpts(name string) []sdkresource.Option {
return []sdkresource.Option{sdkresource.WithAttributes(semconv.ServiceNameKey.String(name)), sdkresource.WithSchemaURL(semconv.SchemaURL), sdkresource.WithProcess()}
}
// Shutdown shuts down the global trace exporter. // Shutdown shuts down the global trace exporter.
func Shutdown(ctx context.Context) error { func Shutdown(ctx context.Context) error {
tp, ok := provider.(*sdktrace.TracerProvider) tp, ok := provider.(*sdktrace.TracerProvider)

View File

@@ -0,0 +1,17 @@
package tracing
import (
"context"
"testing"
sdkresource "go.opentelemetry.io/otel/sdk/resource"
)
func TestCreateTraceableResource(t *testing.T) {
ctx := context.TODO()
resourceOpts := defaultResourceOpts("descheduler")
_, err := sdkresource.New(ctx, resourceOpts...)
if err != nil {
t.Errorf("error initialising tracer provider: %!", err)
}
}