Skip to content

Commit

Permalink
Assert extra spans for MySQlConnectorJ-8.4. (#888)
Browse files Browse the repository at this point in the history
*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.
  • Loading branch information
sam6134 authored Sep 12, 2024
1 parent b366543 commit 4afa55e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ protected void assertAwsAttributes(
.isEqualTo(AppSignalsConstants.AWS_REMOTE_RESOURCE_IDENTIFIER);
assertThat(attribute.getValue().getStringValue()).isEqualTo(identifier);
});
} else {
assertions.allSatisfy(
(attribute) -> {
assertThat(attribute.getKey())
.isNotEqualTo(AppSignalsConstants.AWS_REMOTE_RESOURCE_TYPE);
assertThat(attribute.getKey())
.isNotEqualTo(AppSignalsConstants.AWS_REMOTE_RESOURCE_IDENTIFIER);
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

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

import static io.opentelemetry.proto.trace.v1.Span.SpanKind.SPAN_KIND_CLIENT;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -70,6 +73,7 @@ public void testSuccessSelect() {
DB_CONNECTION_STRING,
DB_RESOURCE_TYPE,
MYSQL_IDENTIFIER);
assertExtraSelectSpan();
}

@Test
Expand Down Expand Up @@ -108,4 +112,23 @@ protected List<Startable> getApplicationDependsOnContainers() {
Wait.forLogMessage(".*database system is ready to accept connections.*", 1));
return List.of(mySQLContainer);
}

private void assertExtraSelectSpan() {
var resourceScopeSpans = mockCollectorClient.getTraces();
assertThat(resourceScopeSpans)
.satisfiesOnlyOnce(
rss -> {
assertThat(rss.getSpan().getKind()).isEqualTo(SPAN_KIND_CLIENT);
var attributesList = rss.getSpan().getAttributesList();
assertAwsAttributes(
attributesList,
"GET",
"success/" + DB_SELECT_OPERATION,
DB_SYSTEM,
DB_SELECT_OPERATION,
DB_USER,
null,
null);
});
}
}
1 change: 1 addition & 0 deletions appsignals-tests/images/jdbc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
implementation("com.h2database:h2:2.2.224")
implementation("org.slf4j:slf4j-simple")
implementation("org.postgresql:postgresql:42.2.0")
implementation("io.opentelemetry:opentelemetry-api:1.34.1")
implementation("com.mysql:mysql-connector-j:8.4.0")
}

Expand Down

0 comments on commit 4afa55e

Please sign in to comment.