Skip to content

Commit 4afa55e

Browse files
authored
Assert extra spans for MySQlConnectorJ-8.4. (#888)
*Description of changes:* Assert extra spans for MySQlConnectorJ-8.4. When making a database query, Pulse agent leverage OTEL agent to intercept the database queries and send them to Cloud-watch agent. Then CloudWatch agent send all telemetry into Cloud-watch We noticed that there will be two separate EMF log entries, one without remote identifier and one with remote identifier, this extra EMF comes in due to extra telemetry traces that come with mysqlConnector version 8.4 > The feature is supported by [component_telemetry](https://dev.mysql.com/doc/refman/8.4/en/telemetry-trace-install.html). MySQL Connector/J 8.4.0 introduces the client-side counterpart feature, with the capability of propagating the context to the MySQL Server it connects to and allowing a more complete observability for an application stack. ([Ref](https://dev.mysql.com/doc/connector-j/en/connector-j-opentelemetry.html)) The following commit adds the extra assertion of asserting the extra SELECT span. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent b366543 commit 4afa55e

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

appsignals-tests/contract-tests/src/test/java/software/amazon/opentelemetry/appsignals/test/jdbc/JdbcContractTestBase.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ protected void assertAwsAttributes(
122122
.isEqualTo(AppSignalsConstants.AWS_REMOTE_RESOURCE_IDENTIFIER);
123123
assertThat(attribute.getValue().getStringValue()).isEqualTo(identifier);
124124
});
125+
} else {
126+
assertions.allSatisfy(
127+
(attribute) -> {
128+
assertThat(attribute.getKey())
129+
.isNotEqualTo(AppSignalsConstants.AWS_REMOTE_RESOURCE_TYPE);
130+
assertThat(attribute.getKey())
131+
.isNotEqualTo(AppSignalsConstants.AWS_REMOTE_RESOURCE_IDENTIFIER);
132+
});
125133
}
126134
}
127135

appsignals-tests/contract-tests/src/test/java/software/amazon/opentelemetry/appsignals/test/jdbc/JdbcMySQLTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
package software.amazon.opentelemetry.appsignals.test.jdbc;
1717

18+
import static io.opentelemetry.proto.trace.v1.Span.SpanKind.SPAN_KIND_CLIENT;
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
1821
import java.util.List;
1922
import java.util.Map;
2023
import org.junit.jupiter.api.AfterEach;
@@ -70,6 +73,7 @@ public void testSuccessSelect() {
7073
DB_CONNECTION_STRING,
7174
DB_RESOURCE_TYPE,
7275
MYSQL_IDENTIFIER);
76+
assertExtraSelectSpan();
7377
}
7478

7579
@Test
@@ -108,4 +112,23 @@ protected List<Startable> getApplicationDependsOnContainers() {
108112
Wait.forLogMessage(".*database system is ready to accept connections.*", 1));
109113
return List.of(mySQLContainer);
110114
}
115+
116+
private void assertExtraSelectSpan() {
117+
var resourceScopeSpans = mockCollectorClient.getTraces();
118+
assertThat(resourceScopeSpans)
119+
.satisfiesOnlyOnce(
120+
rss -> {
121+
assertThat(rss.getSpan().getKind()).isEqualTo(SPAN_KIND_CLIENT);
122+
var attributesList = rss.getSpan().getAttributesList();
123+
assertAwsAttributes(
124+
attributesList,
125+
"GET",
126+
"success/" + DB_SELECT_OPERATION,
127+
DB_SYSTEM,
128+
DB_SELECT_OPERATION,
129+
DB_USER,
130+
null,
131+
null);
132+
});
133+
}
111134
}

appsignals-tests/images/jdbc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies {
3232
implementation("com.h2database:h2:2.2.224")
3333
implementation("org.slf4j:slf4j-simple")
3434
implementation("org.postgresql:postgresql:42.2.0")
35+
implementation("io.opentelemetry:opentelemetry-api:1.34.1")
3536
implementation("com.mysql:mysql-connector-j:8.4.0")
3637
}
3738

0 commit comments

Comments
 (0)