Update semconv dependency version (#1585)

This commit is contained in:
Trask Stalnaker 2024-12-12 08:48:13 -08:00 committed by GitHub
parent 9ad072c556
commit 5b0e7691ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 158 additions and 209 deletions

View File

@ -13,7 +13,8 @@ dependencies {
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure") compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
implementation("com.squareup.okhttp3:okhttp") 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") annotationProcessor("com.google.auto.service:auto-service")
testImplementation("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")
}
}

View File

@ -15,24 +15,24 @@ import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_REMOTE_TARGE
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_SPAN_KIND; 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_STREAM_NAME;
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_TABLE_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.ServiceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.DB_OPERATION; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.DB_SYSTEM; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.FAAS_INVOKED_NAME; import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_INVOKED_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.FAAS_TRIGGER; import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_TRIGGER;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.GRAPHQL_OPERATION_TYPE; import static io.opentelemetry.semconv.incubating.GraphqlIncubatingAttributes.GRAPHQL_OPERATION_TYPE;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_METHOD; import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_METHOD;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_TARGET; import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_TARGET;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_URL; import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_URL;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.MESSAGING_OPERATION; import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.MESSAGING_SYSTEM; import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_NAME; import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_PEER_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_PORT; import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_PEER_PORT;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_SOCK_PEER_ADDR; import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_SOCK_PEER_ADDR;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_SOCK_PEER_PORT; import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_SOCK_PEER_PORT;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.PEER_SERVICE; import static io.opentelemetry.semconv.incubating.PeerIncubatingAttributes.PEER_SERVICE;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.RPC_METHOD; import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.RPC_SERVICE; import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SERVICE;
import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
@ -40,8 +40,8 @@ import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; import io.opentelemetry.semconv.ServiceAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.incubating.GraphqlIncubatingAttributes;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Optional; import java.util.Optional;
@ -57,6 +57,7 @@ import java.util.logging.Logger;
* represent "incoming" traffic, {@link SpanKind#CLIENT} and {@link SpanKind#PRODUCER} spans * represent "incoming" traffic, {@link SpanKind#CLIENT} and {@link SpanKind#PRODUCER} spans
* represent "outgoing" traffic, and {@link SpanKind#INTERNAL} spans are ignored. * represent "outgoing" traffic, and {@link SpanKind#INTERNAL} spans are ignored.
*/ */
@SuppressWarnings("deprecation") // uses deprecated semantic conventions
final class AwsMetricAttributeGenerator implements MetricAttributeGenerator { final class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
private static final Logger logger = private static final Logger logger =
@ -119,7 +120,7 @@ final class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
return Optional.empty(); 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) { private static void setService(Resource resource, SpanData span, AttributesBuilder builder) {
String service = resource.getAttribute(SERVICE_NAME); String service = resource.getAttribute(SERVICE_NAME);
if (service == null) { if (service == null) {
@ -195,8 +196,8 @@ final class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
* <li>DB * <li>DB
* <li>FAAS * <li>FAAS
* <li>Messaging * <li>Messaging
* <li>GraphQL - Special case, if {@link SemanticAttributes#GRAPHQL_OPERATION_TYPE} is present, * <li>GraphQL - Special case, if {@link GraphqlIncubatingAttributes#GRAPHQL_OPERATION_TYPE} is
* we use it for RemoteOperation and set RemoteService to {@link #GRAPHQL}. * present, we use it for RemoteOperation and set RemoteService to {@link #GRAPHQL}.
* </ul> * </ul>
* *
* <p>In each case, these span attributes were selected from the OpenTelemetry trace semantic * <p>In each case, these span attributes were selected from the OpenTelemetry trace semantic

View File

@ -5,7 +5,7 @@
package io.opentelemetry.contrib.awsxray; 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.common.Attributes;
import io.opentelemetry.api.metrics.DoubleHistogram; import io.opentelemetry.api.metrics.DoubleHistogram;
@ -39,6 +39,7 @@ import javax.annotation.concurrent.Immutable;
* AlwaysRecordSampler}, which will result in 100% of spans being sent to the processor. * AlwaysRecordSampler}, which will result in 100% of spans being sent to the processor.
*/ */
@Immutable @Immutable
@SuppressWarnings("deprecation") // uses deprecated semantic conventions
public final class AwsSpanMetricsProcessor implements SpanProcessor { public final class AwsSpanMetricsProcessor implements SpanProcessor {
private static final double NANOS_TO_MILLIS = 1_000_000.0; private static final double NANOS_TO_MILLIS = 1_000_000.0;

View File

@ -5,6 +5,16 @@
package io.opentelemetry.contrib.awsxray; 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.AttributeKey;
import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.SpanKind;
@ -17,8 +27,7 @@ import io.opentelemetry.sdk.trace.data.LinkData;
import io.opentelemetry.sdk.trace.samplers.Sampler; import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.opentelemetry.sdk.trace.samplers.SamplingDecision; import io.opentelemetry.sdk.trace.samplers.SamplingDecision;
import io.opentelemetry.sdk.trace.samplers.SamplingResult; import io.opentelemetry.sdk.trace.samplers.SamplingResult;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; import io.opentelemetry.semconv.incubating.CloudIncubatingAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.time.Duration; import java.time.Duration;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
@ -37,14 +46,18 @@ final class SamplingRuleApplier {
static { static {
Map<String, String> xrayCloudPlatform = new HashMap<>(); 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( 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"); "AWS::ElasticBeanstalk::Environment");
xrayCloudPlatform.put( xrayCloudPlatform.put(
ResourceAttributes.CloudPlatformValues.AWS_LAMBDA, "AWS::Lambda::Function"); CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_LAMBDA,
"AWS::Lambda::Function");
XRAY_CLOUD_PLATFORM = Collections.unmodifiableMap(xrayCloudPlatform); XRAY_CLOUD_PLATFORM = Collections.unmodifiableMap(xrayCloudPlatform);
} }
@ -162,15 +175,15 @@ final class SamplingRuleApplier {
String host = null; String host = null;
for (Map.Entry<AttributeKey<?>, Object> entry : attributes.asMap().entrySet()) { 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(); httpTarget = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.HTTP_URL)) { } else if (entry.getKey().equals(HTTP_URL)) {
httpUrl = (String) entry.getValue(); httpUrl = (String) entry.getValue();
} else if (entry.getKey().equals(SemanticAttributes.HTTP_METHOD)) { } else if (entry.getKey().equals(HTTP_METHOD)) {
httpMethod = (String) entry.getValue(); 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(); 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 // TODO (trask) remove support for deprecated http.host attribute
host = (String) entry.getValue(); host = (String) entry.getValue();
} }
@ -207,7 +220,7 @@ final class SamplingRuleApplier {
} }
return urlPathMatcher.matches(httpTarget) return urlPathMatcher.matches(httpTarget)
&& serviceNameMatcher.matches(resource.getAttribute(ResourceAttributes.SERVICE_NAME)) && serviceNameMatcher.matches(resource.getAttribute(SERVICE_NAME))
&& httpMethodMatcher.matches(httpMethod) && httpMethodMatcher.matches(httpMethod)
&& hostMatcher.matches(host) && hostMatcher.matches(host)
&& serviceTypeMatcher.matches(getServiceType(resource)) && serviceTypeMatcher.matches(getServiceType(resource))
@ -330,12 +343,12 @@ final class SamplingRuleApplier {
@Nullable @Nullable
private static String getArn(Attributes attributes, Resource resource) { 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) { if (arn != null) {
return arn; return arn;
} }
String cloudPlatform = resource.getAttributes().get(ResourceAttributes.CLOUD_PLATFORM); String cloudPlatform = resource.getAttributes().get(CLOUD_PLATFORM);
if (ResourceAttributes.CloudPlatformValues.AWS_LAMBDA.equals(cloudPlatform)) { if (CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_LAMBDA.equals(cloudPlatform)) {
return getLambdaArn(attributes, resource); return getLambdaArn(attributes, resource);
} }
return null; return null;
@ -343,16 +356,16 @@ final class SamplingRuleApplier {
@Nullable @Nullable
private static String getLambdaArn(Attributes attributes, Resource resource) { 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) { if (arn != null) {
return arn; return arn;
} }
return attributes.get(ResourceAttributes.CLOUD_RESOURCE_ID); return attributes.get(CLOUD_RESOURCE_ID);
} }
@Nullable @Nullable
private static String getServiceType(Resource resource) { private static String getServiceType(Resource resource) {
String cloudPlatform = resource.getAttributes().get(ResourceAttributes.CLOUD_PLATFORM); String cloudPlatform = resource.getAttributes().get(CLOUD_PLATFORM);
if (cloudPlatform == null) { if (cloudPlatform == null) {
return null; return null;
} }

View File

@ -15,25 +15,25 @@ import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_REMOTE_TARGE
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_SPAN_KIND; 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_STREAM_NAME;
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_TABLE_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.ServiceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.DB_OPERATION; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.DB_SYSTEM; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.FAAS_INVOKED_NAME; import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_INVOKED_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.FAAS_INVOKED_PROVIDER; import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_INVOKED_PROVIDER;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.FAAS_TRIGGER; import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_TRIGGER;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.GRAPHQL_OPERATION_TYPE; import static io.opentelemetry.semconv.incubating.GraphqlIncubatingAttributes.GRAPHQL_OPERATION_TYPE;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_METHOD; import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_METHOD;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_TARGET; import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_TARGET;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_URL; import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_URL;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.MESSAGING_OPERATION; import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.MESSAGING_SYSTEM; import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_NAME; import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_PEER_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_PORT; import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_PEER_PORT;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_SOCK_PEER_ADDR; import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_SOCK_PEER_ADDR;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_SOCK_PEER_PORT; import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_SOCK_PEER_PORT;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.PEER_SERVICE; import static io.opentelemetry.semconv.incubating.PeerIncubatingAttributes.PEER_SERVICE;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.RPC_METHOD; import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.RPC_SERVICE; import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SERVICE;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -48,6 +48,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
/** Unit tests for {@link AwsMetricAttributeGenerator}. */ /** Unit tests for {@link AwsMetricAttributeGenerator}. */
@SuppressWarnings("deprecation") // uses deprecated semantic conventions
class AwsMetricAttributeGeneratorTest { class AwsMetricAttributeGeneratorTest {
private static final AwsMetricAttributeGenerator GENERATOR = new AwsMetricAttributeGenerator(); private static final AwsMetricAttributeGenerator GENERATOR = new AwsMetricAttributeGenerator();

View File

@ -5,7 +5,7 @@
package io.opentelemetry.contrib.awsxray; 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.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
@ -36,6 +36,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
/** Unit tests for {@link AwsSpanMetricsProcessor}. */ /** Unit tests for {@link AwsSpanMetricsProcessor}. */
@SuppressWarnings("deprecation") // uses deprecated semantic conventions
class AwsSpanMetricsProcessorTest { class AwsSpanMetricsProcessorTest {
// Test constants // Test constants
private static final boolean CONTAINS_ATTRIBUTES = true; private static final boolean CONTAINS_ATTRIBUTES = true;

View File

@ -5,11 +5,11 @@
package io.opentelemetry.contrib.awsxray; package io.opentelemetry.contrib.awsxray;
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import io.opentelemetry.sdk.trace.SdkTracerProvider; import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -43,7 +43,7 @@ class AwsXrayRemoteSamplerProviderTest {
sampler -> { sampler -> {
assertThat(sampler.getClient().getSamplingRulesEndpoint()) assertThat(sampler.getClient().getSamplingRulesEndpoint())
.isEqualTo("http://localhost:2000/GetSamplingRules"); .isEqualTo("http://localhost:2000/GetSamplingRules");
assertThat(sampler.getResource().getAttribute(ResourceAttributes.SERVICE_NAME)) assertThat(sampler.getResource().getAttribute(SERVICE_NAME))
.isEqualTo("cat-service"); .isEqualTo("cat-service");
}); });
} }
@ -74,7 +74,7 @@ class AwsXrayRemoteSamplerProviderTest {
sampler -> { sampler -> {
assertThat(sampler.getClient().getSamplingRulesEndpoint()) assertThat(sampler.getClient().getSamplingRulesEndpoint())
.isEqualTo("http://localhost:3000/GetSamplingRules"); .isEqualTo("http://localhost:3000/GetSamplingRules");
assertThat(sampler.getResource().getAttribute(ResourceAttributes.SERVICE_NAME)) assertThat(sampler.getResource().getAttribute(SERVICE_NAME))
.isEqualTo("cat-service"); .isEqualTo("cat-service");
}); });
} }

View File

@ -5,7 +5,14 @@
package io.opentelemetry.contrib.awsxray; 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.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await; import static org.awaitility.Awaitility.await;
@ -22,8 +29,7 @@ import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.time.TestClock; import io.opentelemetry.sdk.testing.time.TestClock;
import io.opentelemetry.sdk.trace.samplers.SamplingDecision; import io.opentelemetry.sdk.trace.samplers.SamplingDecision;
import io.opentelemetry.sdk.trace.samplers.SamplingResult; import io.opentelemetry.sdk.trace.samplers.SamplingResult;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; import io.opentelemetry.semconv.incubating.CloudIncubatingAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.time.Duration; import java.time.Duration;
@ -35,7 +41,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@SuppressWarnings("JavaUtilDate") @SuppressWarnings({"JavaUtilDate", "deprecation"}) // uses deprecated semantic conventions
class SamplingRuleApplierTest { class SamplingRuleApplierTest {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@ -52,18 +58,16 @@ class SamplingRuleApplierTest {
private final Resource resource = private final Resource resource =
Resource.builder() Resource.builder()
.put(ResourceAttributes.SERVICE_NAME, "test-service-foo-bar") .put(SERVICE_NAME, "test-service-foo-bar")
.put(ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EKS) .put(CLOUD_PLATFORM, CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EKS)
.put( .put(AWS_ECS_CONTAINER_ARN, "arn:aws:xray:us-east-1:595986152929:my-service")
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
"arn:aws:xray:us-east-1:595986152929:my-service")
.build(); .build();
private final Attributes attributes = private final Attributes attributes =
Attributes.builder() Attributes.builder()
.put(SemanticAttributes.HTTP_METHOD, "GET") .put(HTTP_METHOD, "GET")
.put(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io") .put(NET_HOST_NAME, "opentelemetry.io")
.put(SemanticAttributes.HTTP_TARGET, "/instrument-me") .put(HTTP_TARGET, "/instrument-me")
.put(AttributeKey.stringKey("animal"), "cat") .put(AttributeKey.stringKey("animal"), "cat")
.put(AttributeKey.longKey("speed"), 10) .put(AttributeKey.longKey("speed"), 10)
.build(); .build();
@ -109,8 +113,8 @@ class SamplingRuleApplierTest {
assertThat( assertThat(
applier.matches( applier.matches(
attributes.toBuilder() attributes.toBuilder()
.remove(SemanticAttributes.HTTP_TARGET) .remove(HTTP_TARGET)
.put(SemanticAttributes.HTTP_URL, "scheme://host:port/instrument-me") .put(HTTP_URL, "scheme://host:port/instrument-me")
.build(), .build(),
resource)) resource))
.isTrue(); .isTrue();
@ -132,8 +136,7 @@ class SamplingRuleApplierTest {
@Test @Test
void methodNotMatch() { void methodNotMatch() {
Attributes attributes = Attributes attributes = this.attributes.toBuilder().put(HTTP_METHOD, "POST").build();
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "POST").build();
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
} }
@ -142,29 +145,25 @@ class SamplingRuleApplierTest {
// Replacing dot with character makes sure we're not accidentally treating dot as regex // Replacing dot with character makes sure we're not accidentally treating dot as regex
// wildcard. // wildcard.
Attributes attributes = Attributes attributes =
this.attributes.toBuilder() this.attributes.toBuilder().put(NET_HOST_NAME, "opentelemetryfio").build();
.put(SemanticAttributes.NET_HOST_NAME, "opentelemetryfio")
.build();
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
} }
@Test @Test
void pathNotMatch() { void pathNotMatch() {
Attributes attributes = Attributes attributes =
this.attributes.toBuilder().put(HTTP_TARGET, "/instrument-you").build();
assertThat(applier.matches(attributes, resource)).isFalse();
attributes =
this.attributes.toBuilder() this.attributes.toBuilder()
.put(SemanticAttributes.HTTP_TARGET, "/instrument-you") .remove(HTTP_TARGET)
.put(HTTP_URL, "scheme://host:port/instrument-you")
.build(); .build();
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
attributes = attributes =
this.attributes.toBuilder() this.attributes.toBuilder()
.remove(SemanticAttributes.HTTP_TARGET) .remove(HTTP_TARGET)
.put(SemanticAttributes.HTTP_URL, "scheme://host:port/instrument-you") .put(HTTP_URL, "scheme://host:port")
.build();
assertThat(applier.matches(attributes, resource)).isFalse();
attributes =
this.attributes.toBuilder()
.remove(SemanticAttributes.HTTP_TARGET)
.put(SemanticAttributes.HTTP_URL, "scheme://host:port")
.build(); .build();
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
@ -172,8 +171,8 @@ class SamplingRuleApplierTest {
// present. // present.
attributes = attributes =
this.attributes.toBuilder() this.attributes.toBuilder()
.remove(SemanticAttributes.HTTP_TARGET) .remove(HTTP_TARGET)
.put(SemanticAttributes.HTTP_URL, "host:port/instrument-me") .put(HTTP_URL, "host:port/instrument-me")
.build(); .build();
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
} }
@ -195,13 +194,10 @@ class SamplingRuleApplierTest {
void serviceTypeNotMatch() { void serviceTypeNotMatch() {
Resource resource = Resource resource =
this.resource.toBuilder() this.resource.toBuilder()
.put( .put(CLOUD_PLATFORM, CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EC2)
ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EC2)
.build(); .build();
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
resource = resource = Resource.create(removeAttribute(this.resource.getAttributes(), CLOUD_PLATFORM));
Resource.create(
removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_PLATFORM));
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
} }
@ -209,9 +205,7 @@ class SamplingRuleApplierTest {
void arnNotMatch() { void arnNotMatch() {
Resource resource = Resource resource =
this.resource.toBuilder() this.resource.toBuilder()
.put( .put(AWS_ECS_CONTAINER_ARN, "arn:aws:xray:us-east-1:595986152929:my-service2")
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
"arn:aws:xray:us-east-1:595986152929:my-service2")
.build(); .build();
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
} }
@ -227,18 +221,16 @@ class SamplingRuleApplierTest {
private final Resource resource = private final Resource resource =
Resource.builder() Resource.builder()
.put(ResourceAttributes.SERVICE_NAME, "test-service-foo-bar") .put(SERVICE_NAME, "test-service-foo-bar")
.put(ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EKS) .put(CLOUD_PLATFORM, CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EKS)
.put( .put(AWS_ECS_CONTAINER_ARN, "arn:aws:xray:us-east-1:595986152929:my-service")
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
"arn:aws:xray:us-east-1:595986152929:my-service")
.build(); .build();
private final Attributes attributes = private final Attributes attributes =
Attributes.builder() Attributes.builder()
.put(SemanticAttributes.HTTP_METHOD, "GET") .put(HTTP_METHOD, "GET")
.put(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io") .put(NET_HOST_NAME, "opentelemetry.io")
.put(SemanticAttributes.HTTP_TARGET, "/instrument-me?foo=bar&cat=meow") .put(HTTP_TARGET, "/instrument-me?foo=bar&cat=meow")
.put(AttributeKey.stringKey("animal"), "cat") .put(AttributeKey.stringKey("animal"), "cat")
.put(AttributeKey.longKey("speed"), 10) .put(AttributeKey.longKey("speed"), 10)
.build(); .build();
@ -309,104 +301,70 @@ class SamplingRuleApplierTest {
@Test @Test
void methodMatches() { void methodMatches() {
Attributes attributes = Attributes attributes = this.attributes.toBuilder().put(HTTP_METHOD, "BADGETGOOD").build();
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "BADGETGOOD").build();
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
attributes = attributes = this.attributes.toBuilder().put(HTTP_METHOD, "BADGET").build();
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "BADGET").build();
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
attributes = attributes = this.attributes.toBuilder().put(HTTP_METHOD, "GETGET").build();
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "GETGET").build();
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
} }
@Test @Test
void methodNotMatch() { void methodNotMatch() {
Attributes attributes = Attributes attributes = this.attributes.toBuilder().put(HTTP_METHOD, "POST").build();
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "POST").build();
assertThat(applier.matches(attributes, resource)).isFalse(); 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(); assertThat(applier.matches(attributes, resource)).isFalse();
} }
@Test @Test
void hostMatches() { void hostMatches() {
Attributes attributes = Attributes attributes =
this.attributes.toBuilder() this.attributes.toBuilder().put(NET_HOST_NAME, "alpha.opentelemetry.io").build();
.put(SemanticAttributes.NET_HOST_NAME, "alpha.opentelemetry.io")
.build();
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
attributes = attributes = this.attributes.toBuilder().put(NET_HOST_NAME, "opfdnqtelemetry.io").build();
this.attributes.toBuilder()
.put(SemanticAttributes.NET_HOST_NAME, "opfdnqtelemetry.io")
.build();
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
attributes = attributes = this.attributes.toBuilder().put(NET_HOST_NAME, "opentglemetry.io").build();
this.attributes.toBuilder()
.put(SemanticAttributes.NET_HOST_NAME, "opentglemetry.io")
.build();
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
attributes = attributes = this.attributes.toBuilder().put(NET_HOST_NAME, "opentglemry.io").build();
this.attributes.toBuilder()
.put(SemanticAttributes.NET_HOST_NAME, "opentglemry.io")
.build();
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
attributes = attributes = this.attributes.toBuilder().put(NET_HOST_NAME, "opentglemrz.io").build();
this.attributes.toBuilder()
.put(SemanticAttributes.NET_HOST_NAME, "opentglemrz.io")
.build();
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
} }
@Test @Test
void hostNotMatch() { void hostNotMatch() {
Attributes attributes = Attributes attributes =
this.attributes.toBuilder() this.attributes.toBuilder().put(NET_HOST_NAME, "opentelemetryfio").build();
.put(SemanticAttributes.NET_HOST_NAME, "opentelemetryfio")
.build();
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
attributes = attributes = this.attributes.toBuilder().put(NET_HOST_NAME, "opentgalemetry.io").build();
this.attributes.toBuilder()
.put(SemanticAttributes.NET_HOST_NAME, "opentgalemetry.io")
.build();
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
attributes = attributes = this.attributes.toBuilder().put(NET_HOST_NAME, "alpha.oentelemetry.io").build();
this.attributes.toBuilder()
.put(SemanticAttributes.NET_HOST_NAME, "alpha.oentelemetry.io")
.build();
assertThat(applier.matches(attributes, resource)).isFalse(); 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(); assertThat(applier.matches(attributes, resource)).isFalse();
} }
@Test @Test
void pathMatches() { void pathMatches() {
Attributes attributes = Attributes attributes =
this.attributes.toBuilder() this.attributes.toBuilder().put(HTTP_TARGET, "/instrument-me?foo=bar&cat=").build();
.put(SemanticAttributes.HTTP_TARGET, "/instrument-me?foo=bar&cat=")
.build();
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
// Deceptive question mark, it's actually a wildcard :-) // Deceptive question mark, it's actually a wildcard :-)
attributes = attributes =
this.attributes.toBuilder() this.attributes.toBuilder().put(HTTP_TARGET, "/instrument-meafoo=bar&cat=").build();
.put(SemanticAttributes.HTTP_TARGET, "/instrument-meafoo=bar&cat=")
.build();
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
} }
@Test @Test
void pathNotMatch() { void pathNotMatch() {
Attributes attributes = Attributes attributes =
this.attributes.toBuilder() this.attributes.toBuilder().put(HTTP_TARGET, "/instrument-mea?foo=bar&cat=").build();
.put(SemanticAttributes.HTTP_TARGET, "/instrument-mea?foo=bar&cat=")
.build();
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
attributes = attributes =
this.attributes.toBuilder() this.attributes.toBuilder().put(HTTP_TARGET, "foo/instrument-meafoo=bar&cat=").build();
.put(SemanticAttributes.HTTP_TARGET, "foo/instrument-meafoo=bar&cat=")
.build();
assertThat(applier.matches(attributes, resource)).isFalse(); 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(); assertThat(applier.matches(attributes, resource)).isFalse();
} }
@ -441,13 +399,10 @@ class SamplingRuleApplierTest {
void serviceTypeMatches() { void serviceTypeMatches() {
Resource resource = Resource resource =
this.resource.toBuilder() this.resource.toBuilder()
.put( .put(CLOUD_PLATFORM, CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EC2)
ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EC2)
.build(); .build();
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
resource = resource = Resource.create(removeAttribute(this.resource.getAttributes(), CLOUD_PLATFORM));
Resource.create(
removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_PLATFORM));
// null matches for pattern '*' // null matches for pattern '*'
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
} }
@ -456,9 +411,7 @@ class SamplingRuleApplierTest {
void arnMatches() { void arnMatches() {
Resource resource = Resource resource =
this.resource.toBuilder() this.resource.toBuilder()
.put( .put(AWS_ECS_CONTAINER_ARN, "arn:aws:opentelemetry:us-east-3:52929:my-service")
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
"arn:aws:opentelemetry:us-east-3:52929:my-service")
.build(); .build();
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
} }
@ -467,22 +420,16 @@ class SamplingRuleApplierTest {
void arnNotMatch() { void arnNotMatch() {
Resource resource = Resource resource =
this.resource.toBuilder() this.resource.toBuilder()
.put( .put(AWS_ECS_CONTAINER_ARN, "arn:aws:xray:us-east-1:595986152929:my-service2")
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
"arn:aws:xray:us-east-1:595986152929:my-service2")
.build(); .build();
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
resource = resource =
this.resource.toBuilder() this.resource.toBuilder()
.put( .put(AWS_ECS_CONTAINER_ARN, "frn:aws:xray:us-east-1:595986152929:my-service")
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
"frn:aws:xray:us-east-1:595986152929:my-service")
.build(); .build();
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
resource = resource =
Resource.create( Resource.create(removeAttribute(this.resource.getAttributes(), AWS_ECS_CONTAINER_ARN));
removeAttribute(
this.resource.getAttributes(), ResourceAttributes.AWS_ECS_CONTAINER_ARN));
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
} }
} }
@ -497,19 +444,15 @@ class SamplingRuleApplierTest {
private final Resource resource = private final Resource resource =
Resource.builder() Resource.builder()
.put( .put(CLOUD_PLATFORM, CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_LAMBDA)
ResourceAttributes.CLOUD_PLATFORM, .put(CLOUD_RESOURCE_ID, "arn:aws:xray:us-east-1:595986152929:my-service")
ResourceAttributes.CloudPlatformValues.AWS_LAMBDA)
.put(
ResourceAttributes.CLOUD_RESOURCE_ID,
"arn:aws:xray:us-east-1:595986152929:my-service")
.build(); .build();
private final Attributes attributes = private final Attributes attributes =
Attributes.builder() Attributes.builder()
.put(SemanticAttributes.HTTP_METHOD, "GET") .put(HTTP_METHOD, "GET")
.put(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io") .put(NET_HOST_NAME, "opentelemetry.io")
.put(SemanticAttributes.HTTP_TARGET, "/instrument-me") .put(HTTP_TARGET, "/instrument-me")
.put(AttributeKey.stringKey("animal"), "cat") .put(AttributeKey.stringKey("animal"), "cat")
.put(AttributeKey.longKey("speed"), 10) .put(AttributeKey.longKey("speed"), 10)
.build(); .build();
@ -522,13 +465,10 @@ class SamplingRuleApplierTest {
@Test @Test
void spanFaasIdMatches() { void spanFaasIdMatches() {
Resource resource = Resource resource =
Resource.create( Resource.create(removeAttribute(this.resource.getAttributes(), CLOUD_RESOURCE_ID));
removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_RESOURCE_ID));
Attributes attributes = Attributes attributes =
this.attributes.toBuilder() this.attributes.toBuilder()
.put( .put(CLOUD_RESOURCE_ID, "arn:aws:xray:us-east-1:595986152929:my-service")
ResourceAttributes.CLOUD_RESOURCE_ID,
"arn:aws:xray:us-east-1:595986152929:my-service")
.build(); .build();
assertThat(applier.matches(attributes, resource)).isTrue(); assertThat(applier.matches(attributes, resource)).isTrue();
} }
@ -538,13 +478,11 @@ class SamplingRuleApplierTest {
Resource resource = Resource resource =
this.resource.toBuilder() this.resource.toBuilder()
.put( .put(
ResourceAttributes.CLOUD_PLATFORM, CLOUD_PLATFORM,
ResourceAttributes.CloudPlatformValues.GCP_CLOUD_FUNCTIONS) CloudIncubatingAttributes.CloudPlatformIncubatingValues.GCP_CLOUD_FUNCTIONS)
.build(); .build();
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
resource = resource = Resource.create(removeAttribute(this.resource.getAttributes(), CLOUD_PLATFORM));
Resource.create(
removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_PLATFORM));
assertThat(applier.matches(attributes, resource)).isFalse(); assertThat(applier.matches(attributes, resource)).isFalse();
} }
} }