Skip to content

Commit

Permalink
Merge branch 'main' into fix/asgi_target
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv authored Dec 5, 2022
2 parents 75d19b1 + 155fc46 commit f1fadae
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,12 @@ def _instrumented_lambda_handler_call(

span_kind = None
try:
if lambda_event["Records"][0]["eventSource"] in set(
["aws:sqs", "aws:s3", "aws:sns", "aws:dynamodb"]
):
if lambda_event["Records"][0]["eventSource"] in {
"aws:sqs",
"aws:s3",
"aws:sns",
"aws:dynamodb",
}:
# See more:
# https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
# https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ def _patched_query_request(self, original_func, instance, args, kwargs):
)

def _patched_auth_request(self, original_func, instance, args, kwargs):
operation_name = None

frame = currentframe().f_back
operation_name = None
while frame:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def instrumentation_dependencies(self) -> Collection[str]:

def _instrument(self, **kwargs):
"""
Instruments elasticsearch module
Instruments Elasticsearch module
"""
tracer_provider = kwargs.get("tracer_provider")
tracer = get_tracer(__name__, __version__, tracer_provider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ def response_hook(span: Span, status: str, response_headers: List):


def get_default_span_name():
span_name = ""
try:
span_name = flask.request.url_rule.rule
except AttributeError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import mysql.connector

import opentelemetry.instrumentation.mysql
from opentelemetry import trace as trace_api
from opentelemetry.instrumentation.mysql import MySQLInstrumentor
from opentelemetry.sdk import resources
from opentelemetry.test.test_base import TestBase
Expand All @@ -31,6 +32,15 @@ def cursor(self):
return MockConnection()


def connect_and_execute_query():
cnx = mysql.connector.connect(database="test")
cursor = cnx.cursor()
query = "SELECT * FROM test"
cursor.execute(query)

return cnx, query


class TestMysqlIntegration(TestBase):
def tearDown(self):
super().tearDown()
Expand All @@ -42,10 +52,7 @@ def tearDown(self):
def test_instrumentor(self):
MySQLInstrumentor().instrument()

cnx = mysql.connector.connect(database="test")
cursor = cnx.cursor()
query = "SELECT * FROM test"
cursor.execute(query)
connect_and_execute_query()

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)
Expand All @@ -59,10 +66,7 @@ def test_instrumentor(self):
# check that no spans are generated after uninstrumen
MySQLInstrumentor().uninstrument()

cnx = mysql.connector.connect(database="test")
cursor = cnx.cursor()
query = "SELECT * FROM test"
cursor.execute(query)
connect_and_execute_query()

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)
Expand All @@ -74,10 +78,7 @@ def test_custom_tracer_provider(self):
tracer_provider, exporter = result

MySQLInstrumentor().instrument(tracer_provider=tracer_provider)
cnx = mysql.connector.connect(database="test")
cursor = cnx.cursor()
query = "SELECT * FROM test"
cursor.execute(query)
connect_and_execute_query()

span_list = exporter.get_finished_spans()
self.assertEqual(len(span_list), 1)
Expand All @@ -88,10 +89,7 @@ def test_custom_tracer_provider(self):
@patch("mysql.connector.connect", new=mock_connect)
# pylint: disable=unused-argument
def test_instrument_connection(self):
cnx = mysql.connector.connect(database="test")
query = "SELECT * FROM test"
cursor = cnx.cursor()
cursor.execute(query)
cnx, query = connect_and_execute_query()

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)
Expand All @@ -103,14 +101,20 @@ def test_instrument_connection(self):
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)

@patch("mysql.connector.connect", new=mock_connect)
def test_instrument_connection_no_op_tracer_provider(self):
tracer_provider = trace_api.NoOpTracerProvider()
MySQLInstrumentor().instrument(tracer_provider=tracer_provider)
connect_and_execute_query()

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)

@patch("mysql.connector.connect", new=mock_connect)
# pylint: disable=unused-argument
def test_uninstrument_connection(self):
MySQLInstrumentor().instrument()
cnx = mysql.connector.connect(database="test")
query = "SELECT * FROM test"
cursor = cnx.cursor()
cursor.execute(query)
cnx, query = connect_and_execute_query()

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _pop_span(self, event):

def _get_span_dict_key(event):
if event.connection_id is not None:
return (event.request_id, event.connection_id)
return event.request_id, event.connection_id
return event.request_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def _instrument(
):
def _traced_execute_command(func, instance, args, kwargs):
query = _format_command_args(args)
name = ""
if len(args) > 0 and args[0]:
name = args[0]
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

import psutil

# FIXME Remove this pyling disabling line when Github issue is cleared
# FIXME Remove this pylint disabling line when Github issue is cleared
# pylint: disable=no-name-in-module
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.system_metrics.package import _instruments
Expand Down

0 comments on commit f1fadae

Please sign in to comment.