Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shell script to ensure consistent version of OTEL semconv #4652

Merged
merged 4 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ lint:
./scripts/updateLicenses.sh > $(FMT_LOG)
./scripts/import-order-cleanup.sh stdout > $(IMPORT_LOG)
@[ ! -s "$(FMT_LOG)" -a ! -s "$(IMPORT_LOG)" ] || (echo "License check or import ordering failures, run 'make fmt'" | cat - $(FMT_LOG) $(IMPORT_LOG) && false)
./scripts/check-semconv-version.sh

.PHONY: build-examples
build-examples:
Expand Down
23 changes: 23 additions & 0 deletions scripts/check-semconv-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

declare -A semconv_map

package_name="go.opentelemetry.io/otel/semconv"
version_regex="v[0-9]\.[0-9]\+\.[0-9]\+"

while IFS=: read -r file_name package_string; do
semconv_map["$file_name"]="${package_string##*/}"
done < <(find . -type f -name "*.go" -exec grep -o -H "$package_name/$version_regex" {} +)

semconv_versions=($(printf "%s\n" "${semconv_map[@]}" | sort -u))

if [ ${#semconv_versions[@]} -gt 1 ]; then
echo "Error: semconv version mismatch detected."
{
for key in "${!semconv_map[@]}"; do
printf "Source File: %-50s | Semconv Version: %s\n" "$key" "${semconv_map[$key]}"
done
} | column -t -s '|'
echo "Run ./scripts/update-semconv-version.sh to update semconv to latest version."
exit 1
fi
26 changes: 26 additions & 0 deletions scripts/update-semconv-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

package_name="go.opentelemetry.io/otel/semconv"
version_regex="v[0-9]\.[0-9]\+\.[0-9]\+"

latest_semconv_version=$(
curl -s https://pkg.go.dev/$package_name \
| grep -oP 'data-id="v\d+\.\d+\.\d+"' \
| sed -E 's/\"($version_regex)\"/v\1/' \
| sort -Vr \
| head -n 1 \
| awk -F'"' '{print $2}'
)

latest_package_string="$package_name/$latest_semconv_version"

while IFS=: read -r file_name package_string; do
version_number=${package_string##*/}

if [ "$version_number" != "$latest_semconv_version" ]; then
sed -i "s#$package_name/$version_regex#$latest_package_string#g" "$file_name"
{
printf "Source File: %-60s | Previous Semconv Version: %s | Updated Semconv Version: %s\n" "$file_name" "$version_number" "$latest_semconv_version"
} | column -t -s '|'
fi
done < <(find . -type f -name "*.go" -exec grep -o -H "$package_name/$version_regex" {} +)