55
66package io .opentelemetry .contrib .awsxray ;
77
8+ import static io .opentelemetry .semconv .ServiceAttributes .SERVICE_NAME ;
9+ import static io .opentelemetry .semconv .incubating .AwsIncubatingAttributes .AWS_ECS_CONTAINER_ARN ;
10+ import static io .opentelemetry .semconv .incubating .CloudIncubatingAttributes .CLOUD_PLATFORM ;
11+ import static io .opentelemetry .semconv .incubating .CloudIncubatingAttributes .CLOUD_RESOURCE_ID ;
12+ import static io .opentelemetry .semconv .incubating .HttpIncubatingAttributes .HTTP_HOST ;
13+ import static io .opentelemetry .semconv .incubating .HttpIncubatingAttributes .HTTP_METHOD ;
14+ import static io .opentelemetry .semconv .incubating .HttpIncubatingAttributes .HTTP_TARGET ;
15+ import static io .opentelemetry .semconv .incubating .HttpIncubatingAttributes .HTTP_URL ;
16+ import static io .opentelemetry .semconv .incubating .NetIncubatingAttributes .NET_HOST_NAME ;
17+
818import io .opentelemetry .api .common .AttributeKey ;
919import io .opentelemetry .api .common .Attributes ;
1020import io .opentelemetry .api .trace .SpanKind ;
1727import io .opentelemetry .sdk .trace .samplers .Sampler ;
1828import io .opentelemetry .sdk .trace .samplers .SamplingDecision ;
1929import io .opentelemetry .sdk .trace .samplers .SamplingResult ;
20- import io .opentelemetry .semconv .resource .attributes .ResourceAttributes ;
21- import io .opentelemetry .semconv .trace .attributes .SemanticAttributes ;
30+ import io .opentelemetry .semconv .incubating .CloudIncubatingAttributes ;
2231import java .time .Duration ;
2332import java .util .Collections ;
2433import java .util .Date ;
@@ -37,14 +46,18 @@ final class SamplingRuleApplier {
3746
3847 static {
3948 Map <String , String > xrayCloudPlatform = new HashMap <>();
40- xrayCloudPlatform .put (ResourceAttributes .CloudPlatformValues .AWS_EC2 , "AWS::EC2::Instance" );
41- xrayCloudPlatform .put (ResourceAttributes .CloudPlatformValues .AWS_ECS , "AWS::ECS::Container" );
42- xrayCloudPlatform .put (ResourceAttributes .CloudPlatformValues .AWS_EKS , "AWS::EKS::Container" );
4349 xrayCloudPlatform .put (
44- ResourceAttributes .CloudPlatformValues .AWS_ELASTIC_BEANSTALK ,
50+ CloudIncubatingAttributes .CloudPlatformIncubatingValues .AWS_EC2 , "AWS::EC2::Instance" );
51+ xrayCloudPlatform .put (
52+ CloudIncubatingAttributes .CloudPlatformIncubatingValues .AWS_ECS , "AWS::ECS::Container" );
53+ xrayCloudPlatform .put (
54+ CloudIncubatingAttributes .CloudPlatformIncubatingValues .AWS_EKS , "AWS::EKS::Container" );
55+ xrayCloudPlatform .put (
56+ CloudIncubatingAttributes .CloudPlatformIncubatingValues .AWS_ELASTIC_BEANSTALK ,
4557 "AWS::ElasticBeanstalk::Environment" );
4658 xrayCloudPlatform .put (
47- ResourceAttributes .CloudPlatformValues .AWS_LAMBDA , "AWS::Lambda::Function" );
59+ CloudIncubatingAttributes .CloudPlatformIncubatingValues .AWS_LAMBDA ,
60+ "AWS::Lambda::Function" );
4861 XRAY_CLOUD_PLATFORM = Collections .unmodifiableMap (xrayCloudPlatform );
4962 }
5063
@@ -162,15 +175,15 @@ boolean matches(Attributes attributes, Resource resource) {
162175 String host = null ;
163176
164177 for (Map .Entry <AttributeKey <?>, Object > entry : attributes .asMap ().entrySet ()) {
165- if (entry .getKey ().equals (SemanticAttributes . HTTP_TARGET )) {
178+ if (entry .getKey ().equals (HTTP_TARGET )) {
166179 httpTarget = (String ) entry .getValue ();
167- } else if (entry .getKey ().equals (SemanticAttributes . HTTP_URL )) {
180+ } else if (entry .getKey ().equals (HTTP_URL )) {
168181 httpUrl = (String ) entry .getValue ();
169- } else if (entry .getKey ().equals (SemanticAttributes . HTTP_METHOD )) {
182+ } else if (entry .getKey ().equals (HTTP_METHOD )) {
170183 httpMethod = (String ) entry .getValue ();
171- } else if (entry .getKey ().equals (SemanticAttributes . NET_HOST_NAME )) {
184+ } else if (entry .getKey ().equals (NET_HOST_NAME )) {
172185 host = (String ) entry .getValue ();
173- } else if (entry .getKey ().equals (SemanticAttributes . HTTP_HOST )) {
186+ } else if (entry .getKey ().equals (HTTP_HOST )) {
174187 // TODO (trask) remove support for deprecated http.host attribute
175188 host = (String ) entry .getValue ();
176189 }
@@ -207,7 +220,7 @@ boolean matches(Attributes attributes, Resource resource) {
207220 }
208221
209222 return urlPathMatcher .matches (httpTarget )
210- && serviceNameMatcher .matches (resource .getAttribute (ResourceAttributes . SERVICE_NAME ))
223+ && serviceNameMatcher .matches (resource .getAttribute (SERVICE_NAME ))
211224 && httpMethodMatcher .matches (httpMethod )
212225 && hostMatcher .matches (host )
213226 && serviceTypeMatcher .matches (getServiceType (resource ))
@@ -330,29 +343,29 @@ String getRuleName() {
330343
331344 @ Nullable
332345 private static String getArn (Attributes attributes , Resource resource ) {
333- String arn = resource .getAttributes ().get (ResourceAttributes . AWS_ECS_CONTAINER_ARN );
346+ String arn = resource .getAttributes ().get (AWS_ECS_CONTAINER_ARN );
334347 if (arn != null ) {
335348 return arn ;
336349 }
337- String cloudPlatform = resource .getAttributes ().get (ResourceAttributes . CLOUD_PLATFORM );
338- if (ResourceAttributes . CloudPlatformValues .AWS_LAMBDA .equals (cloudPlatform )) {
350+ String cloudPlatform = resource .getAttributes ().get (CLOUD_PLATFORM );
351+ if (CloudIncubatingAttributes . CloudPlatformIncubatingValues .AWS_LAMBDA .equals (cloudPlatform )) {
339352 return getLambdaArn (attributes , resource );
340353 }
341354 return null ;
342355 }
343356
344357 @ Nullable
345358 private static String getLambdaArn (Attributes attributes , Resource resource ) {
346- String arn = resource .getAttributes ().get (ResourceAttributes . CLOUD_RESOURCE_ID );
359+ String arn = resource .getAttributes ().get (CLOUD_RESOURCE_ID );
347360 if (arn != null ) {
348361 return arn ;
349362 }
350- return attributes .get (ResourceAttributes . CLOUD_RESOURCE_ID );
363+ return attributes .get (CLOUD_RESOURCE_ID );
351364 }
352365
353366 @ Nullable
354367 private static String getServiceType (Resource resource ) {
355- String cloudPlatform = resource .getAttributes ().get (ResourceAttributes . CLOUD_PLATFORM );
368+ String cloudPlatform = resource .getAttributes ().get (CLOUD_PLATFORM );
356369 if (cloudPlatform == null ) {
357370 return null ;
358371 }
0 commit comments