diff --git a/aws-xray/build.gradle.kts b/aws-xray/build.gradle.kts index ccec9d52f..98e362d44 100644 --- a/aws-xray/build.gradle.kts +++ b/aws-xray/build.gradle.kts @@ -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") @@ -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") - } -} diff --git a/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsMetricAttributeGenerator.java b/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsMetricAttributeGenerator.java index bf55d061e..4f20eef11 100644 --- a/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsMetricAttributeGenerator.java +++ b/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsMetricAttributeGenerator.java @@ -15,24 +15,24 @@ 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; +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; @@ -40,8 +40,8 @@ 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; @@ -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 = @@ -119,7 +120,7 @@ private static Optional 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) { @@ -195,8 +196,8 @@ private static void setEgressOperation(SpanData span, AttributesBuilder builder) *
  • DB *
  • FAAS *
  • Messaging - *
  • GraphQL - Special case, if {@link SemanticAttributes#GRAPHQL_OPERATION_TYPE} is present, - * we use it for RemoteOperation and set RemoteService to {@link #GRAPHQL}. + *
  • GraphQL - Special case, if {@link GraphqlIncubatingAttributes#GRAPHQL_OPERATION_TYPE} is + * present, we use it for RemoteOperation and set RemoteService to {@link #GRAPHQL}. * * *

    In each case, these span attributes were selected from the OpenTelemetry trace semantic diff --git a/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsSpanMetricsProcessor.java b/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsSpanMetricsProcessor.java index 7efc343a8..3f33eed24 100644 --- a/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsSpanMetricsProcessor.java +++ b/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsSpanMetricsProcessor.java @@ -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; @@ -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; diff --git a/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/SamplingRuleApplier.java b/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/SamplingRuleApplier.java index 53ab1efaf..36d29746b 100644 --- a/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/SamplingRuleApplier.java +++ b/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/SamplingRuleApplier.java @@ -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; @@ -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; @@ -37,14 +46,18 @@ final class SamplingRuleApplier { static { Map 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); } @@ -162,15 +175,15 @@ boolean matches(Attributes attributes, Resource resource) { String host = null; for (Map.Entry, 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(); } @@ -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)) @@ -330,12 +343,12 @@ 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; @@ -343,16 +356,16 @@ private static String getArn(Attributes attributes, Resource resource) { @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; } diff --git a/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsMetricAttributeGeneratorTest.java b/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsMetricAttributeGeneratorTest.java index b1df48daa..135a1eeff 100644 --- a/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsMetricAttributeGeneratorTest.java +++ b/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsMetricAttributeGeneratorTest.java @@ -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; @@ -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(); diff --git a/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsSpanMetricsProcessorTest.java b/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsSpanMetricsProcessorTest.java index 882c973c5..0836f5a8e 100644 --- a/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsSpanMetricsProcessorTest.java +++ b/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsSpanMetricsProcessorTest.java @@ -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; @@ -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; diff --git a/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsXrayRemoteSamplerProviderTest.java b/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsXrayRemoteSamplerProviderTest.java index 5a51318f2..903d5f73a 100644 --- a/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsXrayRemoteSamplerProviderTest.java +++ b/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsXrayRemoteSamplerProviderTest.java @@ -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; @@ -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"); }); } @@ -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"); }); } diff --git a/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/SamplingRuleApplierTest.java b/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/SamplingRuleApplierTest.java index 6bb6e82a4..bc7bdd3e7 100644 --- a/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/SamplingRuleApplierTest.java +++ b/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/SamplingRuleApplierTest.java @@ -5,7 +5,14 @@ package io.opentelemetry.contrib.awsxray; -import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME; +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_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 static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -22,8 +29,7 @@ import io.opentelemetry.sdk.testing.time.TestClock; 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.io.IOException; import java.io.UncheckedIOException; import java.time.Duration; @@ -35,7 +41,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -@SuppressWarnings("JavaUtilDate") +@SuppressWarnings({"JavaUtilDate", "deprecation"}) // uses deprecated semantic conventions class SamplingRuleApplierTest { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); @@ -52,18 +58,16 @@ class ExactMatch { private final Resource resource = Resource.builder() - .put(ResourceAttributes.SERVICE_NAME, "test-service-foo-bar") - .put(ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EKS) - .put( - ResourceAttributes.AWS_ECS_CONTAINER_ARN, - "arn:aws:xray:us-east-1:595986152929:my-service") + .put(SERVICE_NAME, "test-service-foo-bar") + .put(CLOUD_PLATFORM, CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EKS) + .put(AWS_ECS_CONTAINER_ARN, "arn:aws:xray:us-east-1:595986152929:my-service") .build(); private final Attributes attributes = Attributes.builder() - .put(SemanticAttributes.HTTP_METHOD, "GET") - .put(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io") - .put(SemanticAttributes.HTTP_TARGET, "/instrument-me") + .put(HTTP_METHOD, "GET") + .put(NET_HOST_NAME, "opentelemetry.io") + .put(HTTP_TARGET, "/instrument-me") .put(AttributeKey.stringKey("animal"), "cat") .put(AttributeKey.longKey("speed"), 10) .build(); @@ -109,8 +113,8 @@ void matches() { assertThat( applier.matches( attributes.toBuilder() - .remove(SemanticAttributes.HTTP_TARGET) - .put(SemanticAttributes.HTTP_URL, "scheme://host:port/instrument-me") + .remove(HTTP_TARGET) + .put(HTTP_URL, "scheme://host:port/instrument-me") .build(), resource)) .isTrue(); @@ -132,8 +136,7 @@ void serviceNameNullNotMatch() { @Test void methodNotMatch() { - Attributes attributes = - this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "POST").build(); + Attributes attributes = this.attributes.toBuilder().put(HTTP_METHOD, "POST").build(); assertThat(applier.matches(attributes, resource)).isFalse(); } @@ -142,29 +145,25 @@ void hostNotMatch() { // Replacing dot with character makes sure we're not accidentally treating dot as regex // wildcard. Attributes attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.NET_HOST_NAME, "opentelemetryfio") - .build(); + this.attributes.toBuilder().put(NET_HOST_NAME, "opentelemetryfio").build(); assertThat(applier.matches(attributes, resource)).isFalse(); } @Test void pathNotMatch() { Attributes attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.HTTP_TARGET, "/instrument-you") - .build(); + this.attributes.toBuilder().put(HTTP_TARGET, "/instrument-you").build(); assertThat(applier.matches(attributes, resource)).isFalse(); attributes = this.attributes.toBuilder() - .remove(SemanticAttributes.HTTP_TARGET) - .put(SemanticAttributes.HTTP_URL, "scheme://host:port/instrument-you") + .remove(HTTP_TARGET) + .put(HTTP_URL, "scheme://host:port/instrument-you") .build(); assertThat(applier.matches(attributes, resource)).isFalse(); attributes = this.attributes.toBuilder() - .remove(SemanticAttributes.HTTP_TARGET) - .put(SemanticAttributes.HTTP_URL, "scheme://host:port") + .remove(HTTP_TARGET) + .put(HTTP_URL, "scheme://host:port") .build(); assertThat(applier.matches(attributes, resource)).isFalse(); @@ -172,8 +171,8 @@ void pathNotMatch() { // present. attributes = this.attributes.toBuilder() - .remove(SemanticAttributes.HTTP_TARGET) - .put(SemanticAttributes.HTTP_URL, "host:port/instrument-me") + .remove(HTTP_TARGET) + .put(HTTP_URL, "host:port/instrument-me") .build(); assertThat(applier.matches(attributes, resource)).isFalse(); } @@ -195,13 +194,10 @@ void attributeMissing() { void serviceTypeNotMatch() { Resource resource = this.resource.toBuilder() - .put( - ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EC2) + .put(CLOUD_PLATFORM, CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EC2) .build(); assertThat(applier.matches(attributes, resource)).isFalse(); - resource = - Resource.create( - removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_PLATFORM)); + resource = Resource.create(removeAttribute(this.resource.getAttributes(), CLOUD_PLATFORM)); assertThat(applier.matches(attributes, resource)).isFalse(); } @@ -209,9 +205,7 @@ void serviceTypeNotMatch() { void arnNotMatch() { Resource resource = this.resource.toBuilder() - .put( - ResourceAttributes.AWS_ECS_CONTAINER_ARN, - "arn:aws:xray:us-east-1:595986152929:my-service2") + .put(AWS_ECS_CONTAINER_ARN, "arn:aws:xray:us-east-1:595986152929:my-service2") .build(); assertThat(applier.matches(attributes, resource)).isFalse(); } @@ -227,18 +221,16 @@ class WildcardMatch { private final Resource resource = Resource.builder() - .put(ResourceAttributes.SERVICE_NAME, "test-service-foo-bar") - .put(ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EKS) - .put( - ResourceAttributes.AWS_ECS_CONTAINER_ARN, - "arn:aws:xray:us-east-1:595986152929:my-service") + .put(SERVICE_NAME, "test-service-foo-bar") + .put(CLOUD_PLATFORM, CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EKS) + .put(AWS_ECS_CONTAINER_ARN, "arn:aws:xray:us-east-1:595986152929:my-service") .build(); private final Attributes attributes = Attributes.builder() - .put(SemanticAttributes.HTTP_METHOD, "GET") - .put(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io") - .put(SemanticAttributes.HTTP_TARGET, "/instrument-me?foo=bar&cat=meow") + .put(HTTP_METHOD, "GET") + .put(NET_HOST_NAME, "opentelemetry.io") + .put(HTTP_TARGET, "/instrument-me?foo=bar&cat=meow") .put(AttributeKey.stringKey("animal"), "cat") .put(AttributeKey.longKey("speed"), 10) .build(); @@ -309,104 +301,70 @@ void serviceNameNotMatch() { @Test void methodMatches() { - Attributes attributes = - this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "BADGETGOOD").build(); + Attributes attributes = this.attributes.toBuilder().put(HTTP_METHOD, "BADGETGOOD").build(); assertThat(applier.matches(attributes, resource)).isTrue(); - attributes = - this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "BADGET").build(); + attributes = this.attributes.toBuilder().put(HTTP_METHOD, "BADGET").build(); assertThat(applier.matches(attributes, resource)).isTrue(); - attributes = - this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "GETGET").build(); + attributes = this.attributes.toBuilder().put(HTTP_METHOD, "GETGET").build(); assertThat(applier.matches(attributes, resource)).isTrue(); } @Test void methodNotMatch() { - Attributes attributes = - this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "POST").build(); + Attributes attributes = this.attributes.toBuilder().put(HTTP_METHOD, "POST").build(); assertThat(applier.matches(attributes, resource)).isFalse(); - attributes = removeAttribute(this.attributes, SemanticAttributes.HTTP_METHOD); + attributes = removeAttribute(this.attributes, HTTP_METHOD); assertThat(applier.matches(attributes, resource)).isFalse(); } @Test void hostMatches() { Attributes attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.NET_HOST_NAME, "alpha.opentelemetry.io") - .build(); + this.attributes.toBuilder().put(NET_HOST_NAME, "alpha.opentelemetry.io").build(); assertThat(applier.matches(attributes, resource)).isTrue(); - attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.NET_HOST_NAME, "opfdnqtelemetry.io") - .build(); + attributes = this.attributes.toBuilder().put(NET_HOST_NAME, "opfdnqtelemetry.io").build(); assertThat(applier.matches(attributes, resource)).isTrue(); - attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.NET_HOST_NAME, "opentglemetry.io") - .build(); + attributes = this.attributes.toBuilder().put(NET_HOST_NAME, "opentglemetry.io").build(); assertThat(applier.matches(attributes, resource)).isTrue(); - attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.NET_HOST_NAME, "opentglemry.io") - .build(); + attributes = this.attributes.toBuilder().put(NET_HOST_NAME, "opentglemry.io").build(); assertThat(applier.matches(attributes, resource)).isTrue(); - attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.NET_HOST_NAME, "opentglemrz.io") - .build(); + attributes = this.attributes.toBuilder().put(NET_HOST_NAME, "opentglemrz.io").build(); assertThat(applier.matches(attributes, resource)).isTrue(); } @Test void hostNotMatch() { Attributes attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.NET_HOST_NAME, "opentelemetryfio") - .build(); + this.attributes.toBuilder().put(NET_HOST_NAME, "opentelemetryfio").build(); assertThat(applier.matches(attributes, resource)).isFalse(); - attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.NET_HOST_NAME, "opentgalemetry.io") - .build(); + attributes = this.attributes.toBuilder().put(NET_HOST_NAME, "opentgalemetry.io").build(); assertThat(applier.matches(attributes, resource)).isFalse(); - attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.NET_HOST_NAME, "alpha.oentelemetry.io") - .build(); + attributes = this.attributes.toBuilder().put(NET_HOST_NAME, "alpha.oentelemetry.io").build(); assertThat(applier.matches(attributes, resource)).isFalse(); - attributes = removeAttribute(this.attributes, SemanticAttributes.NET_HOST_NAME); + attributes = removeAttribute(this.attributes, NET_HOST_NAME); assertThat(applier.matches(attributes, resource)).isFalse(); } @Test void pathMatches() { Attributes attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.HTTP_TARGET, "/instrument-me?foo=bar&cat=") - .build(); + this.attributes.toBuilder().put(HTTP_TARGET, "/instrument-me?foo=bar&cat=").build(); assertThat(applier.matches(attributes, resource)).isTrue(); // Deceptive question mark, it's actually a wildcard :-) attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.HTTP_TARGET, "/instrument-meafoo=bar&cat=") - .build(); + this.attributes.toBuilder().put(HTTP_TARGET, "/instrument-meafoo=bar&cat=").build(); assertThat(applier.matches(attributes, resource)).isTrue(); } @Test void pathNotMatch() { Attributes attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.HTTP_TARGET, "/instrument-mea?foo=bar&cat=") - .build(); + this.attributes.toBuilder().put(HTTP_TARGET, "/instrument-mea?foo=bar&cat=").build(); assertThat(applier.matches(attributes, resource)).isFalse(); attributes = - this.attributes.toBuilder() - .put(SemanticAttributes.HTTP_TARGET, "foo/instrument-meafoo=bar&cat=") - .build(); + this.attributes.toBuilder().put(HTTP_TARGET, "foo/instrument-meafoo=bar&cat=").build(); assertThat(applier.matches(attributes, resource)).isFalse(); - attributes = removeAttribute(this.attributes, SemanticAttributes.HTTP_TARGET); + attributes = removeAttribute(this.attributes, HTTP_TARGET); assertThat(applier.matches(attributes, resource)).isFalse(); } @@ -441,13 +399,10 @@ void attributeMissing() { void serviceTypeMatches() { Resource resource = this.resource.toBuilder() - .put( - ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EC2) + .put(CLOUD_PLATFORM, CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EC2) .build(); assertThat(applier.matches(attributes, resource)).isTrue(); - resource = - Resource.create( - removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_PLATFORM)); + resource = Resource.create(removeAttribute(this.resource.getAttributes(), CLOUD_PLATFORM)); // null matches for pattern '*' assertThat(applier.matches(attributes, resource)).isTrue(); } @@ -456,9 +411,7 @@ void serviceTypeMatches() { void arnMatches() { Resource resource = this.resource.toBuilder() - .put( - ResourceAttributes.AWS_ECS_CONTAINER_ARN, - "arn:aws:opentelemetry:us-east-3:52929:my-service") + .put(AWS_ECS_CONTAINER_ARN, "arn:aws:opentelemetry:us-east-3:52929:my-service") .build(); assertThat(applier.matches(attributes, resource)).isTrue(); } @@ -467,22 +420,16 @@ void arnMatches() { void arnNotMatch() { Resource resource = this.resource.toBuilder() - .put( - ResourceAttributes.AWS_ECS_CONTAINER_ARN, - "arn:aws:xray:us-east-1:595986152929:my-service2") + .put(AWS_ECS_CONTAINER_ARN, "arn:aws:xray:us-east-1:595986152929:my-service2") .build(); assertThat(applier.matches(attributes, resource)).isFalse(); resource = this.resource.toBuilder() - .put( - ResourceAttributes.AWS_ECS_CONTAINER_ARN, - "frn:aws:xray:us-east-1:595986152929:my-service") + .put(AWS_ECS_CONTAINER_ARN, "frn:aws:xray:us-east-1:595986152929:my-service") .build(); assertThat(applier.matches(attributes, resource)).isFalse(); resource = - Resource.create( - removeAttribute( - this.resource.getAttributes(), ResourceAttributes.AWS_ECS_CONTAINER_ARN)); + Resource.create(removeAttribute(this.resource.getAttributes(), AWS_ECS_CONTAINER_ARN)); assertThat(applier.matches(attributes, resource)).isFalse(); } } @@ -497,19 +444,15 @@ class AwsLambdaTest { private final Resource resource = Resource.builder() - .put( - ResourceAttributes.CLOUD_PLATFORM, - ResourceAttributes.CloudPlatformValues.AWS_LAMBDA) - .put( - ResourceAttributes.CLOUD_RESOURCE_ID, - "arn:aws:xray:us-east-1:595986152929:my-service") + .put(CLOUD_PLATFORM, CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_LAMBDA) + .put(CLOUD_RESOURCE_ID, "arn:aws:xray:us-east-1:595986152929:my-service") .build(); private final Attributes attributes = Attributes.builder() - .put(SemanticAttributes.HTTP_METHOD, "GET") - .put(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io") - .put(SemanticAttributes.HTTP_TARGET, "/instrument-me") + .put(HTTP_METHOD, "GET") + .put(NET_HOST_NAME, "opentelemetry.io") + .put(HTTP_TARGET, "/instrument-me") .put(AttributeKey.stringKey("animal"), "cat") .put(AttributeKey.longKey("speed"), 10) .build(); @@ -522,13 +465,10 @@ void resourceFaasIdMatches() { @Test void spanFaasIdMatches() { Resource resource = - Resource.create( - removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_RESOURCE_ID)); + Resource.create(removeAttribute(this.resource.getAttributes(), CLOUD_RESOURCE_ID)); Attributes attributes = this.attributes.toBuilder() - .put( - ResourceAttributes.CLOUD_RESOURCE_ID, - "arn:aws:xray:us-east-1:595986152929:my-service") + .put(CLOUD_RESOURCE_ID, "arn:aws:xray:us-east-1:595986152929:my-service") .build(); assertThat(applier.matches(attributes, resource)).isTrue(); } @@ -538,13 +478,11 @@ void notLambdaNotMatches() { Resource resource = this.resource.toBuilder() .put( - ResourceAttributes.CLOUD_PLATFORM, - ResourceAttributes.CloudPlatformValues.GCP_CLOUD_FUNCTIONS) + CLOUD_PLATFORM, + CloudIncubatingAttributes.CloudPlatformIncubatingValues.GCP_CLOUD_FUNCTIONS) .build(); assertThat(applier.matches(attributes, resource)).isFalse(); - resource = - Resource.create( - removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_PLATFORM)); + resource = Resource.create(removeAttribute(this.resource.getAttributes(), CLOUD_PLATFORM)); assertThat(applier.matches(attributes, resource)).isFalse(); } }