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 1 commit
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
4 changes: 2 additions & 2 deletions scripts/check-semconv-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ done < <(find . -type f -name "*.go" -exec grep -o -H "go.opentelemetry.io/otel/
semconv_versions=($(printf "%s\n" "${semconv_map[@]}" | sort -u))

if [ ${#semconv_versions[@]} -gt 1 ]; then
echo "Error: semconv version mismatch detected"
echo "Error: semconv version mismatch detected. Run ./scripts/update-semconv-version.sh to update semconv to latest version."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend printing "Run <script>" line at the end of the output, after the listing of files.

{
for key in "${!semconv_map[@]}"; do
printf "Source File: %-30s | Semconv Version: %s\n" "$key" "${semconv_map[$key]}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
printf "Source File: %-30s | Semconv Version: %s\n" "$key" "${semconv_map[$key]}"
printf "Source File: %-50s | Semconv Version: %s\n" "$key" "${semconv_map[$key]}"

30 may not be long enough

done
} | column -t -s '|'

exit 1
fi
fi
22 changes: 22 additions & 0 deletions scripts/update-semconv-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

latest_semconv_version=$(
curl -s https://pkg.go.dev/go.opentelemetry.io/otel/semconv \
| grep -oP 'data-id="v\d+\.\d+\.\d+"' \
| sed -E 's/data-id="v([0-9]+\.[0-9]+\.[0-9]+)"/v\1/' \
| sort -Vr \
| head -n 1
)

latest_package_string="go.opentelemetry.io/otel/semconv/$latest_semconv_version"

while IFS=: read -r file_name package_string; do
version_number=$(echo "$package_string" | grep -o -E "v1\.[0-9]+\.[0-9]+")

if [ "$version_number" != "$latest_semconv_version" ]; then
sed -i "s#go\.opentelemetry\.io\/otel\/semconv\/v[0-9]\+\.[0-9]\+\.[0-9]\+#$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 "go.opentelemetry.io/otel/semconv/v1\.[0-9]\+\.[0-9]\+" {} +)