Skip to content

Commit

Permalink
replace deprecated semantic attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
bjrara committed Dec 14, 2023
1 parent dd90422 commit 3d2f68c
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
import static io.opentelemetry.semconv.SemanticAttributes.FAAS_INVOKED_NAME;
import static io.opentelemetry.semconv.SemanticAttributes.FAAS_TRIGGER;
import static io.opentelemetry.semconv.SemanticAttributes.GRAPHQL_OPERATION_TYPE;
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_METHOD;
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_STATUS_CODE;
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_URL;
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_REQUEST_METHOD;
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_RESPONSE_STATUS_CODE;
import static io.opentelemetry.semconv.SemanticAttributes.MESSAGING_OPERATION;
import static io.opentelemetry.semconv.SemanticAttributes.MESSAGING_SYSTEM;
import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_NAME;
import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_PORT;
import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_ADDR;
import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_PORT;
import static io.opentelemetry.semconv.SemanticAttributes.PEER_SERVICE;
import static io.opentelemetry.semconv.SemanticAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.SemanticAttributes.RPC_SERVICE;
import static io.opentelemetry.semconv.SemanticAttributes.SERVER_ADDRESS;
import static io.opentelemetry.semconv.SemanticAttributes.SERVER_PORT;
import static io.opentelemetry.semconv.SemanticAttributes.SERVER_SOCKET_ADDRESS;
import static io.opentelemetry.semconv.SemanticAttributes.SERVER_SOCKET_PORT;
import static io.opentelemetry.semconv.SemanticAttributes.URL_FULL;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_BUCKET_NAME;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LOCAL_OPERATION;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LOCAL_SERVICE;
Expand Down Expand Up @@ -288,8 +288,8 @@ private static void setRemoteServiceAndOperation(SpanData span, AttributesBuilde
*/
private static String generateRemoteOperation(SpanData span) {
String remoteOperation = UNKNOWN_REMOTE_OPERATION;
if (isKeyPresent(span, HTTP_URL)) {
String httpUrl = span.getAttributes().get(HTTP_URL);
if (isKeyPresent(span, URL_FULL)) {
String httpUrl = span.getAttributes().get(URL_FULL);
try {
URL url;
if (httpUrl != null) {
Expand All @@ -300,8 +300,8 @@ private static String generateRemoteOperation(SpanData span) {
logger.log(Level.FINEST, "invalid http.url attribute: ", httpUrl);
}
}
if (isKeyPresent(span, HTTP_METHOD)) {
String httpMethod = span.getAttributes().get(HTTP_METHOD);
if (isKeyPresent(span, HTTP_REQUEST_METHOD)) {
String httpMethod = span.getAttributes().get(HTTP_REQUEST_METHOD);
remoteOperation = httpMethod + " " + remoteOperation;
}
if (remoteOperation.equals(UNKNOWN_REMOTE_OPERATION)) {
Expand All @@ -312,16 +312,16 @@ private static String generateRemoteOperation(SpanData span) {

private static String generateRemoteService(SpanData span) {
String remoteService = UNKNOWN_REMOTE_SERVICE;
if (isKeyPresent(span, NET_PEER_NAME)) {
remoteService = getRemoteService(span, NET_PEER_NAME);
if (isKeyPresent(span, NET_PEER_PORT)) {
Long port = span.getAttributes().get(NET_PEER_PORT);
if (isKeyPresent(span, SERVER_ADDRESS)) {
remoteService = getRemoteService(span, SERVER_ADDRESS);
if (isKeyPresent(span, SERVER_PORT)) {
Long port = span.getAttributes().get(SERVER_PORT);
remoteService += ":" + port;
}
} else if (isKeyPresent(span, NET_SOCK_PEER_ADDR)) {
remoteService = getRemoteService(span, NET_SOCK_PEER_ADDR);
if (isKeyPresent(span, NET_SOCK_PEER_PORT)) {
Long port = span.getAttributes().get(NET_SOCK_PEER_PORT);
} else if (isKeyPresent(span, SERVER_SOCKET_ADDRESS)) {
remoteService = getRemoteService(span, SERVER_SOCKET_ADDRESS);
if (isKeyPresent(span, SERVER_SOCKET_PORT)) {
Long port = span.getAttributes().get(SERVER_SOCKET_PORT);
remoteService += ":" + port;
}
} else {
Expand Down Expand Up @@ -349,13 +349,13 @@ private static void setSpanKindForDependency(SpanData span, AttributesBuilder bu
* allow for desired metric creation.
*/
private static void setHttpStatus(SpanData span, AttributesBuilder builder) {
if (isKeyPresent(span, HTTP_STATUS_CODE)) {
if (isKeyPresent(span, HTTP_RESPONSE_STATUS_CODE)) {
return;
}

Long statusCode = getAwsStatusCode(span);
if (statusCode != null) {
builder.put(HTTP_STATUS_CODE, statusCode);
builder.put(HTTP_RESPONSE_STATUS_CODE, statusCode);
}
}

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

package software.amazon.opentelemetry.javaagent.providers;

import static io.opentelemetry.semconv.SemanticAttributes.HTTP_STATUS_CODE;
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_RESPONSE_STATUS_CODE;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.DoubleHistogram;
Expand Down Expand Up @@ -118,11 +118,11 @@ public boolean isEndRequired() {
// possible except for the throttle
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/awsxrayexporter/internal/translator/cause.go#L121-L160
private void recordErrorOrFault(SpanData spanData, Attributes attributes) {
Long httpStatusCode = spanData.getAttributes().get(HTTP_STATUS_CODE);
Long httpStatusCode = spanData.getAttributes().get(HTTP_RESPONSE_STATUS_CODE);
StatusCode statusCode = spanData.getStatus().getStatusCode();

if (httpStatusCode == null) {
httpStatusCode = attributes.get(HTTP_STATUS_CODE);
httpStatusCode = attributes.get(HTTP_RESPONSE_STATUS_CODE);
}

if (httpStatusCode == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

package software.amazon.opentelemetry.javaagent.providers;

import static io.opentelemetry.semconv.SemanticAttributes.HTTP_METHOD;
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_TARGET;
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_REQUEST_METHOD;
import static io.opentelemetry.semconv.SemanticAttributes.MESSAGING_OPERATION;
import static io.opentelemetry.semconv.SemanticAttributes.MessagingOperationValues.PROCESS;
import static io.opentelemetry.semconv.SemanticAttributes.RPC_SYSTEM;
import static io.opentelemetry.semconv.SemanticAttributes.URL_PATH;
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LOCAL_OPERATION;

import io.opentelemetry.api.common.AttributeKey;
Expand Down Expand Up @@ -156,8 +156,8 @@ private static boolean isValidOperation(SpanData span, String operation) {
if (operation == null || operation.equals(UNKNOWN_OPERATION)) {
return false;
}
if (isKeyPresent(span, HTTP_METHOD)) {
String httpMethod = span.getAttributes().get(HTTP_METHOD);
if (isKeyPresent(span, HTTP_REQUEST_METHOD)) {
String httpMethod = span.getAttributes().get(HTTP_REQUEST_METHOD);
return !operation.equals(httpMethod);
}
return true;
Expand All @@ -169,15 +169,15 @@ private static boolean isValidOperation(SpanData span, String operation) {
*/
private static String generateIngressOperation(SpanData span) {
String operation = UNKNOWN_OPERATION;
if (isKeyPresent(span, HTTP_TARGET)) {
String httpTarget = span.getAttributes().get(HTTP_TARGET);
if (isKeyPresent(span, URL_PATH)) {
String httpTarget = span.getAttributes().get(URL_PATH);
// get the first part from API path string as operation value
// the more levels/parts we get from API path the higher chance for getting high cardinality
// data
if (httpTarget != null) {
operation = extractAPIPathValue(httpTarget);
if (isKeyPresent(span, HTTP_METHOD)) {
String httpMethod = span.getAttributes().get(HTTP_METHOD);
if (isKeyPresent(span, HTTP_REQUEST_METHOD)) {
String httpMethod = span.getAttributes().get(HTTP_REQUEST_METHOD);
if (httpMethod != null) {
operation = httpMethod + " " + operation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,23 +361,23 @@ public void testServerSpanWithNullSpanName() {
public void testServerSpanWithSpanNameAsHttpMethod() {
updateResourceWithServiceName();
when(spanDataMock.getName()).thenReturn("GET");
mockAttribute(HTTP_METHOD, "GET");
mockAttribute(HTTP_REQUEST_METHOD, "GET");

Attributes expectedAttributes =
Attributes.of(
AWS_SPAN_KIND, SpanKind.SERVER.name(),
AWS_LOCAL_SERVICE, SERVICE_NAME_VALUE,
AWS_LOCAL_OPERATION, UNKNOWN_OPERATION);
validateAttributesProducedForNonLocalRootSpanOfKind(expectedAttributes, SpanKind.SERVER);
mockAttribute(HTTP_METHOD, null);
mockAttribute(HTTP_REQUEST_METHOD, null);
}

@Test
public void testServerSpanWithSpanNameWithHttpTarget() {
updateResourceWithServiceName();
when(spanDataMock.getName()).thenReturn("POST");
mockAttribute(HTTP_METHOD, "POST");
mockAttribute(HTTP_TARGET, "/payment/123");
mockAttribute(HTTP_REQUEST_METHOD, "POST");
mockAttribute(URL_PATH, "/payment/123");

Attributes expectedAttributes =
Attributes.of(
Expand All @@ -388,8 +388,8 @@ public void testServerSpanWithSpanNameWithHttpTarget() {
AWS_LOCAL_OPERATION,
"POST /payment");
validateAttributesProducedForNonLocalRootSpanOfKind(expectedAttributes, SpanKind.SERVER);
mockAttribute(HTTP_METHOD, null);
mockAttribute(HTTP_TARGET, null);
mockAttribute(HTTP_REQUEST_METHOD, null);
mockAttribute(URL_PATH, null);
}

@Test
Expand Down Expand Up @@ -473,45 +473,45 @@ public void testRemoteAttributesCombinations() {
validateExpectedRemoteAttributes("graphql", "GraphQL operation type");
mockAttribute(GRAPHQL_OPERATION_TYPE, null);

// Validate behaviour of extracting Remote Service from net.peer.name
mockAttribute(NET_PEER_NAME, "www.example.com");
// Validate behaviour of extracting Remote Service from server.address
mockAttribute(SERVER_ADDRESS, "www.example.com");
validateExpectedRemoteAttributes("www.example.com", UNKNOWN_REMOTE_OPERATION);
mockAttribute(NET_PEER_NAME, null);
mockAttribute(SERVER_ADDRESS, null);

// Validate behaviour of extracting Remote Service from net.peer.name and net.peer.port
mockAttribute(NET_PEER_NAME, "192.168.0.0");
mockAttribute(NET_PEER_PORT, 8081L);
// Validate behaviour of extracting Remote Service from server.address and server.port
mockAttribute(SERVER_ADDRESS, "192.168.0.0");
mockAttribute(SERVER_PORT, 8081L);
validateExpectedRemoteAttributes("192.168.0.0:8081", UNKNOWN_REMOTE_OPERATION);
mockAttribute(NET_PEER_NAME, null);
mockAttribute(NET_PEER_PORT, null);
mockAttribute(SERVER_ADDRESS, null);
mockAttribute(SERVER_PORT, null);

// Validate behaviour of extracting Remote Service from net.peer.socket.addr
mockAttribute(NET_SOCK_PEER_ADDR, "www.example.com");
// Validate behaviour of extracting Remote Service from server.socket.address
mockAttribute(SERVER_SOCKET_ADDRESS, "www.example.com");
validateExpectedRemoteAttributes("www.example.com", UNKNOWN_REMOTE_OPERATION);
mockAttribute(NET_SOCK_PEER_ADDR, null);
mockAttribute(SERVER_SOCKET_ADDRESS, null);

// Validate behaviour of extracting Remote Service from net.peer.socket.addr and
// net.sock.peer.port
mockAttribute(NET_SOCK_PEER_ADDR, "192.168.0.0");
mockAttribute(NET_SOCK_PEER_PORT, 8081L);
// Validate behaviour of extracting Remote Service from server.socket.address and
// server.socket.port
mockAttribute(SERVER_SOCKET_ADDRESS, "192.168.0.0");
mockAttribute(SERVER_SOCKET_PORT, 8081L);
validateExpectedRemoteAttributes("192.168.0.0:8081", UNKNOWN_REMOTE_OPERATION);
mockAttribute(NET_SOCK_PEER_ADDR, null);
mockAttribute(NET_SOCK_PEER_PORT, null);
mockAttribute(SERVER_SOCKET_ADDRESS, null);
mockAttribute(SERVER_SOCKET_PORT, null);

// Validate behavior of Remote Operation from HttpTarget - with 1st api part, then remove it
mockAttribute(HTTP_URL, "http://www.example.com/payment/123");
// Validate behavior of Remote Operation from url - with 1st api part, then remove it
mockAttribute(URL_FULL, "http://www.example.com/payment/123");
validateExpectedRemoteAttributes(UNKNOWN_REMOTE_SERVICE, "/payment");
mockAttribute(HTTP_URL, null);
mockAttribute(URL_FULL, null);

// Validate behavior of Remote Operation from HttpTarget - without 1st api part, then remove it
mockAttribute(HTTP_URL, "http://www.example.com");
// Validate behavior of Remote Operation from url - without 1st api part, then remove it
mockAttribute(URL_FULL, "http://www.example.com");
validateExpectedRemoteAttributes(UNKNOWN_REMOTE_SERVICE, "/");
mockAttribute(HTTP_URL, null);
mockAttribute(URL_FULL, null);

// Validate behavior of Remote Operation from HttpTarget - invalid url, then remove it
mockAttribute(HTTP_URL, "abc");
// Validate behavior of Remote Operation from url - invalid url, then remove it
mockAttribute(URL_FULL, "abc");
validateExpectedRemoteAttributes(UNKNOWN_REMOTE_SERVICE, UNKNOWN_REMOTE_OPERATION);
mockAttribute(HTTP_URL, null);
mockAttribute(URL_FULL, null);

// Validate behaviour of Peer service attribute, then remove it.
mockAttribute(PEER_SERVICE, "Peer service");
Expand All @@ -529,8 +529,8 @@ public void testPeerServiceDoesOverrideOtherRemoteServices() {
validatePeerServiceDoesOverride(FAAS_INVOKED_PROVIDER);
validatePeerServiceDoesOverride(MESSAGING_SYSTEM);
validatePeerServiceDoesOverride(GRAPHQL_OPERATION_TYPE);
validatePeerServiceDoesOverride(NET_PEER_NAME);
validatePeerServiceDoesOverride(NET_SOCK_PEER_ADDR);
validatePeerServiceDoesOverride(SERVER_ADDRESS);
validatePeerServiceDoesOverride(SERVER_SOCKET_ADDRESS);
// Actually testing that peer service overrides "UnknownRemoteService".
validatePeerServiceDoesOverride(AttributeKey.stringKey("unknown.service.key"));
}
Expand Down Expand Up @@ -577,7 +577,7 @@ public void testHttpStatusAttributeNotAwsSdk() {
@Test
public void testHttpStatusAttributeStatusAlreadyPresent() {
when(instrumentationScopeInfoMock.getName()).thenReturn("aws-sdk");
mockAttribute(HTTP_STATUS_CODE, 200L);
mockAttribute(HTTP_RESPONSE_STATUS_CODE, 200L);
validateHttpStatusWithThrowable(new ThrowableWithMethodGetStatusCode(500), null);
}

Expand Down Expand Up @@ -733,9 +733,9 @@ private void validateHttpStatusForNonLocalRootWithThrowableForClient(
actualAttributes = attributeMap.get(SERVICE_METRIC);
}
}
assertThat(actualAttributes.get(HTTP_STATUS_CODE)).isEqualTo(expectedStatusCode);
assertThat(actualAttributes.get(HTTP_RESPONSE_STATUS_CODE)).isEqualTo(expectedStatusCode);
if (expectedStatusCode == null) {
assertThat(actualAttributes.asMap().containsKey(HTTP_STATUS_CODE)).isFalse();
assertThat(actualAttributes.asMap().containsKey(HTTP_RESPONSE_STATUS_CODE)).isFalse();
}
}

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

package software.amazon.opentelemetry.javaagent.providers;

import static io.opentelemetry.semconv.SemanticAttributes.HTTP_STATUS_CODE;
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_RESPONSE_STATUS_CODE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -134,7 +134,7 @@ public void testOnEndMetricsGenerationWithoutSpanAttributes() {

@Test
public void testOnEndMetricsGenerationWithoutMetricAttributes() {
Attributes spanAttributes = Attributes.of(HTTP_STATUS_CODE, 500L);
Attributes spanAttributes = Attributes.of(HTTP_RESPONSE_STATUS_CODE, 500L);
ReadableSpan readableSpanMock = buildReadableSpanMock(spanAttributes);
Map<String, Attributes> metricAttributesMap =
buildMetricAttributes(CONTAINS_NO_ATTRIBUTES, readableSpanMock.toSpanData());
Expand Down Expand Up @@ -266,7 +266,7 @@ public void testsOnEndMetricsGenerationProducerSpan() {

@Test
public void testOnEndMetricsGenerationWithoutEndRequired() {
Attributes spanAttributes = Attributes.of(HTTP_STATUS_CODE, 500L);
Attributes spanAttributes = Attributes.of(HTTP_RESPONSE_STATUS_CODE, 500L);
ReadableSpan readableSpanMock = buildReadableSpanMock(spanAttributes);
Map<String, Attributes> metricAttributesMap =
buildMetricAttributes(CONTAINS_ATTRIBUTES, readableSpanMock.toSpanData());
Expand All @@ -289,7 +289,7 @@ public void testOnEndMetricsGenerationWithoutEndRequired() {

@Test
public void testOnEndMetricsGenerationWithLatency() {
Attributes spanAttributes = Attributes.of(HTTP_STATUS_CODE, 200L);
Attributes spanAttributes = Attributes.of(HTTP_RESPONSE_STATUS_CODE, 200L);
ReadableSpan readableSpanMock = buildReadableSpanMock(spanAttributes);
Map<String, Attributes> metricAttributesMap =
buildMetricAttributes(CONTAINS_ATTRIBUTES, readableSpanMock.toSpanData());
Expand Down Expand Up @@ -433,7 +433,7 @@ private static ReadableSpan buildReadableSpanMock(

private static ReadableSpan buildReadableSpanWithThrowableMock(Throwable throwable) {
// config http status code as null
Attributes spanAttributes = Attributes.of(HTTP_STATUS_CODE, null);
Attributes spanAttributes = Attributes.of(HTTP_RESPONSE_STATUS_CODE, null);
ReadableSpan readableSpanMock = mock(ReadableSpan.class);
SpanData mockSpanData = mock(SpanData.class);
InstrumentationScopeInfo awsSdkScopeInfo =
Expand Down Expand Up @@ -469,7 +469,7 @@ private void configureMocksForOnEnd(

private void validateMetricsGeneratedForHttpStatusCode(
Long httpStatusCode, ExpectedStatusMetric expectedStatusMetric) {
Attributes spanAttributes = Attributes.of(HTTP_STATUS_CODE, httpStatusCode);
Attributes spanAttributes = Attributes.of(HTTP_RESPONSE_STATUS_CODE, httpStatusCode);
ReadableSpan readableSpanMock =
buildReadableSpanMock(spanAttributes, SpanKind.PRODUCER, null, StatusData.unset());
Map<String, Attributes> metricAttributesMap =
Expand All @@ -494,14 +494,14 @@ private void validateMetricsGeneratedForAttributeStatusCode(
Attributes.of(
AttributeKey.stringKey("new service key"),
"new service value",
HTTP_STATUS_CODE,
HTTP_RESPONSE_STATUS_CODE,
awsStatusCode));
metricAttributesMap.put(
DEPENDENCY_METRIC,
Attributes.of(
AttributeKey.stringKey("new dependency key"),
"new dependency value",
HTTP_STATUS_CODE,
HTTP_RESPONSE_STATUS_CODE,
awsStatusCode));
}
configureMocksForOnEnd(readableSpanMock, metricAttributesMap);
Expand All @@ -511,7 +511,7 @@ private void validateMetricsGeneratedForAttributeStatusCode(

private void validateMetricsGeneratedForStatusDataError(
Long httpStatusCode, ExpectedStatusMetric expectedStatusMetric) {
Attributes spanAttributes = Attributes.of(HTTP_STATUS_CODE, httpStatusCode);
Attributes spanAttributes = Attributes.of(HTTP_RESPONSE_STATUS_CODE, httpStatusCode);
ReadableSpan readableSpanMock =
buildReadableSpanMock(spanAttributes, SpanKind.PRODUCER, null, StatusData.error());
Map<String, Attributes> metricAttributesMap =
Expand All @@ -524,7 +524,7 @@ private void validateMetricsGeneratedForStatusDataError(

private void validateMetricsGeneratedForStatusDataOk(
Long httpStatusCode, ExpectedStatusMetric expectedStatusMetric) {
Attributes spanAttributes = Attributes.of(HTTP_STATUS_CODE, httpStatusCode);
Attributes spanAttributes = Attributes.of(HTTP_RESPONSE_STATUS_CODE, httpStatusCode);

ReadableSpan readableSpanMock =
buildReadableSpanMock(spanAttributes, SpanKind.PRODUCER, null, StatusData.ok());
Expand Down
Loading

0 comments on commit 3d2f68c

Please sign in to comment.