Skip to content

Commit

Permalink
Add Testing for Instrumentation Patch
Browse files Browse the repository at this point in the history
  • Loading branch information
harrryr committed Jun 25, 2024
1 parent e6ca6ac commit cbd5f28
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
import sys
from typing import Dict
from unittest import TestCase
from unittest.mock import MagicMock, patch
Expand Down Expand Up @@ -57,12 +58,14 @@ def _run_patch_behaviour_tests(self):

# Validate unpatched upstream behaviour - important to detect upstream changes that may break instrumentation
self._test_unpatched_botocore_instrumentation()
self._test_unpatched_gevent_ssl_instrumentation()

# Apply patches
apply_instrumentation_patches()

# Validate patched upstream behaviour - important to detect downstream changes that may break instrumentation
self._test_patched_botocore_instrumentation()
self._test_patched_gevent_ssl_instrumentation()

# Test teardown
self._reset_mocks()
Expand Down Expand Up @@ -93,6 +96,10 @@ def _test_unpatched_botocore_instrumentation(self):
self.assertFalse("aws.sqs.queue_url" in attributes)
self.assertFalse("aws.sqs.queue_name" in attributes)

def _test_unpatched_gevent_ssl_instrumentation(self):
# Ssl
self.assertFalse("gevent.ssl" in sys.modules, "Upstream has added the gevent ssl patch")

def _test_patched_botocore_instrumentation(self):
# Kinesis
self.assertTrue("kinesis" in _KNOWN_EXTENSIONS)
Expand All @@ -115,6 +122,10 @@ def _test_patched_botocore_instrumentation(self):
self.assertTrue("aws.sqs.queue_name" in sqs_attributes)
self.assertEqual(sqs_attributes["aws.sqs.queue_name"], _QUEUE_NAME)

def _test_patched_gevent_ssl_instrumentation(self):
# Ssl
self.assertTrue("gevent.ssl" in sys.modules)

def _test_botocore_installed_flag(self):
with patch(
"amazon.opentelemetry.distro.patches._botocore_patches._apply_botocore_instrumentation_patches"
Expand Down

0 comments on commit cbd5f28

Please sign in to comment.