Skip to content

Commit

Permalink
let Corretto 21+ have non-redacted exceptions (#3438)
Browse files Browse the repository at this point in the history
* let Corretto 21+ have non-redacted exceptions

* Add comment and changelog

* fix changelog wrong section

* fix changelog wrong section again lol

* add a test to check on the 21+ no redaction
  • Loading branch information
jackshirazi authored Nov 27, 2023
1 parent 59da6ee commit 681caa3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
[float]
===== Features
* Added support for OpenTelemetry annotations - `WithSpan` and `SpanAttribute` - {pull}3406[#3406]
* Only automatically apply redacted exceptions for Corretto JVM 17-20. Outside that, user should use capture_exception_details=false to workaround the JVM race-condition bug if it gets triggered: {pull}3438[#3438]
[[release-notes-1.x]]
=== Java Agent version 1.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public static void exitDoExecute(@Advice.Argument(value = 0) ClientExecutionPara
Span<?> span = (Span<?>) spanObj;
span.deactivate();
if (thrown != null) {
if (JVM_RUNTIME_INFO.isCoretto() && JVM_RUNTIME_INFO.getMajorVersion() > 16) {
//Only automatically apply this workaround for JVM 17-20. Outside that, user should use capture_exception_details
if (JVM_RUNTIME_INFO.isCoretto() && JVM_RUNTIME_INFO.getMajorVersion() > 16 && JVM_RUNTIME_INFO.getMajorVersion() < 21) {
span.captureException(RedactedException.getInstance(thiz.getClass().getName()));
} else {
span.captureException(thrown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ public void checkRedactedExceptionWhenExceptionThrownOnCorretto17() {
assertThat(BaseSyncClientHandlerInstrumentation.RedactedException.Exceptions.get(this.getClass().getName())).isNotNull();
}

@Test
public void checkNoRedactedExceptionWhenExceptionThrownOnCorretto21() {
BaseSyncClientHandlerInstrumentation.JVM_RUNTIME_INFO = new JvmRuntimeInfo("21.0.1", "OpenJDK 64-Bit Server VM", "Amazon.com Inc.", "17.0.5+8-LTS");
assertThat(BaseSyncClientHandlerInstrumentation.JVM_RUNTIME_INFO.isCoretto()).isTrue();
assertThat(BaseSyncClientHandlerInstrumentation.JVM_RUNTIME_INFO.getMajorVersion()).isGreaterThan(16);
assertThat(exerciseRedactedException(new Exception("test3"))).isEqualTo(Outcome.FAILURE);
assertThat(BaseSyncClientHandlerInstrumentation.RedactedException.Exceptions).isEmpty();
}

public Outcome exerciseRedactedException(Exception canBeNull) {
MockTracer.MockInstrumentationSetup mockInstrumentationSetup = MockTracer.createMockInstrumentationSetup();
ElasticApmTracer tracer = mockInstrumentationSetup.getTracer();
Expand Down

0 comments on commit 681caa3

Please sign in to comment.