@@ -5,8 +5,9 @@ import { AttributeValue, Attributes, Context, Histogram, SpanStatusCode } from '
55import { Resource } from '@opentelemetry/resources' ;
66import { ReadableSpan , Span , SpanProcessor } from '@opentelemetry/sdk-trace-base' ;
77import { SEMATTRS_HTTP_STATUS_CODE } from '@opentelemetry/semantic-conventions' ;
8- import { AttributeMap , MetricAttributeGenerator } from './metric-attribute-generator' ;
8+ import { AttributeMap , DEPENDENCY_METRIC , MetricAttributeGenerator } from './metric-attribute-generator' ;
99import { ForceFlushFunction } from './aws-span-processing-util' ;
10+ import { AWS_ATTRIBUTE_KEYS } from './aws-attribute-keys' ;
1011
1112/**
1213 * This processor will generate metrics based on span data. It depends on a
@@ -33,6 +34,10 @@ export class AwsSpanMetricsProcessor implements SpanProcessor {
3334 private FAULT_CODE_LOWER_BOUND : number = 500 ;
3435 private FAULT_CODE_UPPER_BOUND : number = 599 ;
3536
37+ // EC2 Metadata API IP Address
38+ // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html#instancedata-inside-access
39+ private EC2_METADATA_API_IP : string = '169.254.169.254' ;
40+
3641 // Metric instruments
3742 private errorHistogram : Histogram ;
3843 private faultHistogram : Histogram ;
@@ -83,8 +88,10 @@ export class AwsSpanMetricsProcessor implements SpanProcessor {
8388 public onEnd ( span : ReadableSpan ) : void {
8489 const attributeMap : AttributeMap = this . generator . generateMetricAttributeMapFromSpan ( span , this . resource ) ;
8590
86- for ( const attribute in attributeMap ) {
87- this . recordMetrics ( span , attributeMap [ attribute ] ) ;
91+ if ( ! this . isEc2MetadataApiSpan ( attributeMap ) ) {
92+ for ( const attribute in attributeMap ) {
93+ this . recordMetrics ( span , attributeMap [ attribute ] ) ;
94+ }
8895 }
8996 }
9097
@@ -143,4 +150,8 @@ export class AwsSpanMetricsProcessor implements SpanProcessor {
143150 public forceFlush ( ) : Promise < void > {
144151 return this . forceFlushFunction ( ) ;
145152 }
153+
154+ private isEc2MetadataApiSpan ( attributeMap : AttributeMap ) : boolean {
155+ return attributeMap [ DEPENDENCY_METRIC ] ?. [ AWS_ATTRIBUTE_KEYS . AWS_REMOTE_SERVICE ] === this . EC2_METADATA_API_IP ;
156+ }
146157}
0 commit comments