From 153f7f10c97afe4b765ea234f4c9247fd0e02cfc Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Mon, 20 Oct 2025 15:13:07 -0500 Subject: [PATCH] telemetry: lock the semconv version of the otel sdk This change prevents changes to the otel version from affecting the otel sdk version. This is done by copying the telemetry sdk implementation locally and using our own choice for semconv from within that. This prevents a schema conflict from happening since the otel version of the sdk gets implicitly updated whenever the semconv changes while we have to manually change ours. Now, we manually change both and they're locked to each other. Signed-off-by: Jonathan A. Sternberg Signed-off-by: Sebastiaan van Stijn --- cli/command/telemetry.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cli/command/telemetry.go b/cli/command/telemetry.go index e8e6296b5..f4107c386 100644 --- a/cli/command/telemetry.go +++ b/cli/command/telemetry.go @@ -11,6 +11,7 @@ import ( "github.com/google/uuid" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/metric" + otelsdk "go.opentelemetry.io/otel/sdk" sdkmetric "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/metricdata" "go.opentelemetry.io/otel/sdk/resource" @@ -146,7 +147,7 @@ func defaultResourceOptions() []resource.Option { semconv.ServiceInstanceID(uuid.NewString()), ), resource.WithFromEnv(), - resource.WithTelemetrySDK(), + resource.WithDetectors(telemetrySDK{}), } } @@ -157,7 +158,10 @@ func (r *telemetryResource) AppendOptions(opts ...resource.Option) { r.opts = append(r.opts, opts...) } -type serviceNameDetector struct{} +type ( + serviceNameDetector struct{} + telemetrySDK struct{} +) func (serviceNameDetector) Detect(ctx context.Context) (*resource.Resource, error) { return resource.StringDetector( @@ -169,6 +173,16 @@ func (serviceNameDetector) Detect(ctx context.Context) (*resource.Resource, erro ).Detect(ctx) } +// Detect returns a *Resource that describes the OpenTelemetry SDK used. +func (telemetrySDK) Detect(context.Context) (*resource.Resource, error) { + return resource.NewWithAttributes( + semconv.SchemaURL, + semconv.TelemetrySDKName("opentelemetry"), + semconv.TelemetrySDKLanguageGo, + semconv.TelemetrySDKVersion(otelsdk.Version()), + ), nil +} + // cliReader is an implementation of Reader that will automatically // report to a designated Exporter when Shutdown is called. type cliReader struct {