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

Static import semconv constants in tests #12920

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

trask
Copy link
Member

@trask trask commented Dec 19, 2024

I was looking into scraping the code to verify that all inlined constants are tested (via non-inlined constants):

open-telemetry/opentelemetry-java-contrib#1604 (comment)

and this normalizing will help my grepping efforts

tracking my latest script:

#!/bin/bash -e

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 $(perl -ne "print \"\$1\n\" if /$negative_lookbehind$class\.([A-Z][A-Z][A-Z_]*)/" $file | sort -u); 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 "AwsIncubatingAttributes" "DbIncubatingAttributes" "HttpIncubatingAttributes" "MessagingIncubatingAttributes"; do
    for attr in $(perl -ne "print \"\$1\n\" if /$negative_lookbehind$class\.([A-Z][A-Z][A-Z_]*)/" $file | sort -u); 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

@trask trask requested a review from a team as a code owner December 19, 2024 01:07
@trask
Copy link
Member Author

trask commented Dec 19, 2024

have you tried using this approach?

https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12009/files#diff-b36b9b7d4939f00472feba2fd8ee942cec0591677a9b7a8220b6770ba1cd2fadR53-R64

I'm not quite ready to enforce it, maybe after we finish migrating all of the groovy tests

@@ -51,7 +52,7 @@ static void tearDown() {
}
}

@SuppressWarnings("deprecation") // DbIncubatingAttributes.DB_NAME has been deprecated
@SuppressWarnings("deprecation") // DB_NAME has been deprecated
Copy link
Contributor

@laurit laurit Dec 19, 2024

Choose a reason for hiding this comment

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

DB_NAME isn't the only deprecate attribute used here, maybe reword the comment?

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