Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
import time

Expand All @@ -21,13 +22,16 @@
from opentelemetry.ext.mysql import trace_integration
from opentelemetry.test.test_base import TestBase

logger = logging.getLogger(__name__)

MYSQL_USER = os.getenv("MYSQL_USER ", "testuser")
MYSQL_PASSWORD = os.getenv("MYSQL_PASSWORD ", "testpassword")
MYSQL_HOST = os.getenv("MYSQL_HOST ", "localhost")
MYSQL_PORT = int(os.getenv("MYSQL_PORT ", "3306"))
MYSQL_DB_NAME = os.getenv("MYSQL_DB_NAME ", "opentelemetry-tests")


# pylint: disable=broad-except
class TestFunctionalMysql(TestBase):
@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -75,16 +79,24 @@ def test_execute(self):
"""Should create a child span for execute
"""
with self._tracer.start_as_current_span("rootSpan"):
self._cursor.execute("CREATE TABLE IF NOT EXISTS test (id INT)")
try:
self._cursor.execute(
"CREATE TABLE IF NOT EXISTS test (id INT)"
)
except Exception as ex:
logger.warning("Failed to execute with mysql. %s", str(ex))
self.validate_spans()

def test_executemany(self):
"""Should create a child span for executemany
"""
with self._tracer.start_as_current_span("rootSpan"):
data = ["1", "2", "3"]
stmt = "INSERT INTO test (id) VALUES (%s)"
self._cursor.executemany(stmt, data)
try:
data = ["1", "2", "3"]
stmt = "INSERT INTO test (id) VALUES (%s)"
self._cursor.executemany(stmt, data)
except Exception as ex:
logger.warning("Failed to executemany with mysql. %s", str(ex))
self.validate_spans()

def test_callproc(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
import time

Expand All @@ -21,13 +22,16 @@
from opentelemetry.ext.psycopg2 import trace_integration
from opentelemetry.test.test_base import TestBase

logger = logging.getLogger(__name__)

POSTGRES_HOST = os.getenv("POSTGRESQL_HOST ", "localhost")
POSTGRES_PORT = int(os.getenv("POSTGRESQL_PORT ", "5432"))
POSTGRES_DB_NAME = os.getenv("POSTGRESQL_DB_NAME ", "opentelemetry-tests")
POSTGRES_PASSWORD = os.getenv("POSTGRESQL_HOST ", "testpassword")
POSTGRES_USER = os.getenv("POSTGRESQL_HOST ", "testuser")


# pylint: disable=broad-except
class TestFunctionalPsycopg(TestBase):
@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -79,19 +83,28 @@ def validate_spans(self):
def test_execute(self):
"""Should create a child span for execute method
"""

with self._tracer.start_as_current_span("rootSpan"):
self._cursor.execute(
"CREATE TABLE IF NOT EXISTS test (id integer)"
)
try:
self._cursor.execute(
"CREATE TABLE IF NOT EXISTS test (id integer)"
)
except Exception as ex:
logger.warning("Failed to execute with pyscopg2. %s", str(ex))
self.validate_spans()

def test_executemany(self):
"""Should create a child span for executemany
"""
with self._tracer.start_as_current_span("rootSpan"):
data = ("1", "2", "3")
stmt = "INSERT INTO test (id) VALUES (%s)"
self._cursor.executemany(stmt, data)
try:
data = ("1", "2", "3")
stmt = "INSERT INTO test (id) VALUES (%s)"
self._cursor.executemany(stmt, data)
except Exception as ex:
logger.warning(
"Failed to executemany with pyscopg2. %s", str(ex)
)
self.validate_spans()

def test_callproc(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os

from pymongo import MongoClient
Expand All @@ -20,12 +21,15 @@
from opentelemetry.ext.pymongo import trace_integration
from opentelemetry.test.test_base import TestBase

logger = logging.getLogger(__name__)

MONGODB_HOST = os.getenv("MONGODB_HOST ", "localhost")
MONGODB_PORT = int(os.getenv("MONGODB_PORT ", "27017"))
MONGODB_DB_NAME = os.getenv("MONGODB_DB_NAME ", "opentelemetry-tests")
MONGODB_COLLECTION_NAME = "test"


# pylint: disable=broad-except
class TestFunctionalPymongo(TestBase):
@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -67,30 +71,42 @@ def test_insert(self):
"""Should create a child span for insert
"""
with self._tracer.start_as_current_span("rootSpan"):
self._collection.insert_one(
{"name": "testName", "value": "testValue"}
)
try:
self._collection.insert_one(
{"name": "testName", "value": "testValue"}
)
except Exception as ex:
logger.warning("Failed to insert with pymongo. %s", str(ex))
self.validate_spans()

def test_update(self):
"""Should create a child span for update
"""
with self._tracer.start_as_current_span("rootSpan"):
self._collection.update_one(
{"name": "testName"}, {"$set": {"value": "someOtherValue"}}
)
try:
self._collection.update_one(
{"name": "testName"}, {"$set": {"value": "someOtherValue"}}
)
except Exception as ex:
logger.warning("Failed to update with pymongo. %s", str(ex))
self.validate_spans()

def test_find(self):
"""Should create a child span for find
"""
with self._tracer.start_as_current_span("rootSpan"):
self._collection.find_one()
try:
self._collection.find_one()
except Exception as ex:
logger.warning("Failed to find with pymongo. %s", str(ex))
self.validate_spans()

def test_delete(self):
"""Should create a child span for delete
"""
with self._tracer.start_as_current_span("rootSpan"):
self._collection.delete_one({"name": "testName"})
try:
self._collection.delete_one({"name": "testName"})
except Exception as ex:
logger.warning("Failed to delete with pymongo. %s", str(ex))
self.validate_spans()