Skip to content

Commit c17a124

Browse files
committed
Move EC2 Metadata Span Check
1 parent ff3554b commit c17a124

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

awsagentprovider/src/main/java/software/amazon/opentelemetry/javaagent/providers/AwsSpanMetricsProcessor.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,8 @@ public void onEnd(ReadableSpan span) {
122122
Map<String, Attributes> attributeMap =
123123
generator.generateMetricAttributeMapFromSpan(spanData, resource);
124124

125-
if (!isEc2MetadataSpan(attributeMap)) {
126-
for (Map.Entry<String, Attributes> attribute : attributeMap.entrySet()) {
127-
recordMetrics(span, spanData, attribute.getValue());
128-
}
125+
for (Map.Entry<String, Attributes> attribute : attributeMap.entrySet()) {
126+
recordMetrics(span, spanData, attribute.getValue());
129127
}
130128
}
131129

@@ -179,20 +177,15 @@ private void recordLatency(ReadableSpan span, Attributes attributes) {
179177

180178
private void recordMetrics(ReadableSpan span, SpanData spanData, Attributes attributes) {
181179
// Only record metrics if non-empty attributes are returned.
182-
if (!attributes.isEmpty()) {
180+
if (!attributes.isEmpty() && !isEc2MetadataSpan((attributes))) {
183181
recordErrorOrFault(spanData, attributes);
184182
recordLatency(span, attributes);
185183
}
186184
}
187185

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)) {
186+
private boolean isEc2MetadataSpan(Attributes attributes) {
187+
if (attributes.get(AWS_REMOTE_SERVICE) != null
188+
&& attributes.get(AWS_REMOTE_SERVICE).equals(EC2_METADATA_API_IP)) {
196189
return true;
197190
}
198191

0 commit comments

Comments
 (0)