Skip to content

Commit 96e4be1

Browse files
committed
Move EC2 Metadata Span Check
1 parent 1d162e4 commit 96e4be1

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing_extensions import override
66

77
from amazon.opentelemetry.distro._aws_attribute_keys import AWS_REMOTE_SERVICE
8-
from amazon.opentelemetry.distro.metric_attribute_generator import DEPENDENCY_METRIC, MetricAttributeGenerator
8+
from amazon.opentelemetry.distro.metric_attribute_generator import MetricAttributeGenerator
99
from opentelemetry.context import Context
1010
from opentelemetry.metrics import Histogram
1111
from opentelemetry.sdk.resources import Resource
@@ -86,9 +86,8 @@ def on_end(self, span: ReadableSpan) -> None:
8686
span, self._resource
8787
)
8888

89-
if not _is_ec2_metadata_api_span(attribute_dict):
90-
for attributes in attribute_dict.values():
91-
self._record_metrics(span, attributes)
89+
for attributes in attribute_dict.values():
90+
self._record_metrics(span, attributes)
9291

9392
@override
9493
def shutdown(self) -> None:
@@ -101,7 +100,7 @@ def force_flush(self, timeout_millis: float = 10_000) -> bool:
101100

102101
def _record_metrics(self, span: ReadableSpan, attributes: BoundedAttributes) -> None:
103102
# Only record metrics if non-empty attributes are returned.
104-
if len(attributes) > 0:
103+
if len(attributes) > 0 and not _is_ec2_metadata_api_span(attributes):
105104
self._record_error_or_fault(span, attributes)
106105
self._record_latency(span, attributes)
107106

@@ -140,5 +139,5 @@ def _is_not_error_or_fault(http_status_code: int) -> bool:
140139
)
141140

142141

143-
def _is_ec2_metadata_api_span(attribute_dict: Dict[str, BoundedAttributes]) -> bool:
144-
return attribute_dict.get(DEPENDENCY_METRIC, {}).get(AWS_REMOTE_SERVICE) == _EC2_METADATA_API_IP
142+
def _is_ec2_metadata_api_span(attributes: BoundedAttributes) -> bool:
143+
return attributes.get(AWS_REMOTE_SERVICE) == _EC2_METADATA_API_IP

0 commit comments

Comments
 (0)