|
17 | 17 | import io.opentelemetry.sdk.trace.samplers.Sampler; |
18 | 18 | import io.opentelemetry.sdk.trace.samplers.SamplingDecision; |
19 | 19 | import io.opentelemetry.sdk.trace.samplers.SamplingResult; |
20 | | -import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; |
21 | | -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; |
| 20 | +import io.opentelemetry.semconv.incubating.CloudIncubatingAttributes; |
22 | 21 | import java.time.Duration; |
23 | 22 | import java.util.Collections; |
24 | 23 | import java.util.Date; |
|
31 | 30 | import java.util.stream.Collectors; |
32 | 31 | import javax.annotation.Nullable; |
33 | 32 |
|
| 33 | +import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME; |
| 34 | +import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_HOST; |
| 35 | +import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_METHOD; |
| 36 | +import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_TARGET; |
| 37 | +import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_URL; |
| 38 | +import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_HOST_NAME; |
| 39 | +import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_ECS_CONTAINER_ARN; |
| 40 | +import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PLATFORM; |
| 41 | +import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_RESOURCE_ID; |
| 42 | + |
34 | 43 | final class SamplingRuleApplier { |
35 | 44 |
|
36 | 45 | private static final Map<String, String> XRAY_CLOUD_PLATFORM; |
37 | 46 |
|
38 | 47 | static { |
39 | 48 | 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"); |
| 49 | + xrayCloudPlatform.put(CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EC2, "AWS::EC2::Instance"); |
| 50 | + xrayCloudPlatform.put(CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_ECS, "AWS::ECS::Container"); |
| 51 | + xrayCloudPlatform.put(CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EKS, "AWS::EKS::Container"); |
43 | 52 | xrayCloudPlatform.put( |
44 | | - ResourceAttributes.CloudPlatformValues.AWS_ELASTIC_BEANSTALK, |
| 53 | + CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_ELASTIC_BEANSTALK, |
45 | 54 | "AWS::ElasticBeanstalk::Environment"); |
46 | 55 | xrayCloudPlatform.put( |
47 | | - ResourceAttributes.CloudPlatformValues.AWS_LAMBDA, "AWS::Lambda::Function"); |
| 56 | + CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_LAMBDA, "AWS::Lambda::Function"); |
48 | 57 | XRAY_CLOUD_PLATFORM = Collections.unmodifiableMap(xrayCloudPlatform); |
49 | 58 | } |
50 | 59 |
|
@@ -162,15 +171,15 @@ boolean matches(Attributes attributes, Resource resource) { |
162 | 171 | String host = null; |
163 | 172 |
|
164 | 173 | for (Map.Entry<AttributeKey<?>, Object> entry : attributes.asMap().entrySet()) { |
165 | | - if (entry.getKey().equals(SemanticAttributes.HTTP_TARGET)) { |
| 174 | + if (entry.getKey().equals(HTTP_TARGET)) { |
166 | 175 | httpTarget = (String) entry.getValue(); |
167 | | - } else if (entry.getKey().equals(SemanticAttributes.HTTP_URL)) { |
| 176 | + } else if (entry.getKey().equals(HTTP_URL)) { |
168 | 177 | httpUrl = (String) entry.getValue(); |
169 | | - } else if (entry.getKey().equals(SemanticAttributes.HTTP_METHOD)) { |
| 178 | + } else if (entry.getKey().equals(HTTP_METHOD)) { |
170 | 179 | httpMethod = (String) entry.getValue(); |
171 | | - } else if (entry.getKey().equals(SemanticAttributes.NET_HOST_NAME)) { |
| 180 | + } else if (entry.getKey().equals(NET_HOST_NAME)) { |
172 | 181 | host = (String) entry.getValue(); |
173 | | - } else if (entry.getKey().equals(SemanticAttributes.HTTP_HOST)) { |
| 182 | + } else if (entry.getKey().equals(HTTP_HOST)) { |
174 | 183 | // TODO (trask) remove support for deprecated http.host attribute |
175 | 184 | host = (String) entry.getValue(); |
176 | 185 | } |
@@ -207,7 +216,7 @@ boolean matches(Attributes attributes, Resource resource) { |
207 | 216 | } |
208 | 217 |
|
209 | 218 | return urlPathMatcher.matches(httpTarget) |
210 | | - && serviceNameMatcher.matches(resource.getAttribute(ResourceAttributes.SERVICE_NAME)) |
| 219 | + && serviceNameMatcher.matches(resource.getAttribute(SERVICE_NAME)) |
211 | 220 | && httpMethodMatcher.matches(httpMethod) |
212 | 221 | && hostMatcher.matches(host) |
213 | 222 | && serviceTypeMatcher.matches(getServiceType(resource)) |
@@ -330,29 +339,29 @@ String getRuleName() { |
330 | 339 |
|
331 | 340 | @Nullable |
332 | 341 | private static String getArn(Attributes attributes, Resource resource) { |
333 | | - String arn = resource.getAttributes().get(ResourceAttributes.AWS_ECS_CONTAINER_ARN); |
| 342 | + String arn = resource.getAttributes().get(AWS_ECS_CONTAINER_ARN); |
334 | 343 | if (arn != null) { |
335 | 344 | return arn; |
336 | 345 | } |
337 | | - String cloudPlatform = resource.getAttributes().get(ResourceAttributes.CLOUD_PLATFORM); |
338 | | - if (ResourceAttributes.CloudPlatformValues.AWS_LAMBDA.equals(cloudPlatform)) { |
| 346 | + String cloudPlatform = resource.getAttributes().get(CLOUD_PLATFORM); |
| 347 | + if (CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_LAMBDA.equals(cloudPlatform)) { |
339 | 348 | return getLambdaArn(attributes, resource); |
340 | 349 | } |
341 | 350 | return null; |
342 | 351 | } |
343 | 352 |
|
344 | 353 | @Nullable |
345 | 354 | private static String getLambdaArn(Attributes attributes, Resource resource) { |
346 | | - String arn = resource.getAttributes().get(ResourceAttributes.CLOUD_RESOURCE_ID); |
| 355 | + String arn = resource.getAttributes().get(CLOUD_RESOURCE_ID); |
347 | 356 | if (arn != null) { |
348 | 357 | return arn; |
349 | 358 | } |
350 | | - return attributes.get(ResourceAttributes.CLOUD_RESOURCE_ID); |
| 359 | + return attributes.get(CLOUD_RESOURCE_ID); |
351 | 360 | } |
352 | 361 |
|
353 | 362 | @Nullable |
354 | 363 | private static String getServiceType(Resource resource) { |
355 | | - String cloudPlatform = resource.getAttributes().get(ResourceAttributes.CLOUD_PLATFORM); |
| 364 | + String cloudPlatform = resource.getAttributes().get(CLOUD_PLATFORM); |
356 | 365 | if (cloudPlatform == null) { |
357 | 366 | return null; |
358 | 367 | } |
|
0 commit comments