Skip to content

Commit

Permalink
Fix merge from main.
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhlogin committed Jul 8, 2024
1 parent 1e318bb commit 4df6563
Showing 1 changed file with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,6 @@ 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_instrumentation(self):
self.assertFalse(gevent.monkey.is_module_patched("os"), "gevent os module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("thread"), "gevent thread module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("time"), "gevent time module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("sys"), "gevent sys module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("socket"), "gevent socket module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("select"), "gevent select module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("ssl"), "gevent ssl module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("subprocess"), "gevent subprocess module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("builtins"), "gevent builtins module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("signal"), "gevent signal module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("queue"), "gevent queue module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("contextvars"), "gevent contextvars module has been patched")

# Bedrock
self.assertFalse("bedrock" in _KNOWN_EXTENSIONS, "Upstream has added a Bedrock extension")

Expand All @@ -155,6 +141,20 @@ def _test_unpatched_gevent_instrumentation(self):
# BedrockRuntime
self.assertFalse("bedrock-runtime" in _KNOWN_EXTENSIONS, "Upstream has added a bedrock-runtime extension")

def _test_unpatched_gevent_instrumentation(self):
self.assertFalse(gevent.monkey.is_module_patched("os"), "gevent os module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("thread"), "gevent thread module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("time"), "gevent time module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("sys"), "gevent sys module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("socket"), "gevent socket module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("select"), "gevent select module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("ssl"), "gevent ssl module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("subprocess"), "gevent subprocess module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("builtins"), "gevent builtins module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("signal"), "gevent signal module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("queue"), "gevent queue module has been patched")
self.assertFalse(gevent.monkey.is_module_patched("contextvars"), "gevent contextvars module has been patched")

# pylint: disable=too-many-statements
def _test_patched_botocore_instrumentation(self):
# Kinesis
Expand All @@ -178,6 +178,28 @@ 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)

# Bedrock
self._test_patched_bedrock_instrumentation()

# Bedrock Agent Operation
self._test_patched_bedrock_agent_instrumentation()

# Bedrock Agent Runtime
self.assertTrue("bedrock-agent-runtime" in _KNOWN_EXTENSIONS)
bedrock_agent_runtime_attributes: Dict[str, str] = _do_extract_attributes_bedrock("bedrock-agent-runtime")
self.assertEqual(len(bedrock_agent_runtime_attributes), 2)
self.assertEqual(bedrock_agent_runtime_attributes["aws.bedrock.agent.id"], _BEDROCK_AGENT_ID)
self.assertEqual(bedrock_agent_runtime_attributes["aws.bedrock.knowledge_base.id"], _BEDROCK_KNOWLEDGEBASE_ID)
bedrock_agent_runtime_sucess_attributes: Dict[str, str] = _do_on_success_bedrock("bedrock-agent-runtime")
self.assertEqual(len(bedrock_agent_runtime_sucess_attributes), 0)

# BedrockRuntime
self.assertTrue("bedrock-runtime" in _KNOWN_EXTENSIONS)
bedrock_runtime_attributes: Dict[str, str] = _do_extract_bedrock_runtime_attributes()
self.assertEqual(len(bedrock_runtime_attributes), 2)
self.assertEqual(bedrock_runtime_attributes["gen_ai.system"], _GEN_AI_SYSTEM)
self.assertEqual(bedrock_runtime_attributes["gen_ai.request.model"], _GEN_AI_REQUEST_MODEL)

def _test_patched_gevent_os_ssl_instrumentation(self):
# Only ssl and os module should have been patched since the environment variable was set to 'os, ssl'
self.assertTrue(gevent.monkey.is_module_patched("ssl"), "gevent ssl module has not been patched")
Expand Down Expand Up @@ -210,28 +232,6 @@ def _test_patched_gevent_instrumentation(self):
self.assertFalse(gevent.monkey.is_module_patched("builtins"), "gevent builtins module not been patched")
self.assertFalse(gevent.monkey.is_module_patched("contextvars"), "gevent contextvars module has been patched")

# Bedrock
self._test_patched_bedrock_instrumentation()

# Bedrock Agent Operation
self._test_patched_bedrock_agent_instrumentation()

# Bedrock Agent Runtime
self.assertTrue("bedrock-agent-runtime" in _KNOWN_EXTENSIONS)
bedrock_agent_runtime_attributes: Dict[str, str] = _do_extract_attributes_bedrock("bedrock-agent-runtime")
self.assertEqual(len(bedrock_agent_runtime_attributes), 2)
self.assertEqual(bedrock_agent_runtime_attributes["aws.bedrock.agent.id"], _BEDROCK_AGENT_ID)
self.assertEqual(bedrock_agent_runtime_attributes["aws.bedrock.knowledge_base.id"], _BEDROCK_KNOWLEDGEBASE_ID)
bedrock_agent_runtime_sucess_attributes: Dict[str, str] = _do_on_success_bedrock("bedrock-agent-runtime")
self.assertEqual(len(bedrock_agent_runtime_sucess_attributes), 0)

# BedrockRuntime
self.assertTrue("bedrock-runtime" in _KNOWN_EXTENSIONS)
bedrock_runtime_attributes: Dict[str, str] = _do_extract_bedrock_runtime_attributes()
self.assertEqual(len(bedrock_runtime_attributes), 2)
self.assertEqual(bedrock_runtime_attributes["gen_ai.system"], _GEN_AI_SYSTEM)
self.assertEqual(bedrock_runtime_attributes["gen_ai.request.model"], _GEN_AI_REQUEST_MODEL)

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

0 comments on commit 4df6563

Please sign in to comment.