From b40866a67ca984da37b6143d04c5bfe4df867ca3 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 12 Feb 2024 17:20:42 -0600 Subject: [PATCH 1/2] Update core SHA Fixes #2173 --- .github/workflows/instrumentations_0.yml | 2 +- .github/workflows/instrumentations_1.yml | 2 +- .github/workflows/test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/instrumentations_0.yml b/.github/workflows/instrumentations_0.yml index c0df94171d..d6a1d688e6 100644 --- a/.github/workflows/instrumentations_0.yml +++ b/.github/workflows/instrumentations_0.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: 84c0e4f38d4fcdb8c13fd3988469fbb8cda28150 + CORE_REPO_SHA: e98af82ff0ebe7e687fda265093aa576cd9ba80f jobs: instrumentations-0: diff --git a/.github/workflows/instrumentations_1.yml b/.github/workflows/instrumentations_1.yml index 5b57472076..7b1a0925cf 100644 --- a/.github/workflows/instrumentations_1.yml +++ b/.github/workflows/instrumentations_1.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: 84c0e4f38d4fcdb8c13fd3988469fbb8cda28150 + CORE_REPO_SHA: e98af82ff0ebe7e687fda265093aa576cd9ba80f jobs: instrumentations-1: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1d6b03d74b..33791db4cd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: d829e375202d0106d45d7a2441409be82086b423 + CORE_REPO_SHA: e98af82ff0ebe7e687fda265093aa576cd9ba80f jobs: misc: From 96fc338d5aa0beb34e1e3406b9b01e672c7c1735 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 12 Feb 2024 16:21:54 -0600 Subject: [PATCH 2/2] Fix celery and urllib tests Fixes #2164 --- .../tests/test_metrics.py | 42 ++++- .../tests/test_metrics_instrumentation.py | 150 ++++++++++++++++-- 2 files changed, 180 insertions(+), 12 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/tests/test_metrics.py b/instrumentation/opentelemetry-instrumentation-celery/tests/test_metrics.py index e290362e77..01c9487ea8 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/tests/test_metrics.py +++ b/instrumentation/opentelemetry-instrumentation-celery/tests/test_metrics.py @@ -64,8 +64,44 @@ def test_basic_metric(self): def test_metric_uninstrument(self): CeleryInstrumentor().instrument() - metrics = self.get_metrics() - self.assertEqual(len(metrics), 1) + + self.get_metrics() + self.assertEqual( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics[0] + .data.data_points[0] + .bucket_counts[1] + ), + 1, + ) + + self.get_metrics() + self.assertEqual( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics[0] + .data.data_points[0] + .bucket_counts[1] + ), + 2, + ) + CeleryInstrumentor().uninstrument() - self.assertIsNone(self.memory_metrics_reader.get_metrics_data()) + self.get_metrics() + self.assertEqual( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics[0] + .data.data_points[0] + .bucket_counts[1] + ), + 2, + ) diff --git a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_metrics_instrumentation.py b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_metrics_instrumentation.py index 087607e606..e544feaaef 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_metrics_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_metrics_instrumentation.py @@ -194,15 +194,147 @@ def test_basic_metric_request_not_empty(self): ) def test_metric_uninstrument(self): with request.urlopen(self.URL): - metrics = self.get_sorted_metrics() - self.assertEqual(len(metrics), 3) - self.assertEqual(metrics[0].data.data_points[0].sum, 1) - self.assertEqual(metrics[1].data.data_points[0].sum, 0) - self.assertEqual(metrics[2].data.data_points[0].sum, 6) + self.assertEqual( + len( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics + ) + ), + 3, + ) + + self.assertEqual( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics[0] + .data.data_points[0] + .bucket_counts[1] + ), + 1, + ) + self.assertEqual( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics[1] + .data.data_points[0] + .bucket_counts[0] + ), + 1, + ) + self.assertEqual( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics[2] + .data.data_points[0] + .bucket_counts[2] + ), + 1, + ) + + with request.urlopen(self.URL): + + self.assertEqual( + len( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics + ) + ), + 3, + ) + + self.assertEqual( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics[0] + .data.data_points[0] + .bucket_counts[1] + ), + 2, + ) + self.assertEqual( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics[1] + .data.data_points[0] + .bucket_counts[0] + ), + 2, + ) + self.assertEqual( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics[2] + .data.data_points[0] + .bucket_counts[2] + ), + 2, + ) + + URLLibInstrumentor().uninstrument() + + with request.urlopen(self.URL): + + self.assertEqual( + len( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics + ) + ), + 3, + ) - URLLibInstrumentor().uninstrument() - with request.urlopen(self.URL): - self.assertIsNone( + self.assertEqual( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics[0] + .data.data_points[0] + .bucket_counts[1] + ), + 2, + ) + self.assertEqual( + ( self.memory_metrics_reader.get_metrics_data() - ) + .resource_metrics[0] + .scope_metrics[0] + .metrics[1] + .data.data_points[0] + .bucket_counts[0] + ), + 2, + ) + self.assertEqual( + ( + self.memory_metrics_reader.get_metrics_data() + .resource_metrics[0] + .scope_metrics[0] + .metrics[2] + .data.data_points[0] + .bucket_counts[2] + ), + 2, + )