2222import static io .opentelemetry .semconv .ServerAttributes .SERVER_ADDRESS ;
2323import static io .opentelemetry .semconv .ServerAttributes .SERVER_PORT ;
2424import 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.
2531import static io .opentelemetry .semconv .incubating .DbIncubatingAttributes .DB_CONNECTION_STRING ;
2632import static io .opentelemetry .semconv .incubating .DbIncubatingAttributes .DB_NAME ;
2733import static io .opentelemetry .semconv .incubating .DbIncubatingAttributes .DB_OPERATION ;
3440import static io .opentelemetry .semconv .incubating .HttpIncubatingAttributes .HTTP_METHOD ;
3541import static io .opentelemetry .semconv .incubating .HttpIncubatingAttributes .HTTP_STATUS_CODE ;
3642import 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.
3745import static io .opentelemetry .semconv .incubating .MessagingIncubatingAttributes .MESSAGING_OPERATION ;
46+ import static io .opentelemetry .semconv .incubating .MessagingIncubatingAttributes .MESSAGING_OPERATION_TYPE ;
3847import static io .opentelemetry .semconv .incubating .MessagingIncubatingAttributes .MESSAGING_SYSTEM ;
3948import static io .opentelemetry .semconv .incubating .NetIncubatingAttributes .NET_PEER_NAME ;
4049import static io .opentelemetry .semconv .incubating .NetIncubatingAttributes .NET_PEER_PORT ;
8796import static software .amazon .opentelemetry .javaagent .providers .AwsSpanProcessingUtil .isAwsSDKSpan ;
8897import static software .amazon .opentelemetry .javaagent .providers .AwsSpanProcessingUtil .isDBSpan ;
8998import static software .amazon .opentelemetry .javaagent .providers .AwsSpanProcessingUtil .isKeyPresent ;
99+ import static software .amazon .opentelemetry .javaagent .providers .AwsSpanProcessingUtil .isKeyPresentWithFallback ;
90100
91101import com .amazonaws .arn .Arn ;
92102import io .opentelemetry .api .common .AttributeKey ;
122132 * represent "outgoing" traffic, and {@link SpanKind#INTERNAL} spans are ignored.
123133 */
124134final 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
0 commit comments