Skip to content

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
@zeitlinger
Copy link
Member

@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

}

@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?

@trask trask merged commit cf0f530 into open-telemetry:main Dec 20, 2024
55 of 56 checks passed
@trask trask deleted the semconv-static-import branch December 20, 2024 16:11
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