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

Statically import semconv constants in tests #12575

Merged

Conversation

trask
Copy link
Member

@trask trask commented Nov 5, 2024

automated via:

for file in $(find instrumentation -name '*Test.java'); do
  echo "Processing $file"

  # stable semconv

  negative_lookbehind='(?<!import static io.opentelemetry.semconv.)'

  for class in "ClientAttributes" "ErrorAttributes" "ExceptionAttributes" "HttpAttributes" "JvmAttributes" "NetworkAttributes" "OtelAttributes" "ServerAttributes" "ServiceAttributes" "TelemetryAttributes" "UrlAttributes" "UserAgentAttributes"; do
    for attr in $(grep -Po "$negative_lookbehind$class\.[A-Z][A-Z][A-Z_]*" $file | sort -u | sed "s/$class\.//"); do
      perl -i -pe "s/$negative_lookbehind$class\.$attr/$attr/" $file
      sed -i "0,/^import/{s/^import/import static io.opentelemetry.semconv.$class.$attr;\nimport/}" $file
    done
  done

  # incubating semconv

  negative_lookbehind='(?<!import static io.opentelemetry.semconv.incubating.)'

  for class in "DbIncubatingAttributes" "HttpIncubatingAttributes" "MessagingIncubatingAttributes"; do
    for attr in $(grep -Po "$negative_lookbehind$class\.[A-Z][A-Z][A-Z_]*" $file | sort -u | sed "s/$class\.//"); do
      perl -i -pe "s/$negative_lookbehind$class\.$attr/$attr/" $file
      sed -i "0,/^import/{s/^import/import static io.opentelemetry.semconv.incubating.$class.$attr;\nimport/}" $file
    done
  done
done

./gradlew spotlessApply

plus one manual rollback: e308dbe

@trask trask force-pushed the statically-import-semconv-constants branch from a1bf61b to 07c153f Compare November 6, 2024 02:29
@trask trask marked this pull request as ready for review November 6, 2024 03:24
@trask trask requested a review from a team as a code owner November 6, 2024 03:24
Copy link
Contributor

@laurit laurit left a comment

Choose a reason for hiding this comment

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

I have usually skipped static imports when there is only 1 usage, but always adding a static import is fine too. At least RpcIncubatingAttributes seems to be missing, could you add static import for these too. Could be done in a separate PR if that is more convenient.

@trask trask merged commit 2371589 into open-telemetry:main Nov 6, 2024
56 checks passed
@trask trask deleted the statically-import-semconv-constants branch November 6, 2024 16:18
akats7 pushed a commit to akats7/opentelemetry-java-instrumentation that referenced this pull request Nov 21, 2024
akats7 pushed a commit to akats7/opentelemetry-java-instrumentation that referenced this pull request Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants