diff --git a/hack/update-deps.sh b/hack/update-deps.sh index 68bfa5f6a3..76a8d68d7d 100755 --- a/hack/update-deps.sh +++ b/hack/update-deps.sh @@ -21,3 +21,39 @@ set -o pipefail source $(dirname "$0")/../vendor/knative.dev/hack/library.sh go_update_deps "$@" + +# Update semconv import versions to match the go.opentelemetry.io/otel version +# This prevents schema conflict errors when OpenTelemetry dependencies are bumped +log.step "Syncing semconv imports" +OTEL_VERSION=$(go list -m go.opentelemetry.io/otel 2>/dev/null | awk '{print $NF}') +if [ -n "$OTEL_VERSION" ]; then + group "Detected go.opentelemetry.io/otel ${OTEL_VERSION}" + + # Check known mappings first (fast path) + case "$OTEL_VERSION" in + v1.45.*) SEMCONV_VERSION="v1.43.0" ;; + v1.44.*) SEMCONV_VERSION="v1.41.0" ;; + esac + + # If no mapping found, fetch from OTEL's go.mod + if [ -z "$SEMCONV_VERSION" ]; then + group "No known mapping, fetching semconv version from OTEL go.mod" + SEMCONV_VERSION=$(curl -s "https://raw.githubusercontent.com/open-telemetry/opentelemetry-go/${OTEL_VERSION}/go.mod" 2>/dev/null | \ + grep "go.opentelemetry.io/otel/semconv/v" | head -1 | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' || echo "") + fi + + if [ -n "$SEMCONV_VERSION" ]; then + group "Updating semconv imports to ${SEMCONV_VERSION}" + # Find Go files under observability/ that use a versioned semconv import and + # update them. Match only the version segment so subpackage imports + # (e.g. .../v1.41.0/httpconv) are updated too, preserving what follows it. + find observability -type f -name "*.go" -exec \ + grep -lE "go.opentelemetry.io/otel/semconv/v[0-9]+\.[0-9]+\.[0-9]+" {} + | \ + while IFS= read -r file; do + group " ${file}" + sed -i -E "s|(go.opentelemetry.io/otel/semconv/)v[0-9]+\.[0-9]+\.[0-9]+|\1$SEMCONV_VERSION|g" "$file" + done + else + group "Could not determine semconv version, skipping" + fi +fi