Skip to content

Commit ba00b11

Browse files
authored
Merge branch 'aws-observability:main' into main
2 parents 78fda7d + 7017193 commit ba00b11

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
"@opentelemetry/id-generator-aws-xray": "1.2.2",
104104
"@opentelemetry/instrumentation": "0.53.0",
105105
"@opentelemetry/instrumentation-aws-sdk": "0.44.0",
106+
"@opentelemetry/otlp-transformer": "0.53.0",
106107
"@opentelemetry/propagator-aws-xray": "1.26.0",
107108
"@opentelemetry/resource-detector-aws": "1.6.1",
108109
"@opentelemetry/resources": "1.26.0",

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ReadableSpan, Span, SpanProcessor } from '@opentelemetry/sdk-trace-base
77
import { SEMATTRS_HTTP_STATUS_CODE } from '@opentelemetry/semantic-conventions';
88
import { AttributeMap, MetricAttributeGenerator } from './metric-attribute-generator';
99
import { 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;
@@ -130,7 +135,7 @@ export class AwsSpanMetricsProcessor implements SpanProcessor {
130135

131136
private recordMetrics(span: ReadableSpan, attributes: Attributes): void {
132137
// Only record metrics if non-empty attributes are returned.
133-
if (Object.keys(attributes).length > 0) {
138+
if (Object.keys(attributes).length > 0 && !this.isEc2MetadataApiSpan(attributes)) {
134139
this.recordErrorOrFault(span, attributes);
135140
this.recordLatency(span, attributes);
136141
}
@@ -143,4 +148,8 @@ export class AwsSpanMetricsProcessor implements SpanProcessor {
143148
public forceFlush(): Promise<void> {
144149
return this.forceFlushFunction();
145150
}
151+
152+
private isEc2MetadataApiSpan(attributes: Attributes): boolean {
153+
return attributes[AWS_ATTRIBUTE_KEYS.AWS_REMOTE_SERVICE] === this.EC2_METADATA_API_IP;
154+
}
146155
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,22 @@ describe('AwsSpanMetricsProcessorTest', () => {
397397
validateMetricsGeneratedForStatusDataOk(600, ExpectedStatusMetric.NEITHER);
398398
});
399399

400+
it('testOnEndMetricsGenerationFromEc2MetadataApi', () => {
401+
const spanAttributes: Attributes = { [AWS_ATTRIBUTE_KEYS.AWS_REMOTE_SERVICE]: '169.254.169.254' };
402+
const readableSpanMock: ReadableSpan = buildReadableSpanMock(
403+
spanAttributes,
404+
SpanKind.CLIENT,
405+
INVALID_SPAN_CONTEXT,
406+
{ code: SpanStatusCode.UNSET }
407+
);
408+
const metricAttributesMap: AttributeMap = buildEc2MetadataApiMetricAttributes();
409+
configureMocksForOnEnd(readableSpanMock, metricAttributesMap);
410+
awsSpanMetricsProcessor.onEnd(readableSpanMock);
411+
sinon.assert.notCalled(errorHistogramMockRecord);
412+
sinon.assert.notCalled(faultHistogramMockRecord);
413+
sinon.assert.notCalled(latencyHistogramMockRecord);
414+
});
415+
400416
function buildSpanAttributes(containsAttribute: boolean): Attributes {
401417
if (containsAttribute) {
402418
return { 'original key': 'original value' };
@@ -421,6 +437,13 @@ describe('AwsSpanMetricsProcessorTest', () => {
421437
return attributesMap;
422438
}
423439

440+
function buildEc2MetadataApiMetricAttributes(): AttributeMap {
441+
const attributesMap: AttributeMap = {};
442+
const attributes: Attributes = { [AWS_ATTRIBUTE_KEYS.AWS_REMOTE_SERVICE]: '169.254.169.254' };
443+
attributesMap[DEPENDENCY_METRIC] = attributes;
444+
return attributesMap;
445+
}
446+
424447
function buildReadableSpanMock(
425448
spanAttributes: Attributes,
426449
spanKind: SpanKind = SpanKind.SERVER,

0 commit comments

Comments
 (0)