Skip to content

Commit

Permalink
Replace stringLeading method with Java 8 friendlty alternative (#902)
Browse files Browse the repository at this point in the history
*Issue #, if available:*
The stringLeading method is only available in Java 11+. This doesn't
meet our requirement of ADOT Java being available for Java 8+. We need
to find an alternative method.

*Description of changes:*
Refactor code to be Java 8 friendlty

*Test run:*

https://github.com/aws-observability/aws-otel-java-instrumentation/actions/runs/11158858146

*Note*
Previously, the test was failing Java 8 for EKS use case. With this new
change, it is passing now.
This proves that:
1. The function `getDBStatementRemoteOperation`, specfically
`stripLeading()` is being tested by E2E test
2. The new change does not affect Java 11+ and also fixes Java 8

Unit tests also show that combinations of different attributes all pass
([Link](https://github.com/aws-observability/aws-otel-java-instrumentation/blob/main/awsagentprovider/src/test/java/software/amazon/opentelemetry/javaagent/providers/AwsMetricAttributeGeneratorTest.java#L573))


By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
  • Loading branch information
harrryr authored Oct 5, 2024
1 parent c6e03ab commit 47ce3b1
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ private static String getDBStatementRemoteOperation(

// Remove all whitespace and newline characters from the beginning of remote_operation
// and retrieve the first MAX_KEYWORD_LENGTH characters
remoteOperation = remoteOperation.stripLeading();
remoteOperation = remoteOperation.replaceFirst("^\\s+", "");
if (remoteOperation.length() > MAX_KEYWORD_LENGTH) {
remoteOperation = remoteOperation.substring(0, MAX_KEYWORD_LENGTH);
}
Expand Down

0 comments on commit 47ce3b1

Please sign in to comment.