|
17 | 17 |
|
18 | 18 | import static io.opentelemetry.semconv.SemanticAttributes.HTTP_RESPONSE_STATUS_CODE; |
19 | 19 | import static io.opentelemetry.semconv.SemanticAttributes.HTTP_STATUS_CODE; |
| 20 | +import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_REMOTE_SERVICE; |
20 | 21 | import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isKeyPresent; |
21 | 22 |
|
22 | 23 | import io.opentelemetry.api.common.Attributes; |
@@ -61,6 +62,10 @@ public final class AwsSpanMetricsProcessor implements SpanProcessor { |
61 | 62 | private static final int FAULT_CODE_LOWER_BOUND = 500; |
62 | 63 | private static final int FAULT_CODE_UPPER_BOUND = 599; |
63 | 64 |
|
| 65 | + // EC2 Metadata API IP Address |
| 66 | + // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html#instancedata-inside-access |
| 67 | + private final String EC2_METADATA_API_IP = "169.254.169.254"; |
| 68 | + |
64 | 69 | // Metric instruments |
65 | 70 | private final LongHistogram errorHistogram; |
66 | 71 | private final LongHistogram faultHistogram; |
@@ -117,8 +122,10 @@ public void onEnd(ReadableSpan span) { |
117 | 122 | Map<String, Attributes> attributeMap = |
118 | 123 | generator.generateMetricAttributeMapFromSpan(spanData, resource); |
119 | 124 |
|
120 | | - for (Map.Entry<String, Attributes> attribute : attributeMap.entrySet()) { |
121 | | - recordMetrics(span, spanData, attribute.getValue()); |
| 125 | + if (!isEc2MetadataSpan(attributeMap)) { |
| 126 | + for (Map.Entry<String, Attributes> attribute : attributeMap.entrySet()) { |
| 127 | + recordMetrics(span, spanData, attribute.getValue()); |
| 128 | + } |
122 | 129 | } |
123 | 130 | } |
124 | 131 |
|
@@ -177,4 +184,18 @@ private void recordMetrics(ReadableSpan span, SpanData spanData, Attributes attr |
177 | 184 | recordLatency(span, attributes); |
178 | 185 | } |
179 | 186 | } |
| 187 | + |
| 188 | + private boolean isEc2MetadataSpan(Map<String, Attributes> attributeMap) { |
| 189 | + if (attributeMap.get(MetricAttributeGenerator.DEPENDENCY_METRIC) != null |
| 190 | + && attributeMap.get(MetricAttributeGenerator.DEPENDENCY_METRIC).get(AWS_REMOTE_SERVICE) |
| 191 | + != null |
| 192 | + && attributeMap |
| 193 | + .get(MetricAttributeGenerator.DEPENDENCY_METRIC) |
| 194 | + .get(AWS_REMOTE_SERVICE) |
| 195 | + .equals(EC2_METADATA_API_IP)) { |
| 196 | + return true; |
| 197 | + } |
| 198 | + |
| 199 | + return false; |
| 200 | + } |
180 | 201 | } |
0 commit comments