From 6186b9c869b663c152c26dd4c4059311256562ad Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Fri, 8 Nov 2024 09:20:00 -0600 Subject: [PATCH] detect: use newer semconv for resource and add unit test We upgraded a dependency that upgraded otel and also changed the semconv schema for us to a newer version. We forgot to upgrade our own semconv. In the future, we may want to find a way to have a detector that doesn't require us to manually specify a semconv so we don't have to remember this. For now, I've added a test to catch when this happens so it doesn't happen again. Signed-off-by: Jonathan A. Sternberg --- util/tracing/detect/resource.go | 2 +- util/tracing/detect/resource_test.go | 29 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 util/tracing/detect/resource_test.go diff --git a/util/tracing/detect/resource.go b/util/tracing/detect/resource.go index 79abea9526cb1..5f263e0fd5d67 100644 --- a/util/tracing/detect/resource.go +++ b/util/tracing/detect/resource.go @@ -8,7 +8,7 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/sdk/resource" - semconv "go.opentelemetry.io/otel/semconv/v1.21.0" + semconv "go.opentelemetry.io/otel/semconv/v1.26.0" ) var ( diff --git a/util/tracing/detect/resource_test.go b/util/tracing/detect/resource_test.go new file mode 100644 index 0000000000000..3863b4ffa3d05 --- /dev/null +++ b/util/tracing/detect/resource_test.go @@ -0,0 +1,29 @@ +package detect + +import ( + "testing" + + "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel" +) + +func TestResource(t *testing.T) { + prevHandler := otel.GetErrorHandler() + t.Cleanup(func() { + otel.SetErrorHandler(prevHandler) + }) + + var resourceErr error + otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) { + resourceErr = err + })) + + res := Resource() + + // Should not have an empty schema url. Only happens when + // there is a schema conflict. + require.NotEqual(t, "", res.SchemaURL()) + + // No error should have been invoked. + require.NoError(t, resourceErr) +}