Skip to content

Commit bb4abb4

Browse files
authored
[semconv]: Add functions to support migration of deprecated semconv keys (#1150)
This PR adds a utility method to help migrate deprecated semconv keys. It first checks the new key; if the new key is not available, it falls back to the legacy deprecated key. This PR also handles the following deprecated keys: MESSAGING_OPERATION SERVER_SOCKET_ADDRESS SERVER_SOCKET_PORT Tests: ./gradlew build test — Pass ./gradlew appsignals-tests:contract-tests:contractTests — Pass Manual E2E with Spring Boot sample app: Compared raw span data with and without this change — Pass By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 492f406 commit bb4abb4

File tree

4 files changed

+182
-29
lines changed

4 files changed

+182
-29
lines changed

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

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
2323
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
2424
import static io.opentelemetry.semconv.UrlAttributes.URL_FULL;
25+
// These DB keys have been deprecated:
26+
// https://github.com/open-telemetry/semantic-conventions-java/blob/release/v1.34.0/semconv-incubating/src/main/java/io/opentelemetry/semconv/incubating/DbIncubatingAttributes.java#L322-L327
27+
// They have been replaced with new keys:
28+
// https://github.com/open-telemetry/semantic-conventions-java/blob/release/v1.34.0/semconv/src/main/java/io/opentelemetry/semconv/DbAttributes.java#L77
29+
// TODO: Supporting new keys. Cannot do this now as new keys are not available in OTel Agent 2.11.
30+
// TODO: Delete deprecated keys once they no longer exist in binding version of the upstream code.
2531
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_CONNECTION_STRING;
2632
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAME;
2733
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
@@ -34,7 +40,10 @@
3440
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_METHOD;
3541
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_STATUS_CODE;
3642
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_URL;
43+
// https://github.com/open-telemetry/semantic-conventions-java/blob/release/v1.34.0/semconv-incubating/src/main/java/io/opentelemetry/semconv/incubating/MessagingIncubatingAttributes.java#L236-L242
44+
// Deprecated, use {@code messaging.operation.type} instead.
3745
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION;
46+
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION_TYPE;
3847
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;
3948
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_PEER_NAME;
4049
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_PEER_PORT;
@@ -87,6 +96,7 @@
8796
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isAwsSDKSpan;
8897
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isDBSpan;
8998
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isKeyPresent;
99+
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isKeyPresentWithFallback;
90100

91101
import com.amazonaws.arn.Arn;
92102
import io.opentelemetry.api.common.AttributeKey;
@@ -122,15 +132,6 @@
122132
* represent "outgoing" traffic, and {@link SpanKind#INTERNAL} spans are ignored.
123133
*/
124134
final class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
125-
// ToDo: These two keys were deleted by upstream. Code need to be updated to capture the same
126-
// information by using new keys.
127-
// https://github.com/open-telemetry/semantic-conventions-java/blob/release/v1.28.0/semconv/src/main/java/io/opentelemetry/semconv/SemanticAttributes.java#L3784-L3795
128-
static final AttributeKey<String> SERVER_SOCKET_ADDRESS =
129-
io.opentelemetry.api.common.AttributeKey.stringKey("server.socket.address");
130-
131-
static final AttributeKey<Long> SERVER_SOCKET_PORT =
132-
io.opentelemetry.api.common.AttributeKey.longKey("server.socket.port");
133-
134135
private static final Logger logger =
135136
Logger.getLogger(AwsMetricAttributeGenerator.class.getName());
136137

@@ -293,9 +294,11 @@ private static void setRemoteServiceAndOperation(SpanData span, AttributesBuilde
293294
} else if (isKeyPresent(span, FAAS_INVOKED_NAME) || isKeyPresent(span, FAAS_TRIGGER)) {
294295
remoteService = getRemoteService(span, FAAS_INVOKED_NAME);
295296
remoteOperation = getRemoteOperation(span, FAAS_TRIGGER);
296-
} else if (isKeyPresent(span, MESSAGING_SYSTEM) || isKeyPresent(span, MESSAGING_OPERATION)) {
297+
} else if (isKeyPresent(span, MESSAGING_SYSTEM)
298+
|| isKeyPresentWithFallback(span, MESSAGING_OPERATION_TYPE, MESSAGING_OPERATION)) {
297299
remoteService = getRemoteService(span, MESSAGING_SYSTEM);
298-
remoteOperation = getRemoteOperation(span, MESSAGING_OPERATION);
300+
remoteOperation =
301+
getRemoteOperationWithFallback(span, MESSAGING_OPERATION_TYPE, MESSAGING_OPERATION);
299302
} else if (isKeyPresent(span, GRAPHQL_OPERATION_TYPE)) {
300303
remoteService = GRAPHQL;
301304
remoteOperation = getRemoteOperation(span, GRAPHQL_OPERATION_TYPE);
@@ -772,15 +775,15 @@ private static Optional<String> getSnsResourceNameFromArn(Optional<String> strin
772775
* {address} attribute is retrieved in priority order:
773776
* - {@link SemanticAttributes#SERVER_ADDRESS},
774777
* - {@link SemanticAttributes#NET_PEER_NAME},
775-
* - {@link SemanticAttributes#SERVER_SOCKET_ADDRESS}
778+
* - {@link SemanticAttributes#NETWORK_PEER_ADDRESS}
776779
* - {@link SemanticAttributes#DB_CONNECTION_STRING}-Hostname
777780
* </pre>
778781
*
779782
* <pre>
780783
* {port} attribute is retrieved in priority order:
781784
* - {@link SemanticAttributes#SERVER_PORT},
782785
* - {@link SemanticAttributes#NET_PEER_PORT},
783-
* - {@link SemanticAttributes#SERVER_SOCKET_PORT}
786+
* - {@link SemanticAttributes#NETWORK_PEER_PORT}
784787
* - {@link SemanticAttributes#DB_CONNECTION_STRING}-Port
785788
* </pre>
786789
*
@@ -799,9 +802,9 @@ private static Optional<String> getDbConnection(SpanData span) {
799802
String networkPeerAddress = span.getAttributes().get(NET_PEER_NAME);
800803
Long networkPeerPort = span.getAttributes().get(NET_PEER_PORT);
801804
dbConnection = buildDbConnection(networkPeerAddress, networkPeerPort);
802-
} else if (isKeyPresent(span, SERVER_SOCKET_ADDRESS)) {
803-
String serverSocketAddress = span.getAttributes().get(SERVER_SOCKET_ADDRESS);
804-
Long serverSocketPort = span.getAttributes().get(SERVER_SOCKET_PORT);
805+
} else if (isKeyPresent(span, NETWORK_PEER_ADDRESS)) {
806+
String serverSocketAddress = span.getAttributes().get(NETWORK_PEER_ADDRESS);
807+
Long serverSocketPort = span.getAttributes().get(NETWORK_PEER_PORT);
805808
dbConnection = buildDbConnection(serverSocketAddress, serverSocketPort);
806809
} else if (isKeyPresent(span, DB_CONNECTION_STRING)) {
807810
String connectionString = span.getAttributes().get(DB_CONNECTION_STRING);
@@ -954,6 +957,15 @@ private static String getRemoteOperation(SpanData span, AttributeKey<String> rem
954957
return remoteOperation;
955958
}
956959

960+
static String getRemoteOperationWithFallback(
961+
SpanData span, AttributeKey<String> remoteOpKey, AttributeKey<String> remoteOpFallbackKey) {
962+
String remoteOp = span.getAttributes().get(remoteOpKey);
963+
if (remoteOp == null) {
964+
return getRemoteOperation(span, remoteOpFallbackKey);
965+
}
966+
return remoteOp;
967+
}
968+
957969
/**
958970
* If no db.operation attribute provided in the span, we use db.statement to compute a valid
959971
* remote operation in a best-effort manner. To do this, we take the first substring of the

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_REQUEST_METHOD;
2424
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_TARGET;
2525
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION;
26+
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION_TYPE;
2627
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MessagingOperationTypeIncubatingValues.PROCESS;
2728
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SYSTEM;
2829
import static software.amazon.opentelemetry.javaagent.providers.AwsApplicationSignalsCustomizerProvider.AWS_LAMBDA_FUNCTION_NAME_CONFIG;
@@ -153,6 +154,23 @@ static boolean isKeyPresent(SpanData span, AttributeKey<?> key) {
153154
return span.getAttributes().get(key) != null;
154155
}
155156

157+
static <T> boolean isKeyPresentWithFallback(
158+
SpanData span, AttributeKey<T> key, AttributeKey<T> fallbackKey) {
159+
if (span.getAttributes().get(key) != null) {
160+
return true;
161+
}
162+
return isKeyPresent(span, fallbackKey);
163+
}
164+
165+
static <T> T getKeyValueWithFallback(
166+
SpanData span, AttributeKey<T> key, AttributeKey<T> fallbackKey) {
167+
T value = span.getAttributes().get(key);
168+
if (value != null) {
169+
return value;
170+
}
171+
return span.getAttributes().get(fallbackKey);
172+
}
173+
156174
static boolean isAwsSDKSpan(SpanData span) {
157175
// https://opentelemetry.io/docs/specs/otel/trace/semantic_conventions/instrumentation/aws-sdk/#common-attributes
158176
return "aws-api".equals(span.getAttributes().get(RPC_SYSTEM));
@@ -170,7 +188,8 @@ static boolean shouldGenerateDependencyMetricAttributes(SpanData span) {
170188
}
171189

172190
static boolean isConsumerProcessSpan(SpanData spanData) {
173-
String messagingOperation = spanData.getAttributes().get(MESSAGING_OPERATION);
191+
String messagingOperation =
192+
getKeyValueWithFallback(spanData, MESSAGING_OPERATION_TYPE, MESSAGING_OPERATION);
174193
return SpanKind.CONSUMER.equals(spanData.getKind()) && PROCESS.equals(messagingOperation);
175194
}
176195

@@ -192,7 +211,8 @@ static boolean isLocalRoot(SpanData spanData) {
192211
private static boolean isSqsReceiveMessageConsumerSpan(SpanData spanData) {
193212
String spanName = spanData.getName();
194213
SpanKind spanKind = spanData.getKind();
195-
String messagingOperation = spanData.getAttributes().get(MESSAGING_OPERATION);
214+
String messagingOperation =
215+
getKeyValueWithFallback(spanData, MESSAGING_OPERATION_TYPE, MESSAGING_OPERATION);
196216
InstrumentationScopeInfo instrumentationScopeInfo = spanData.getInstrumentationScopeInfo();
197217

198218
return SQS_RECEIVE_MESSAGE_SPAN_NAME.equalsIgnoreCase(spanName)

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

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_TARGET;
3939
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_URL;
4040
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION;
41+
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION_TYPE;
4142
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;
4243
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MessagingOperationTypeIncubatingValues.PROCESS;
4344
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_PEER_NAME;
@@ -1264,31 +1265,31 @@ public void testDBClientSpanWithRemoteResourceAttributes() {
12641265
assertThat(actualAttributes.get(AWS_REMOTE_RESOURCE_IDENTIFIER)).isNull();
12651266
mockAttribute(NET_PEER_PORT, null);
12661267

1267-
// Validate behaviour of DB_NAME, SERVER_SOCKET_ADDRESS and SERVER_SOCKET_PORT exist, then
1268+
// Validate behaviour of DB_NAME, NETWORK_PEER_ADDRESS and NETWORK_PEER_PORT exist, then
12681269
// remove it.
12691270
mockAttribute(DB_NAME, "db_name");
1270-
mockAttribute(AwsMetricAttributeGenerator.SERVER_SOCKET_ADDRESS, "abc.com");
1271-
mockAttribute(AwsMetricAttributeGenerator.SERVER_SOCKET_PORT, 3306L);
1271+
mockAttribute(NETWORK_PEER_ADDRESS, "abc.com");
1272+
mockAttribute(NETWORK_PEER_PORT, 3306L);
12721273
validateRemoteResourceAttributes("DB::Connection", "db_name|abc.com|3306");
12731274
mockAttribute(DB_NAME, null);
1274-
mockAttribute(AwsMetricAttributeGenerator.SERVER_SOCKET_ADDRESS, null);
1275-
mockAttribute(AwsMetricAttributeGenerator.SERVER_SOCKET_PORT, null);
1275+
mockAttribute(NETWORK_PEER_ADDRESS, null);
1276+
mockAttribute(NETWORK_PEER_PORT, null);
12761277

1277-
// Validate behaviour of DB_NAME, SERVER_SOCKET_ADDRESS exist, then remove it.
1278+
// Validate behaviour of DB_NAME, NETWORK_PEER_ADDRESS exist, then remove it.
12781279
mockAttribute(DB_NAME, "db_name");
1279-
mockAttribute(AwsMetricAttributeGenerator.SERVER_SOCKET_ADDRESS, "abc.com");
1280+
mockAttribute(NETWORK_PEER_ADDRESS, "abc.com");
12801281
validateRemoteResourceAttributes("DB::Connection", "db_name|abc.com");
12811282
mockAttribute(DB_NAME, null);
1282-
mockAttribute(AwsMetricAttributeGenerator.SERVER_SOCKET_ADDRESS, null);
1283+
mockAttribute(NETWORK_PEER_ADDRESS, null);
12831284

1284-
// Validate behaviour of SERVER_SOCKET_PORT exist, then remove it.
1285-
mockAttribute(AwsMetricAttributeGenerator.SERVER_SOCKET_PORT, 3306L);
1285+
// Validate behaviour of NETWORK_PEER_PORT exist, then remove it.
1286+
mockAttribute(NETWORK_PEER_PORT, 3306L);
12861287
when(spanDataMock.getKind()).thenReturn(SpanKind.CLIENT);
12871288
actualAttributes =
12881289
GENERATOR.generateMetricAttributeMapFromSpan(spanDataMock, resource).get(DEPENDENCY_METRIC);
12891290
assertThat(actualAttributes.get(AWS_REMOTE_RESOURCE_TYPE)).isNull();
12901291
assertThat(actualAttributes.get(AWS_REMOTE_RESOURCE_IDENTIFIER)).isNull();
1291-
mockAttribute(AwsMetricAttributeGenerator.SERVER_SOCKET_PORT, null);
1292+
mockAttribute(NETWORK_PEER_PORT, null);
12921293

12931294
// Validate behaviour of only DB_NAME exist, then remove it.
12941295
mockAttribute(DB_NAME, "db_name");
@@ -1614,6 +1615,36 @@ public void testDbUserPresentAndIsDbSpanFalse() {
16141615
assertThat(actualAttributes.get(AWS_REMOTE_DB_USER)).isNull();
16151616
}
16161617

1618+
@Test
1619+
public void testGetRemoteOperationWithFallback_NewKeyPresent() {
1620+
mockAttribute(MESSAGING_OPERATION_TYPE, "send");
1621+
mockAttribute(MESSAGING_OPERATION, "publish");
1622+
String result =
1623+
AwsMetricAttributeGenerator.getRemoteOperationWithFallback(
1624+
spanDataMock, MESSAGING_OPERATION_TYPE, MESSAGING_OPERATION);
1625+
1626+
assertThat(result).isEqualTo("send");
1627+
}
1628+
1629+
@Test
1630+
public void testGetRemoteOperationWithFallback_DeprecatedKeyPresent() {
1631+
mockAttribute(MESSAGING_OPERATION, "publish");
1632+
String result =
1633+
AwsMetricAttributeGenerator.getRemoteOperationWithFallback(
1634+
spanDataMock, MESSAGING_OPERATION_TYPE, MESSAGING_OPERATION);
1635+
1636+
assertThat(result).isEqualTo("publish");
1637+
}
1638+
1639+
@Test
1640+
public void testGetRemoteOperationWithFallback_BothKeysAbsent() {
1641+
String result =
1642+
AwsMetricAttributeGenerator.getRemoteOperationWithFallback(
1643+
spanDataMock, MESSAGING_OPERATION_TYPE, MESSAGING_OPERATION);
1644+
1645+
assertThat(result).isEqualTo(UNKNOWN_REMOTE_OPERATION);
1646+
}
1647+
16171648
@Test
16181649
public void testNormalizeRemoteServiceName_NoNormalization() {
16191650
String serviceName = "non aws service";

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

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD;
1919
import static io.opentelemetry.semconv.UrlAttributes.URL_PATH;
2020
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION;
21+
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION_TYPE;
2122
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MessagingOperationTypeIncubatingValues.PROCESS;
2223
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MessagingOperationTypeIncubatingValues.RECEIVE;
2324
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SYSTEM;
@@ -365,13 +366,29 @@ public void testIsConsumerProcessSpanFalse() {
365366
assertThat(AwsSpanProcessingUtil.isConsumerProcessSpan(spanDataMock)).isFalse();
366367
}
367368

369+
@Test
370+
public void testIsConsumerProcessSpanFalse_with_MESSAGING_OPERATION_TYPE() {
371+
when(attributesMock.get(MESSAGING_OPERATION_TYPE)).thenReturn(RECEIVE);
372+
when(attributesMock.get(MESSAGING_OPERATION)).thenReturn(PROCESS);
373+
when(spanDataMock.getKind()).thenReturn(SpanKind.CONSUMER);
374+
assertThat(AwsSpanProcessingUtil.isConsumerProcessSpan(spanDataMock)).isFalse();
375+
}
376+
368377
@Test
369378
public void testIsConsumerProcessSpanTrue() {
370379
when(attributesMock.get(MESSAGING_OPERATION)).thenReturn(PROCESS);
371380
when(spanDataMock.getKind()).thenReturn(SpanKind.CONSUMER);
372381
assertThat(AwsSpanProcessingUtil.isConsumerProcessSpan(spanDataMock)).isTrue();
373382
}
374383

384+
@Test
385+
public void testIsConsumerProcessSpanTrue_with_MESSAGING_OPERATION_TYPE() {
386+
when(attributesMock.get(MESSAGING_OPERATION_TYPE)).thenReturn(PROCESS);
387+
when(attributesMock.get(MESSAGING_OPERATION)).thenReturn(RECEIVE);
388+
when(spanDataMock.getKind()).thenReturn(SpanKind.CONSUMER);
389+
assertThat(AwsSpanProcessingUtil.isConsumerProcessSpan(spanDataMock)).isTrue();
390+
}
391+
375392
// check that AWS SDK v1 SQS ReceiveMessage consumer spans metrics are suppressed
376393
@Test
377394
public void testNoMetricAttributesForSqsConsumerSpanAwsSdkV1() {
@@ -436,6 +453,26 @@ public void testNoMetricAttributesForAwsSdkSqsConsumerProcessSpan() {
436453
.isTrue();
437454
}
438455

456+
@Test
457+
public void
458+
testNoMetricAttributesForAwsSdkSqsConsumerProcessSpan_with_MESSAGING_OPERATION_TYPE() {
459+
InstrumentationScopeInfo instrumentationScopeInfo = mock(InstrumentationScopeInfo.class);
460+
when(instrumentationScopeInfo.getName()).thenReturn("io.opentelemetry.aws-sdk-2.2");
461+
when(spanDataMock.getInstrumentationScopeInfo()).thenReturn(instrumentationScopeInfo);
462+
when(spanDataMock.getKind()).thenReturn(SpanKind.CONSUMER);
463+
when(spanDataMock.getName()).thenReturn("Sqs.ReceiveMessage");
464+
when(attributesMock.get(MESSAGING_OPERATION_TYPE)).thenReturn(PROCESS);
465+
466+
assertThat(AwsSpanProcessingUtil.shouldGenerateServiceMetricAttributes(spanDataMock)).isFalse();
467+
assertThat(AwsSpanProcessingUtil.shouldGenerateDependencyMetricAttributes(spanDataMock))
468+
.isFalse();
469+
470+
when(attributesMock.get(MESSAGING_OPERATION_TYPE)).thenReturn(RECEIVE);
471+
assertThat(AwsSpanProcessingUtil.shouldGenerateServiceMetricAttributes(spanDataMock)).isTrue();
472+
assertThat(AwsSpanProcessingUtil.shouldGenerateDependencyMetricAttributes(spanDataMock))
473+
.isTrue();
474+
}
475+
439476
@Test
440477
public void testSqlDialectKeywordsOrder() {
441478
List<String> keywords = getDialectKeywords();
@@ -454,4 +491,57 @@ public void testSqlDialectKeywordsMaxLength() {
454491
assertThat(MAX_KEYWORD_LENGTH >= keyword.length());
455492
}
456493
}
494+
495+
@Test
496+
public void testIsKeyPresentWithFallback_NewKeyPresent() {
497+
when(attributesMock.get(MESSAGING_OPERATION_TYPE)).thenReturn("publish");
498+
assertThat(
499+
AwsSpanProcessingUtil.isKeyPresentWithFallback(
500+
spanDataMock, MESSAGING_OPERATION_TYPE, MESSAGING_OPERATION))
501+
.isTrue();
502+
}
503+
504+
@Test
505+
public void testIsKeyPresentWithFallback_DeprecatedKeyPresent() {
506+
when(attributesMock.get(MESSAGING_OPERATION)).thenReturn("publish");
507+
assertThat(
508+
AwsSpanProcessingUtil.isKeyPresentWithFallback(
509+
spanDataMock, MESSAGING_OPERATION_TYPE, MESSAGING_OPERATION))
510+
.isTrue();
511+
}
512+
513+
@Test
514+
public void testIsKeyPresentWithFallback_BothKeysAbsent() {
515+
assertThat(
516+
AwsSpanProcessingUtil.isKeyPresentWithFallback(
517+
spanDataMock, MESSAGING_OPERATION_TYPE, MESSAGING_OPERATION))
518+
.isFalse();
519+
}
520+
521+
@Test
522+
public void testGetKeyValueWithFallback_NewKeyPresent() {
523+
when(attributesMock.get(MESSAGING_OPERATION_TYPE)).thenReturn("send");
524+
when(attributesMock.get(MESSAGING_OPERATION)).thenReturn("publish");
525+
assertThat(
526+
AwsSpanProcessingUtil.getKeyValueWithFallback(
527+
spanDataMock, MESSAGING_OPERATION_TYPE, MESSAGING_OPERATION))
528+
.isEqualTo("send");
529+
}
530+
531+
@Test
532+
public void testGetKeyValueWithFallback_DeprecatedKeyPresent() {
533+
when(attributesMock.get(MESSAGING_OPERATION)).thenReturn("publish");
534+
assertThat(
535+
AwsSpanProcessingUtil.getKeyValueWithFallback(
536+
spanDataMock, MESSAGING_OPERATION_TYPE, MESSAGING_OPERATION))
537+
.isEqualTo("publish");
538+
}
539+
540+
@Test
541+
public void testGetKeyValueWithFallback_BothKeysAbsent() {
542+
assertThat(
543+
AwsSpanProcessingUtil.getKeyValueWithFallback(
544+
spanDataMock, MESSAGING_OPERATION_TYPE, MESSAGING_OPERATION))
545+
.isNull();
546+
}
457547
}

0 commit comments

Comments
 (0)