|
5 | 5 | from unittest import TestCase |
6 | 6 | from unittest.mock import MagicMock, call |
7 | 7 |
|
| 8 | +from amazon.opentelemetry.distro._aws_attribute_keys import AWS_REMOTE_SERVICE |
8 | 9 | from amazon.opentelemetry.distro._aws_span_processing_util import ( |
9 | 10 | should_generate_dependency_metric_attributes, |
10 | 11 | should_generate_service_metric_attributes, |
@@ -238,6 +239,15 @@ def test_on_end_metrics_generation_with_status_data_ok(self): |
238 | 239 | self._validate_metrics_generated_for_status_data_ok(599, self.ExpectedStatusMetric.FAULT) |
239 | 240 | self._validate_metrics_generated_for_status_data_ok(600, self.ExpectedStatusMetric.NEITHER) |
240 | 241 |
|
| 242 | + def test_on_end_metrics_generation_from_ec2_metadata_api(self): |
| 243 | + span_attributes: Attributes = {AWS_REMOTE_SERVICE: "169.254.169.254"} |
| 244 | + span: ReadableSpan = _build_readable_span_mock(span_attributes) |
| 245 | + metric_attributes_dict = _build_ec2_metadata_api_metric_attributes() |
| 246 | + self._configure_mock_for_on_end(span, metric_attributes_dict) |
| 247 | + |
| 248 | + self.aws_span_metrics_processor.on_end(span) |
| 249 | + self._verify_histogram_record(metric_attributes_dict, 0, 0) |
| 250 | + |
241 | 251 | def _configure_mock_for_on_end(self, span: Span, attribute_map: {str: Attributes}): |
242 | 252 | def generate_m_a_from_span_side_effect(input_span, resource): |
243 | 253 | if input_span == span and resource == self.test_resource: |
@@ -373,3 +383,10 @@ def _build_metric_attributes(contain_attributes: bool, span: Span) -> Attributes |
373 | 383 | attributes = {"new dependency key": "new dependency value"} |
374 | 384 | attribute_map[DEPENDENCY_METRIC] = attributes |
375 | 385 | return attribute_map |
| 386 | + |
| 387 | + |
| 388 | +def _build_ec2_metadata_api_metric_attributes() -> Attributes: |
| 389 | + attribute_map: Attributes = {} |
| 390 | + attributes = {AWS_REMOTE_SERVICE: "169.254.169.254"} |
| 391 | + attribute_map[DEPENDENCY_METRIC] = attributes |
| 392 | + return attribute_map |
0 commit comments