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

Update semconv dependency version #1585

Merged
merged 1 commit into from
Dec 12, 2024
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
10 changes: 2 additions & 8 deletions aws-xray/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ dependencies {
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")

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

annotationProcessor("com.google.auto.service:auto-service")
testImplementation("com.google.auto.service:auto-service")
Expand Down Expand Up @@ -45,10 +46,3 @@ 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.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 static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is using incubating attributes here ok?

Copy link
Member Author

@trask trask Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may be able to revise our guidance about inlining incubating attributes now that we are planning to keep them around @jack-berg?

it's definitely nice to not inline them, since then we get the deprecation warnings and know when we need to consider making semconv updates

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laurit I think it's a good question, but I'd suggest it's ok to merge this PR as-is since it's not introducing any new problems

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think incubating attributes should be fine.

import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_INVOKED_NAME;
import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_TRIGGER;
import static io.opentelemetry.semconv.incubating.GraphqlIncubatingAttributes.GRAPHQL_OPERATION_TYPE;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_METHOD;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_TARGET;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_URL;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_PEER_NAME;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_PEER_PORT;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_SOCK_PEER_ADDR;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_SOCK_PEER_PORT;
import static io.opentelemetry.semconv.incubating.PeerIncubatingAttributes.PEER_SERVICE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.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.resource.attributes.ResourceAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentelemetry.semconv.ServiceAttributes;
import io.opentelemetry.semconv.incubating.GraphqlIncubatingAttributes;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Optional;
Expand All @@ -57,6 +57,7 @@
* represent "incoming" traffic, {@link SpanKind#CLIENT} and {@link SpanKind#PRODUCER} spans
* represent "outgoing" traffic, and {@link SpanKind#INTERNAL} spans are ignored.
*/
@SuppressWarnings("deprecation") // uses deprecated semantic conventions
final class AwsMetricAttributeGenerator implements MetricAttributeGenerator {

private static final Logger logger =
Expand Down Expand Up @@ -119,7 +120,7 @@ private static Optional<String> getRemoteTarget(SpanData span) {
return Optional.empty();
}

/** Service is always derived from {@link ResourceAttributes#SERVICE_NAME} */
/** Service is always derived from {@link ServiceAttributes#SERVICE_NAME} */
private static void setService(Resource resource, SpanData span, AttributesBuilder builder) {
String service = resource.getAttribute(SERVICE_NAME);
if (service == null) {
Expand Down Expand Up @@ -195,8 +196,8 @@ private static void setEgressOperation(SpanData span, AttributesBuilder builder)
* <li>DB
* <li>FAAS
* <li>Messaging
* <li>GraphQL - Special case, if {@link SemanticAttributes#GRAPHQL_OPERATION_TYPE} is present,
* we use it for RemoteOperation and set RemoteService to {@link #GRAPHQL}.
* <li>GraphQL - Special case, if {@link GraphqlIncubatingAttributes#GRAPHQL_OPERATION_TYPE} is
* present, we use it for RemoteOperation and set RemoteService to {@link #GRAPHQL}.
* </ul>
*
* <p>In each case, these span attributes were selected from the OpenTelemetry trace semantic
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.trace.attributes.SemanticAttributes.HTTP_STATUS_CODE;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_STATUS_CODE;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.DoubleHistogram;
Expand Down Expand Up @@ -39,6 +39,7 @@
* AlwaysRecordSampler}, which will result in 100% of spans being sent to the processor.
*/
@Immutable
@SuppressWarnings("deprecation") // uses deprecated semantic conventions
public final class AwsSpanMetricsProcessor implements SpanProcessor {

private static final double NANOS_TO_MILLIS = 1_000_000.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@

package io.opentelemetry.contrib.awsxray;

import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_ECS_CONTAINER_ARN;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PLATFORM;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_RESOURCE_ID;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_HOST;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_METHOD;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_TARGET;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_URL;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_HOST_NAME;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
Expand All @@ -17,8 +27,7 @@
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.resource.attributes.ResourceAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentelemetry.semconv.incubating.CloudIncubatingAttributes;
import java.time.Duration;
import java.util.Collections;
import java.util.Date;
Expand All @@ -37,14 +46,18 @@ final class SamplingRuleApplier {

static {
Map<String, String> xrayCloudPlatform = new HashMap<>();
xrayCloudPlatform.put(ResourceAttributes.CloudPlatformValues.AWS_EC2, "AWS::EC2::Instance");
xrayCloudPlatform.put(ResourceAttributes.CloudPlatformValues.AWS_ECS, "AWS::ECS::Container");
xrayCloudPlatform.put(ResourceAttributes.CloudPlatformValues.AWS_EKS, "AWS::EKS::Container");
xrayCloudPlatform.put(
ResourceAttributes.CloudPlatformValues.AWS_ELASTIC_BEANSTALK,
CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EC2, "AWS::EC2::Instance");
xrayCloudPlatform.put(
CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_ECS, "AWS::ECS::Container");
xrayCloudPlatform.put(
CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EKS, "AWS::EKS::Container");
xrayCloudPlatform.put(
CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_ELASTIC_BEANSTALK,
"AWS::ElasticBeanstalk::Environment");
xrayCloudPlatform.put(
ResourceAttributes.CloudPlatformValues.AWS_LAMBDA, "AWS::Lambda::Function");
CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_LAMBDA,
"AWS::Lambda::Function");
XRAY_CLOUD_PLATFORM = Collections.unmodifiableMap(xrayCloudPlatform);
}

Expand Down Expand Up @@ -162,15 +175,15 @@ boolean matches(Attributes attributes, Resource resource) {
String host = null;

for (Map.Entry<AttributeKey<?>, Object> entry : attributes.asMap().entrySet()) {
if (entry.getKey().equals(SemanticAttributes.HTTP_TARGET)) {
if (entry.getKey().equals(HTTP_TARGET)) {
httpTarget = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.HTTP_URL)) {
} else if (entry.getKey().equals(HTTP_URL)) {
httpUrl = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.HTTP_METHOD)) {
} else if (entry.getKey().equals(HTTP_METHOD)) {
httpMethod = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.NET_HOST_NAME)) {
} else if (entry.getKey().equals(NET_HOST_NAME)) {
host = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.HTTP_HOST)) {
} else if (entry.getKey().equals(HTTP_HOST)) {
// TODO (trask) remove support for deprecated http.host attribute
host = (String) entry.getValue();
}
Expand Down Expand Up @@ -207,7 +220,7 @@ boolean matches(Attributes attributes, Resource resource) {
}

return urlPathMatcher.matches(httpTarget)
&& serviceNameMatcher.matches(resource.getAttribute(ResourceAttributes.SERVICE_NAME))
&& serviceNameMatcher.matches(resource.getAttribute(SERVICE_NAME))
&& httpMethodMatcher.matches(httpMethod)
&& hostMatcher.matches(host)
&& serviceTypeMatcher.matches(getServiceType(resource))
Expand Down Expand Up @@ -330,29 +343,29 @@ String getRuleName() {

@Nullable
private static String getArn(Attributes attributes, Resource resource) {
String arn = resource.getAttributes().get(ResourceAttributes.AWS_ECS_CONTAINER_ARN);
String arn = resource.getAttributes().get(AWS_ECS_CONTAINER_ARN);
if (arn != null) {
return arn;
}
String cloudPlatform = resource.getAttributes().get(ResourceAttributes.CLOUD_PLATFORM);
if (ResourceAttributes.CloudPlatformValues.AWS_LAMBDA.equals(cloudPlatform)) {
String cloudPlatform = resource.getAttributes().get(CLOUD_PLATFORM);
if (CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_LAMBDA.equals(cloudPlatform)) {
return getLambdaArn(attributes, resource);
}
return null;
}

@Nullable
private static String getLambdaArn(Attributes attributes, Resource resource) {
String arn = resource.getAttributes().get(ResourceAttributes.CLOUD_RESOURCE_ID);
String arn = resource.getAttributes().get(CLOUD_RESOURCE_ID);
if (arn != null) {
return arn;
}
return attributes.get(ResourceAttributes.CLOUD_RESOURCE_ID);
return attributes.get(CLOUD_RESOURCE_ID);
}

@Nullable
private static String getServiceType(Resource resource) {
String cloudPlatform = resource.getAttributes().get(ResourceAttributes.CLOUD_PLATFORM);
String cloudPlatform = resource.getAttributes().get(CLOUD_PLATFORM);
if (cloudPlatform == null) {
return null;
}
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.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 io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_INVOKED_NAME;
import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_INVOKED_PROVIDER;
import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_TRIGGER;
import static io.opentelemetry.semconv.incubating.GraphqlIncubatingAttributes.GRAPHQL_OPERATION_TYPE;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_METHOD;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_TARGET;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_URL;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_PEER_NAME;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_PEER_PORT;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_SOCK_PEER_ADDR;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_SOCK_PEER_PORT;
import static io.opentelemetry.semconv.incubating.PeerIncubatingAttributes.PEER_SERVICE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SERVICE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -48,6 +48,7 @@
import org.junit.jupiter.api.Test;

/** Unit tests for {@link AwsMetricAttributeGenerator}. */
@SuppressWarnings("deprecation") // uses deprecated semantic conventions
class AwsMetricAttributeGeneratorTest {

private static final AwsMetricAttributeGenerator GENERATOR = new AwsMetricAttributeGenerator();
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.trace.attributes.SemanticAttributes.HTTP_STATUS_CODE;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_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 @@ -36,6 +36,7 @@
import org.junit.jupiter.api.Test;

/** Unit tests for {@link AwsSpanMetricsProcessor}. */
@SuppressWarnings("deprecation") // uses deprecated semantic conventions
class AwsSpanMetricsProcessorTest {
// Test constants
private static final boolean CONTAINS_ATTRIBUTES = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

package io.opentelemetry.contrib.awsxray;

import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -43,7 +43,7 @@ void serviceNameOnly() {
sampler -> {
assertThat(sampler.getClient().getSamplingRulesEndpoint())
.isEqualTo("http://localhost:2000/GetSamplingRules");
assertThat(sampler.getResource().getAttribute(ResourceAttributes.SERVICE_NAME))
assertThat(sampler.getResource().getAttribute(SERVICE_NAME))
.isEqualTo("cat-service");
});
}
Expand Down Expand Up @@ -74,7 +74,7 @@ void setEndpoint() {
sampler -> {
assertThat(sampler.getClient().getSamplingRulesEndpoint())
.isEqualTo("http://localhost:3000/GetSamplingRules");
assertThat(sampler.getResource().getAttribute(ResourceAttributes.SERVICE_NAME))
assertThat(sampler.getResource().getAttribute(SERVICE_NAME))
.isEqualTo("cat-service");
});
}
Expand Down
Loading
Loading