Skip to content

Commit 6b31ef6

Browse files
committed
Move EC2 Metadata Span Check
1 parent fad2e58 commit 6b31ef6

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-metrics-processor.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AttributeValue, Attributes, Context, Histogram, SpanStatusCode } from '
55
import { Resource } from '@opentelemetry/resources';
66
import { ReadableSpan, Span, SpanProcessor } from '@opentelemetry/sdk-trace-base';
77
import { SEMATTRS_HTTP_STATUS_CODE } from '@opentelemetry/semantic-conventions';
8-
import { AttributeMap, DEPENDENCY_METRIC, MetricAttributeGenerator } from './metric-attribute-generator';
8+
import { AttributeMap, MetricAttributeGenerator } from './metric-attribute-generator';
99
import { ForceFlushFunction } from './aws-span-processing-util';
1010
import { AWS_ATTRIBUTE_KEYS } from './aws-attribute-keys';
1111

@@ -88,10 +88,8 @@ export class AwsSpanMetricsProcessor implements SpanProcessor {
8888
public onEnd(span: ReadableSpan): void {
8989
const attributeMap: AttributeMap = this.generator.generateMetricAttributeMapFromSpan(span, this.resource);
9090

91-
if (!this.isEc2MetadataApiSpan(attributeMap)) {
92-
for (const attribute in attributeMap) {
93-
this.recordMetrics(span, attributeMap[attribute]);
94-
}
91+
for (const attribute in attributeMap) {
92+
this.recordMetrics(span, attributeMap[attribute]);
9593
}
9694
}
9795

@@ -137,7 +135,7 @@ export class AwsSpanMetricsProcessor implements SpanProcessor {
137135

138136
private recordMetrics(span: ReadableSpan, attributes: Attributes): void {
139137
// Only record metrics if non-empty attributes are returned.
140-
if (Object.keys(attributes).length > 0) {
138+
if (Object.keys(attributes).length > 0 && !this.isEc2MetadataApiSpan(attributes)) {
141139
this.recordErrorOrFault(span, attributes);
142140
this.recordLatency(span, attributes);
143141
}
@@ -151,7 +149,7 @@ export class AwsSpanMetricsProcessor implements SpanProcessor {
151149
return this.forceFlushFunction();
152150
}
153151

154-
private isEc2MetadataApiSpan(attributeMap: AttributeMap): boolean {
155-
return attributeMap[DEPENDENCY_METRIC]?.[AWS_ATTRIBUTE_KEYS.AWS_REMOTE_SERVICE] === this.EC2_METADATA_API_IP;
152+
private isEc2MetadataApiSpan(attributes: Attributes): boolean {
153+
return attributes[AWS_ATTRIBUTE_KEYS.AWS_REMOTE_SERVICE] === this.EC2_METADATA_API_IP;
156154
}
157155
}

0 commit comments

Comments
 (0)