22
22
import static io .opentelemetry .semconv .ServerAttributes .SERVER_ADDRESS ;
23
23
import static io .opentelemetry .semconv .ServerAttributes .SERVER_PORT ;
24
24
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.
25
31
import static io .opentelemetry .semconv .incubating .DbIncubatingAttributes .DB_CONNECTION_STRING ;
26
32
import static io .opentelemetry .semconv .incubating .DbIncubatingAttributes .DB_NAME ;
27
33
import static io .opentelemetry .semconv .incubating .DbIncubatingAttributes .DB_OPERATION ;
34
40
import static io .opentelemetry .semconv .incubating .HttpIncubatingAttributes .HTTP_METHOD ;
35
41
import static io .opentelemetry .semconv .incubating .HttpIncubatingAttributes .HTTP_STATUS_CODE ;
36
42
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.
37
45
import static io .opentelemetry .semconv .incubating .MessagingIncubatingAttributes .MESSAGING_OPERATION ;
46
+ import static io .opentelemetry .semconv .incubating .MessagingIncubatingAttributes .MESSAGING_OPERATION_TYPE ;
38
47
import static io .opentelemetry .semconv .incubating .MessagingIncubatingAttributes .MESSAGING_SYSTEM ;
39
48
import static io .opentelemetry .semconv .incubating .NetIncubatingAttributes .NET_PEER_NAME ;
40
49
import static io .opentelemetry .semconv .incubating .NetIncubatingAttributes .NET_PEER_PORT ;
87
96
import static software .amazon .opentelemetry .javaagent .providers .AwsSpanProcessingUtil .isAwsSDKSpan ;
88
97
import static software .amazon .opentelemetry .javaagent .providers .AwsSpanProcessingUtil .isDBSpan ;
89
98
import static software .amazon .opentelemetry .javaagent .providers .AwsSpanProcessingUtil .isKeyPresent ;
99
+ import static software .amazon .opentelemetry .javaagent .providers .AwsSpanProcessingUtil .isKeyPresentWithFallback ;
90
100
91
101
import com .amazonaws .arn .Arn ;
92
102
import io .opentelemetry .api .common .AttributeKey ;
122
132
* represent "outgoing" traffic, and {@link SpanKind#INTERNAL} spans are ignored.
123
133
*/
124
134
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
-
134
135
private static final Logger logger =
135
136
Logger .getLogger (AwsMetricAttributeGenerator .class .getName ());
136
137
@@ -293,9 +294,11 @@ private static void setRemoteServiceAndOperation(SpanData span, AttributesBuilde
293
294
} else if (isKeyPresent (span , FAAS_INVOKED_NAME ) || isKeyPresent (span , FAAS_TRIGGER )) {
294
295
remoteService = getRemoteService (span , FAAS_INVOKED_NAME );
295
296
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 )) {
297
299
remoteService = getRemoteService (span , MESSAGING_SYSTEM );
298
- remoteOperation = getRemoteOperation (span , MESSAGING_OPERATION );
300
+ remoteOperation =
301
+ getRemoteOperationWithFallback (span , MESSAGING_OPERATION_TYPE , MESSAGING_OPERATION );
299
302
} else if (isKeyPresent (span , GRAPHQL_OPERATION_TYPE )) {
300
303
remoteService = GRAPHQL ;
301
304
remoteOperation = getRemoteOperation (span , GRAPHQL_OPERATION_TYPE );
@@ -772,15 +775,15 @@ private static Optional<String> getSnsResourceNameFromArn(Optional<String> strin
772
775
* {address} attribute is retrieved in priority order:
773
776
* - {@link SemanticAttributes#SERVER_ADDRESS},
774
777
* - {@link SemanticAttributes#NET_PEER_NAME},
775
- * - {@link SemanticAttributes#SERVER_SOCKET_ADDRESS }
778
+ * - {@link SemanticAttributes#NETWORK_PEER_ADDRESS }
776
779
* - {@link SemanticAttributes#DB_CONNECTION_STRING}-Hostname
777
780
* </pre>
778
781
*
779
782
* <pre>
780
783
* {port} attribute is retrieved in priority order:
781
784
* - {@link SemanticAttributes#SERVER_PORT},
782
785
* - {@link SemanticAttributes#NET_PEER_PORT},
783
- * - {@link SemanticAttributes#SERVER_SOCKET_PORT }
786
+ * - {@link SemanticAttributes#NETWORK_PEER_PORT }
784
787
* - {@link SemanticAttributes#DB_CONNECTION_STRING}-Port
785
788
* </pre>
786
789
*
@@ -799,9 +802,9 @@ private static Optional<String> getDbConnection(SpanData span) {
799
802
String networkPeerAddress = span .getAttributes ().get (NET_PEER_NAME );
800
803
Long networkPeerPort = span .getAttributes ().get (NET_PEER_PORT );
801
804
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 );
805
808
dbConnection = buildDbConnection (serverSocketAddress , serverSocketPort );
806
809
} else if (isKeyPresent (span , DB_CONNECTION_STRING )) {
807
810
String connectionString = span .getAttributes ().get (DB_CONNECTION_STRING );
@@ -954,6 +957,15 @@ private static String getRemoteOperation(SpanData span, AttributeKey<String> rem
954
957
return remoteOperation ;
955
958
}
956
959
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
+
957
969
/**
958
970
* If no db.operation attribute provided in the span, we use db.statement to compute a valid
959
971
* remote operation in a best-effort manner. To do this, we take the first substring of the
0 commit comments