Skip to content

Commit 32e4ec9

Browse files
committed
Updating the test cases and adding unit test for isDbSpan
1 parent 258aea9 commit 32e4ec9

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

awsagentprovider/src/main/java/software/amazon/opentelemetry/javaagent/providers/AwsSpanProcessingUtil.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static io.opentelemetry.semconv.SemanticAttributes.DB_OPERATION;
1919
import static io.opentelemetry.semconv.SemanticAttributes.DB_STATEMENT;
2020
import static io.opentelemetry.semconv.SemanticAttributes.DB_SYSTEM;
21-
import static io.opentelemetry.semconv.SemanticAttributes.DB_USER;
2221
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_METHOD;
2322
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_TARGET;
2423
import static io.opentelemetry.semconv.SemanticAttributes.MESSAGING_OPERATION;
@@ -227,7 +226,6 @@ private static String generateIngressOperation(SpanData span) {
227226
static boolean isDBSpan(SpanData span) {
228227
return isKeyPresent(span, DB_SYSTEM)
229228
|| isKeyPresent(span, DB_OPERATION)
230-
|| isKeyPresent(span, DB_USER)
231229
|| isKeyPresent(span, DB_STATEMENT);
232230
}
233231
}

awsagentprovider/src/test/java/software/amazon/opentelemetry/javaagent/providers/AwsMetricAttributeGeneratorTest.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,13 +1032,16 @@ private void validateHttpStatusForNonLocalRootWithThrowableForClient(
10321032

10331033
@Test
10341034
void testDBUserAttribute() {
1035-
String dbUser = "test_user";
1036-
mockAttribute(DB_USER, dbUser);
1035+
mockAttribute(DB_SYSTEM, "db_system");
1036+
mockAttribute(DB_OPERATION, "db_operation");
1037+
mockAttribute(DB_STATEMENT, "db_statement");
1038+
mockAttribute(DB_USER, "db_user");
10371039
when(spanDataMock.getKind()).thenReturn(SpanKind.CLIENT);
10381040

10391041
Attributes actualAttributes =
10401042
GENERATOR.generateMetricAttributeMapFromSpan(spanDataMock, resource).get(DEPENDENCY_METRIC);
1041-
assertThat(actualAttributes.get(AWS_REMOTE_DB_USER)).isEqualTo(dbUser);
1043+
assertThat(actualAttributes.get(AWS_REMOTE_OPERATION)).isEqualTo("db_operation");
1044+
assertThat(actualAttributes.get(AWS_REMOTE_DB_USER)).isEqualTo("db_user");
10421045
}
10431046

10441047
@Test
@@ -1053,18 +1056,20 @@ void testDBUserAttributeAbsent() {
10531056

10541057
@Test
10551058
void testDBUserAttributeWithDifferentValues() {
1056-
String dbUser = "non_db_user";
1057-
mockAttribute(DB_USER, dbUser);
1059+
mockAttribute(DB_SYSTEM, "db_system");
1060+
mockAttribute(DB_OPERATION, "db_operation");
1061+
mockAttribute(DB_STATEMENT, "db_statement");
1062+
mockAttribute(DB_USER, "non_db_user");
10581063
when(spanDataMock.getKind()).thenReturn(SpanKind.CLIENT);
10591064

10601065
Attributes actualAttributes =
10611066
GENERATOR.generateMetricAttributeMapFromSpan(spanDataMock, resource).get(DEPENDENCY_METRIC);
1062-
assertThat(actualAttributes.get(AWS_REMOTE_DB_USER)).isEqualTo(dbUser);
1067+
assertThat(actualAttributes.get(AWS_REMOTE_DB_USER)).isEqualTo("non_db_user");
10631068
}
10641069

10651070
@Test
10661071
void testDBUserAttributeNotPresentInServiceMetricForServerSpan() {
1067-
String dbUser = "test_user";
1072+
String dbUser = "db_user";
10681073
mockAttribute(DB_USER, dbUser);
10691074
when(spanDataMock.getKind()).thenReturn(SpanKind.SERVER);
10701075

@@ -1073,6 +1078,24 @@ void testDBUserAttributeNotPresentInServiceMetricForServerSpan() {
10731078
assertThat(actualAttributes.get(AWS_REMOTE_DB_USER)).isNull();
10741079
}
10751080

1081+
@Test
1082+
public void testIsDbSpanTrue() {
1083+
mockAttribute(DB_SYSTEM, "DB system");
1084+
mockAttribute(DB_OPERATION, "DB operation");
1085+
mockAttribute(DB_USER, "DB user");
1086+
when(spanDataMock.getKind()).thenReturn(SpanKind.CLIENT);
1087+
1088+
assertThat(AwsSpanProcessingUtil.isDBSpan(spanDataMock)).isTrue();
1089+
}
1090+
1091+
@Test
1092+
public void testIsDbSpanFalse() {
1093+
mockAttribute(DB_SYSTEM, null);
1094+
when(spanDataMock.getKind()).thenReturn(SpanKind.CLIENT);
1095+
1096+
assertThat(AwsSpanProcessingUtil.isDBSpan(spanDataMock)).isFalse();
1097+
}
1098+
10761099
@Test
10771100
public void testNormalizeRemoteServiceName_NoNormalization() {
10781101
String serviceName = "non aws service";

0 commit comments

Comments
 (0)