Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Move to io.opentelemetry.semconv:opentelemetry-semconv (#1050)" #1070

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion aws-xray/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")

implementation("com.squareup.okhttp3:okhttp")
implementation("io.opentelemetry.semconv:opentelemetry-semconv")
implementation("io.opentelemetry:opentelemetry-semconv")

annotationProcessor("com.google.auto.service:auto-service")
testImplementation("com.google.auto.service:auto-service")
Expand Down Expand Up @@ -45,3 +45,10 @@ testing {
}
}
}

configurations.all {
resolutionStrategy {
// TODO this module still needs to be updated to the latest semconv
force("io.opentelemetry:opentelemetry-semconv:1.28.0-alpha")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_SPAN_KIND;
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_STREAM_NAME;
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_TABLE_NAME;
import static io.opentelemetry.semconv.ResourceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.SemanticAttributes.DB_OPERATION;
import static io.opentelemetry.semconv.SemanticAttributes.DB_SYSTEM;
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_REQUEST_METHOD;
import static io.opentelemetry.semconv.SemanticAttributes.MESSAGING_OPERATION;
import static io.opentelemetry.semconv.SemanticAttributes.MESSAGING_SYSTEM;
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 io.opentelemetry.semconv.SemanticAttributes.URL_PATH;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.DB_OPERATION;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.FAAS_INVOKED_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.FAAS_TRIGGER;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.GRAPHQL_OPERATION_TYPE;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_METHOD;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_TARGET;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_URL;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.MESSAGING_OPERATION;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.MESSAGING_SYSTEM;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_PORT;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_SOCK_PEER_ADDR;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_SOCK_PEER_PORT;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.PEER_SERVICE;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.RPC_SERVICE;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.semconv.ResourceAttributes;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Optional;
Expand Down Expand Up @@ -156,8 +156,8 @@ private static boolean isValidOperation(SpanData span) {
if (operation == null || operation.equals(UNKNOWN_OPERATION)) {
return false;
}
if (isKeyPresent(span, HTTP_REQUEST_METHOD)) {
String httpMethod = span.getAttributes().get(HTTP_REQUEST_METHOD);
if (isKeyPresent(span, HTTP_METHOD)) {
String httpMethod = span.getAttributes().get(HTTP_METHOD);
return !operation.equals(httpMethod);
}
return true;
Expand Down Expand Up @@ -260,15 +260,15 @@ private static void setRemoteServiceAndOperation(SpanData span, AttributesBuilde
*/
private static String generateIngressOperation(SpanData span) {
String operation = UNKNOWN_OPERATION;
if (isKeyPresent(span, URL_PATH)) {
String httpTarget = span.getAttributes().get(URL_PATH);
if (isKeyPresent(span, HTTP_TARGET)) {
String httpTarget = span.getAttributes().get(HTTP_TARGET);
// 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_REQUEST_METHOD)) {
String httpMethod = span.getAttributes().get(HTTP_REQUEST_METHOD);
if (isKeyPresent(span, HTTP_METHOD)) {
String httpMethod = span.getAttributes().get(HTTP_METHOD);
if (httpMethod != null) {
operation = httpMethod + " " + operation;
}
Expand All @@ -284,8 +284,8 @@ private static String generateIngressOperation(SpanData span) {
*/
private static String generateRemoteOperation(SpanData span) {
String remoteOperation = UNKNOWN_REMOTE_OPERATION;
if (isKeyPresent(span, URL_FULL)) {
String httpUrl = span.getAttributes().get(URL_FULL);
if (isKeyPresent(span, HTTP_URL)) {
String httpUrl = span.getAttributes().get(HTTP_URL);
try {
URL url;
if (httpUrl != null) {
Expand All @@ -296,8 +296,8 @@ private static String generateRemoteOperation(SpanData span) {
logger.log(Level.FINEST, "invalid http.url attribute: ", httpUrl);
}
}
if (isKeyPresent(span, HTTP_REQUEST_METHOD)) {
String httpMethod = span.getAttributes().get(HTTP_REQUEST_METHOD);
if (isKeyPresent(span, HTTP_METHOD)) {
String httpMethod = span.getAttributes().get(HTTP_METHOD);
remoteOperation = httpMethod + " " + remoteOperation;
}
if (remoteOperation.equals(UNKNOWN_REMOTE_OPERATION)) {
Expand Down Expand Up @@ -325,16 +325,16 @@ private static String extractApiPathValue(String httpTarget) {

private static String generateRemoteService(SpanData span) {
String remoteService = UNKNOWN_REMOTE_SERVICE;
if (isKeyPresent(span, SERVER_ADDRESS)) {
remoteService = getRemoteService(span, SERVER_ADDRESS);
if (isKeyPresent(span, SERVER_PORT)) {
Long port = span.getAttributes().get(SERVER_PORT);
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);
remoteService += ":" + 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);
} 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);
remoteService += ":" + port;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package io.opentelemetry.contrib.awsxray;

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

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.DoubleHistogram;
Expand Down Expand Up @@ -107,7 +107,7 @@ public boolean isEndRequired() {
}

private void recordErrorOrFault(SpanData spanData, Attributes attributes) {
Long httpStatusCode = spanData.getAttributes().get(HTTP_RESPONSE_STATUS_CODE);
Long httpStatusCode = spanData.getAttributes().get(HTTP_STATUS_CODE);
if (httpStatusCode == null) {
httpStatusCode = getAwsStatusCode(spanData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.opentelemetry.sdk.trace.samplers.SamplingDecision;
import io.opentelemetry.sdk.trace.samplers.SamplingResult;
import io.opentelemetry.semconv.ResourceAttributes;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.time.Duration;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -162,25 +162,13 @@ boolean matches(Attributes attributes, Resource resource) {
String host = null;

for (Map.Entry<AttributeKey<?>, Object> entry : attributes.asMap().entrySet()) {
if (entry.getKey().equals(SemanticAttributes.URL_PATH)) {
if (entry.getKey().equals(SemanticAttributes.HTTP_TARGET)) {
httpTarget = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.HTTP_TARGET)) {
// TODO remove support for deprecated http.target attribute
httpTarget = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.URL_FULL)) {
httpUrl = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.HTTP_URL)) {
// TODO remove support for deprecated http.url attribute
httpUrl = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.HTTP_REQUEST_METHOD)) {
httpMethod = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.HTTP_METHOD)) {
// TODO remove support for deprecated http.method attribute
httpMethod = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.SERVER_ADDRESS)) {
host = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.NET_HOST_NAME)) {
// TODO remove support for deprecated net.host.name attribute
host = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.HTTP_HOST)) {
// TODO (trask) remove support for deprecated http.host attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_SPAN_KIND;
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_STREAM_NAME;
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_TABLE_NAME;
import static io.opentelemetry.semconv.ResourceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.SemanticAttributes.DB_OPERATION;
import static io.opentelemetry.semconv.SemanticAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.SemanticAttributes.FAAS_INVOKED_NAME;
import static io.opentelemetry.semconv.SemanticAttributes.FAAS_INVOKED_PROVIDER;
import static io.opentelemetry.semconv.SemanticAttributes.FAAS_TRIGGER;
import static io.opentelemetry.semconv.SemanticAttributes.GRAPHQL_OPERATION_TYPE;
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_REQUEST_METHOD;
import static io.opentelemetry.semconv.SemanticAttributes.MESSAGING_OPERATION;
import static io.opentelemetry.semconv.SemanticAttributes.MESSAGING_SYSTEM;
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 io.opentelemetry.semconv.SemanticAttributes.URL_PATH;
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.DB_OPERATION;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.FAAS_INVOKED_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.FAAS_INVOKED_PROVIDER;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.FAAS_TRIGGER;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.GRAPHQL_OPERATION_TYPE;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_METHOD;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_TARGET;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_URL;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.MESSAGING_OPERATION;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.MESSAGING_SYSTEM;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_PORT;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_SOCK_PEER_ADDR;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_SOCK_PEER_PORT;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.PEER_SERVICE;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.RPC_SERVICE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -170,23 +170,23 @@ public void testServerSpanWithNullSpanName() {
public void testServerSpanWithSpanNameAsHttpMethod() {
updateResourceWithServiceName();
when(spanDataMock.getName()).thenReturn("GET");
mockAttribute(HTTP_REQUEST_METHOD, "GET");
mockAttribute(HTTP_METHOD, "GET");

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

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

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

@Test
Expand Down Expand Up @@ -283,44 +283,44 @@ public void testRemoteAttributesCombinations() {
mockAttribute(GRAPHQL_OPERATION_TYPE, null);

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

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

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

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

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

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

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

// Validate behaviour of Peer service attribute, then remove it.
mockAttribute(PEER_SERVICE, "Peer service");
Expand All @@ -338,8 +338,8 @@ public void testPeerServiceDoesOverrideOtherRemoteServices() {
validatePeerServiceDoesOverride(FAAS_INVOKED_PROVIDER);
validatePeerServiceDoesOverride(MESSAGING_SYSTEM);
validatePeerServiceDoesOverride(GRAPHQL_OPERATION_TYPE);
validatePeerServiceDoesOverride(SERVER_ADDRESS);
validatePeerServiceDoesOverride(SERVER_SOCKET_ADDRESS);
validatePeerServiceDoesOverride(NET_PEER_NAME);
validatePeerServiceDoesOverride(NET_SOCK_PEER_ADDR);
// Actually testing that peer service overrides "UnknownRemoteService".
validatePeerServiceDoesOverride(AttributeKey.stringKey("unknown.service.key"));
}
Expand Down
Loading
Loading