diff --git a/.circleci/config.yml b/.circleci/config.yml index 8e94fc22183..285a93b5d53 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -625,6 +625,14 @@ jobs: pattern: "grpc" snapshot: true + mariadb: + <<: *machine_executor + steps: + - run_test: + pattern: 'mariadb$' + snapshot: true + docker_services: "mariadb" + molten: <<: *contrib_job steps: @@ -946,6 +954,7 @@ requires_tests: &requires_tests - jinja2 - kombu - mako + - mariadb - molten - mongoengine - mysqlconnector @@ -1027,6 +1036,7 @@ workflows: - jinja2: *requires_base_venvs - kombu: *requires_base_venvs - mako: *requires_base_venvs + - mariadb: *requires_base_venvs - molten: *requires_base_venvs - mongoengine: *requires_base_venvs - mysqlconnector: *requires_base_venvs diff --git a/ddtrace/contrib/mariadb/__init__.py b/ddtrace/contrib/mariadb/__init__.py new file mode 100644 index 00000000000..f1803653de1 --- /dev/null +++ b/ddtrace/contrib/mariadb/__init__.py @@ -0,0 +1,65 @@ +""" +The MariaDB integration instruments the +`MariaDB library `_ to trace queries. + + +Enabling +~~~~~~~~ + +The MariaDB integration is enabled automatically when using +:ref:`ddtrace-run` or :ref:`patch_all()`. + +Or use :ref:`patch()` to manually enable the integration:: + + from ddtrace import patch + patch(mariadb=True) + + +Global Configuration +~~~~~~~~~~~~~~~~~~~~ + +.. py:data:: ddtrace.config.mariadb["service"] + + The service name reported by default for MariaDB spans. + + This option can also be set with the ``DD_MARIADB_SERVICE`` environment + variable. + + Default: ``"mariadb"`` + + +Instance Configuration +~~~~~~~~~~~~~~~~~~~~~~ + +To configure the mariadb integration on an per-connection basis use the +``Pin`` API:: + + from ddtrace import Pin + from ddtrace import patch + + # Make sure to patch before importing mariadb + patch(mariadb=True) + + import mariadb.connector + + # This will report a span with the default settings + conn = mariadb.connector.connect(user="alice", password="b0b", host="localhost", port=3306, database="test") + + # Use a pin to override the service name for this connection. + Pin.override(conn, service="mariadb-users") + + cursor = conn.cursor() + cursor.execute("SELECT 6*7 AS the_answer;") + +""" +from ...utils.importlib import require_modules + + +required_modules = ["mariadb"] + +with require_modules(required_modules) as missing_modules: + if not missing_modules: + from .patch import patch + from .patch import unpatch + + __all__ = ["patch", "unpatch"] diff --git a/ddtrace/contrib/mariadb/patch.py b/ddtrace/contrib/mariadb/patch.py new file mode 100644 index 00000000000..4b90cc8070a --- /dev/null +++ b/ddtrace/contrib/mariadb/patch.py @@ -0,0 +1,49 @@ +import mariadb + +from ddtrace import Pin +from ddtrace import config +from ddtrace.contrib.dbapi import TracedConnection +from ddtrace.ext import db +from ddtrace.ext import net +from ddtrace.utils.formats import asbool +from ddtrace.utils.formats import get_env +from ddtrace.utils.wrappers import unwrap +from ddtrace.vendor import wrapt + + +config._add( + "mariadb", + dict( + trace_fetch_methods=asbool(get_env("mariadb", "trace_fetch_methods", default=False)), + _default_service="mariadb", + ), +) + + +def patch(): + if getattr(mariadb, "_datadog_patch", False): + return + setattr(mariadb, "_datadog_patch", True) + wrapt.wrap_function_wrapper("mariadb", "connect", _connect) + + +def unpatch(): + if getattr(mariadb, "_datadog_patch", False): + setattr(mariadb, "_datadog_patch", False) + unwrap(mariadb, "connect") + + +def _connect(func, instance, args, kwargs): + conn = func(*args, **kwargs) + tags = { + net.TARGET_HOST: kwargs["host"], + net.TARGET_PORT: kwargs["port"], + db.USER: kwargs["user"], + db.NAME: kwargs["database"], + } + + pin = Pin(app="mariadb", tags=tags) + + wrapped = TracedConnection(conn, pin=pin, cfg=config.mariadb) + pin.onto(wrapped) + return wrapped diff --git a/ddtrace/monkey.py b/ddtrace/monkey.py index e6c9e3d69cd..43d9784741b 100644 --- a/ddtrace/monkey.py +++ b/ddtrace/monkey.py @@ -43,6 +43,7 @@ "mysql": True, "mysqldb": True, "pymysql": True, + "mariadb": True, "psycopg": True, "pylibmc": True, "pymemcache": True, diff --git a/docker-compose.yml b/docker-compose.yml index 9e25431808c..a43bf341726 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,6 +25,15 @@ services: - POSTGRES_DB=postgres ports: - "127.0.0.1:5432:5432" + mariadb: + image: mariadb + environment: + - MYSQL_ROOT_PASSWORD=example + - MYSQL_DATABASE=test + - MYSQL_USER=test + - MYSQL_PASSWORD=test + ports: + - "127.0.0.1:3306:3306" mysql: image: mysql:5.7 environment: diff --git a/docs/index.rst b/docs/index.rst index 88174fca578..89e7913d3a4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -90,6 +90,8 @@ contacting support. +--------------------------------------------------+---------------+----------------+ | :ref:`mako` | >= 0.1.0 | Yes | +--------------------------------------------------+---------------+----------------+ +| :ref:`mariadb` | >= 1.0.0 | Yes | ++--------------------------------------------------+---------------+----------------+ | :ref:`kombu` | >= 4.0 | No | +--------------------------------------------------+---------------+----------------+ | :ref:`molten` | >= 0.7.0 | Yes | diff --git a/docs/integrations.rst b/docs/integrations.rst index ccf5dc60026..bba4686ed84 100644 --- a/docs/integrations.rst +++ b/docs/integrations.rst @@ -193,6 +193,13 @@ Mako .. automodule:: ddtrace.contrib.mako +.. _mariadb: + +MariaDB +^^^^^^^ +.. automodule:: ddtrace.contrib.mariadb + + .. _molten: Molten diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt index d768e0c29a2..c5d2ee17bf4 100644 --- a/docs/spelling_wordlist.txt +++ b/docs/spelling_wordlist.txt @@ -72,6 +72,7 @@ kwarg lifecycle lookups mako +mariadb memcached metadata microservices diff --git a/releasenotes/notes/mariadb-8e7bc94a0d1b8f02.yaml b/releasenotes/notes/mariadb-8e7bc94a0d1b8f02.yaml new file mode 100644 index 00000000000..4b159551642 --- /dev/null +++ b/releasenotes/notes/mariadb-8e7bc94a0d1b8f02.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Add MariaDB integration. diff --git a/riotfile.py b/riotfile.py index 46bb0334dd0..cc28b7f168e 100644 --- a/riotfile.py +++ b/riotfile.py @@ -862,6 +862,22 @@ def select_pys(min_version=MIN_PYTHON_VERSION, max_version=MAX_PYTHON_VERSION): pys=select_pys(min_version="3.6"), command="pytest {cmdargs} tests/contrib/asgi", ), + Venv( + name="mariadb", + command="pytest {cmdargs} tests/contrib/mariadb", + venvs=[ + Venv( + pys=select_pys(min_version="3.6"), + pkgs={ + "mariadb": [ + "~=1.0.0", + "~=1.0", + latest, + ], + }, + ), + ], + ), Venv( name="fastapi", command="pytest {cmdargs} tests/contrib/fastapi", diff --git a/tests/contrib/config.py b/tests/contrib/config.py index e9341c27b2b..0abc5ea41bf 100644 --- a/tests/contrib/config.py +++ b/tests/contrib/config.py @@ -40,6 +40,14 @@ "database": os.getenv("TEST_MYSQL_DATABASE", "test"), } +MARIADB_CONFIG = { + "host": "127.0.0.1", + "port": int(os.getenv("TEST_MARIADB_PORT", 3306)), + "user": os.getenv("TEST_MARIADB_USER", "test"), + "password": os.getenv("TEST_MARIADB_PASSWORD", "test"), + "database": os.getenv("TEST_MARIADB_DATABASE", "test"), +} + REDIS_CONFIG = { "port": int(os.getenv("TEST_REDIS_PORT", 6379)), } diff --git a/tests/contrib/mariadb/__init__.py b/tests/contrib/mariadb/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/contrib/mariadb/test_mariadb.py b/tests/contrib/mariadb/test_mariadb.py new file mode 100644 index 00000000000..4e7f040036a --- /dev/null +++ b/tests/contrib/mariadb/test_mariadb.py @@ -0,0 +1,288 @@ +import os + +import mariadb +import pytest + +from ddtrace import Pin +from ddtrace.constants import ANALYTICS_SAMPLE_RATE_KEY +from ddtrace.contrib.mariadb import patch +from ddtrace.contrib.mariadb import unpatch +from tests.contrib.config import MARIADB_CONFIG +from tests.utils import DummyTracer +from tests.utils import assert_dict_issuperset +from tests.utils import assert_is_measured +from tests.utils import override_config +from tests.utils import snapshot + + +@pytest.fixture +def tracer(): + tracer = DummyTracer() + patch() + try: + yield tracer + finally: + unpatch() + + +def get_connection(tracer): + connection = mariadb.connect(**MARIADB_CONFIG) + Pin.override(connection, tracer=tracer) + + return connection + + +@pytest.fixture +def connection(tracer): + with get_connection(tracer) as connection: + yield connection + + +def test_simple_query(connection, tracer): + cursor = connection.cursor() + cursor.execute("SELECT 1") + rows = cursor.fetchall() + assert len(rows) == 1 + spans = tracer.pop() + assert len(spans) == 1 + span = spans[0] + assert_is_measured(span) + assert span.service == "mariadb" + assert span.name == "mariadb.query" + assert span.span_type == "sql" + assert span.error == 0 + assert span.get_metric("out.port") == 3306 + + assert_dict_issuperset( + span.meta, + { + "out.host": u"127.0.0.1", + "db.name": u"test", + "db.user": u"test", + }, + ) + + +def test_query_executemany(connection, tracer): + tracer.enabled = False + cursor = connection.cursor() + + cursor.execute( + """ + create table if not exists dummy ( + dummy_key VARCHAR(32) PRIMARY KEY, + dummy_value TEXT NOT NULL)""" + ) + tracer.enabled = True + + stmt = "INSERT INTO dummy (dummy_key, dummy_value) VALUES (%s, %s)" + data = [ + ("foo", "this is foo"), + ("bar", "this is bar"), + ] + cursor.executemany(stmt, data) + query = "SELECT dummy_key, dummy_value FROM dummy ORDER BY dummy_key" + cursor.execute(query) + rows = cursor.fetchall() + assert len(rows) == 2 + assert rows[0][0] == "bar" + assert rows[0][1] == "this is bar" + assert rows[1][0] == "foo" + assert rows[1][1] == "this is foo" + + spans = tracer.pop() + assert len(spans) == 2 + span = spans[-1] + assert span.get_tag("mariadb.query") is None + cursor.execute("drop table if exists dummy") + + +def test_rollback(connection, tracer): + connection.rollback() + spans = tracer.pop() + assert len(spans) == 1 + span = spans[0] + assert span.service == "mariadb" + assert span.name == "mariadb.connection.rollback" + + +def test_analytics_default(connection, tracer): + cursor = connection.cursor() + cursor.execute("SELECT 1") + rows = cursor.fetchall() + assert len(rows) == 1 + spans = tracer.pop() + assert len(spans) == 1 + span = spans[0] + assert span.get_metric(ANALYTICS_SAMPLE_RATE_KEY) is None + + +test_user_specified_code = """ +from ddtrace import config +from ddtrace import patch +from ddtrace import tracer +import mariadb +patch(mariadb=True) +from tests.contrib.config import MARIADB_CONFIG +connection = mariadb.connect(**MARIADB_CONFIG) +cursor = connection.cursor() +cursor.execute("SELECT 1") +rows = cursor.fetchall() +assert len(rows) == 1 +tracer.shutdown() +""" + + +@snapshot(async_mode=False) +def test_user_specified_dd_service_snapshot(run_python_code_in_subprocess): + """ + When a user specifies a service for the app + The mariadb integration should not use it. + """ + env = os.environ.copy() + env["DD_SERVICE"] = "mysvc" + out, err, status, pid = run_python_code_in_subprocess( + test_user_specified_code, + env=env, + ) + assert status == 0, err + + +@snapshot(async_mode=False) +def test_user_specified_dd_mariadb_service_snapshot(run_python_code_in_subprocess): + """ + When a user specifies a service for the app + The mariadb integration should not use it. + """ + + env = os.environ.copy() + env["DD_MARIADB_SERVICE"] = "mysvc" + out, err, status, pid = run_python_code_in_subprocess( + test_user_specified_code, + env=env, + ) + assert status == 0, err + + +@snapshot(include_tracer=True) +def test_simple_query_snapshot(tracer): + with get_connection(tracer) as connection: + cursor = connection.cursor() + cursor.execute("SELECT 1") + rows = cursor.fetchall() + assert len(rows) == 1 + + +@snapshot(include_tracer=True, ignores=["meta.error.stack"]) +def test_simple_malformed_query_snapshot(tracer): + with get_connection(tracer) as connection: + cursor = connection.cursor() + with pytest.raises(mariadb.ProgrammingError): + cursor.execute("SELEC 1") + + +@snapshot(include_tracer=True) +def test_simple_query_fetchall_snapshot(tracer): + with override_config("mariadb", dict(trace_fetch_methods=True)): + with get_connection(tracer) as connection: + cursor = connection.cursor() + cursor.execute("SELECT 1") + rows = cursor.fetchall() + assert len(rows) == 1 + + +@snapshot(include_tracer=True) +def test_query_with_several_rows_snapshot(tracer): + with get_connection(tracer) as connection: + cursor = connection.cursor() + query = "SELECT n FROM (SELECT 42 n UNION SELECT 421 UNION SELECT 4210) m" + cursor.execute(query) + rows = cursor.fetchall() + assert len(rows) == 3 + + +@snapshot(include_tracer=True) +def test_query_with_several_rows_fetchall_snapshot(tracer): + with override_config("mariadb", dict(trace_fetch_methods=True)): + with get_connection(tracer) as connection: + cursor = connection.cursor() + query = "SELECT n FROM (SELECT 42 n UNION SELECT 421 UNION SELECT 4210) m" + cursor.execute(query) + rows = cursor.fetchall() + assert len(rows) == 3 + + +@snapshot(include_tracer=True) +def test_query_many_fetchall_snapshot(tracer): + with override_config("mariadb", dict(trace_fetch_methods=True)): + with get_connection(tracer) as connection: + + # tests that the executemany method is correctly wrapped. + tracer.enabled = False + cursor = connection.cursor() + + cursor.execute( + """ + create table if not exists dummy ( + dummy_key VARCHAR(32) PRIMARY KEY, + dummy_value TEXT NOT NULL)""" + ) + tracer.enabled = True + + stmt = "INSERT INTO dummy (dummy_key, dummy_value) VALUES (%s, %s)" + data = [ + ("foo", "this is foo"), + ("bar", "this is bar"), + ] + cursor.executemany(stmt, data) + query = "SELECT dummy_key, dummy_value FROM dummy ORDER BY dummy_key" + cursor.execute(query) + rows = cursor.fetchall() + assert len(rows) == 2 + + +@snapshot(include_tracer=True) +def test_commit_snapshot(tracer): + with get_connection(tracer) as connection: + connection.commit() + + +@snapshot(include_tracer=True) +def test_query_proc_snapshot(tracer): + with get_connection(tracer) as connection: + # create a procedure + tracer.enabled = False + cursor = connection.cursor() + cursor.execute("DROP PROCEDURE IF EXISTS sp_sum") + cursor.execute( + """ + CREATE PROCEDURE sp_sum (IN p1 INTEGER, IN p2 INTEGER, OUT p3 INTEGER) + BEGIN + SET p3 := p1 + p2; + END;""" + ) + + tracer.enabled = True + proc = "sp_sum" + data = (40, 2, None) + cursor.callproc(proc, data) + + +@snapshot(include_tracer=True) +def test_analytics_with_rate_snapshot(tracer): + with override_config("mariadb", dict(analytics_enabled=True, analytics_sample_rate=0.5)): + with get_connection(tracer) as connection: + cursor = connection.cursor() + cursor.execute("SELECT 1") + rows = cursor.fetchall() + assert len(rows) == 1 + + +@snapshot(include_tracer=True) +def test_analytics_without_rate_snapshot(tracer): + with override_config("mariadb", dict(analytics_enabled=True)): + with get_connection(tracer) as connection: + cursor = connection.cursor() + cursor.execute("SELECT 1") + rows = cursor.fetchall() + assert len(rows) == 1 diff --git a/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_analytics_with_rate_snapshot.snap b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_analytics_with_rate_snapshot.snap new file mode 100644 index 00000000000..6749529ce0c --- /dev/null +++ b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_analytics_with_rate_snapshot.snap @@ -0,0 +1,23 @@ +[[{"name" "mariadb.query" + "service" "mariadb" + "resource" "SELECT 1" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 0 + "parent_id" nil + "start" 1626718453548365000 + "duration" 980000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_dd.measured" 1 + "_dd1.sr.eausr" 0.5 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "_dd.tracer_kr" 1.0 + "sql.rows" 0 + "db.rowcount" 0 + "out.port" 3306}}]] diff --git a/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_analytics_without_rate_snapshot.snap b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_analytics_without_rate_snapshot.snap new file mode 100644 index 00000000000..d5a8d6b66b1 --- /dev/null +++ b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_analytics_without_rate_snapshot.snap @@ -0,0 +1,23 @@ +[[{"name" "mariadb.query" + "service" "mariadb" + "resource" "SELECT 1" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 0 + "parent_id" nil + "start" 1626718453593771000 + "duration" 1124000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_dd.measured" 1 + "_dd1.sr.eausr" 1.0 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "_dd.tracer_kr" 1.0 + "sql.rows" 0 + "db.rowcount" 0 + "out.port" 3306}}]] diff --git a/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_commit_snapshot.snap b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_commit_snapshot.snap new file mode 100644 index 00000000000..ec1505c0f52 --- /dev/null +++ b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_commit_snapshot.snap @@ -0,0 +1,18 @@ +[[{"name" "mariadb.connection.commit" + "service" "mariadb" + "resource" "mariadb.connection.commit" + "error" 0 + "span_id" 0 + "trace_id" 0 + "parent_id" nil + "start" 1626718453452681000 + "duration" 1324000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "out.port" 3306 + "_dd.tracer_kr" 1.0}}]] diff --git a/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_query_many_fetchall_snapshot.snap b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_query_many_fetchall_snapshot.snap new file mode 100644 index 00000000000..f7f16dca4c6 --- /dev/null +++ b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_query_many_fetchall_snapshot.snap @@ -0,0 +1,66 @@ +[[{"name" "mariadb.query" + "service" "mariadb" + "resource" "INSERT INTO dummy (dummy_key, dummy_value) VALUES (%s, %s)" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 0 + "parent_id" nil + "start" 1626718453407952000 + "duration" 1705000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test" + "sql.executemany" "true"} + "metrics" {"_dd.agent_psr" 1.0 + "_dd.measured" 1 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "out.port" 3306 + "db.rowcount" 2 + "sql.rows" 2 + "_dd.tracer_kr" 1.0}}] + [{"name" "mariadb.query" + "service" "mariadb" + "resource" "SELECT dummy_key, dummy_value FROM dummy ORDER BY dummy_key" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 1 + "parent_id" nil + "start" 1626718453410309000 + "duration" 1858000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_dd.measured" 1 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "out.port" 3306 + "db.rowcount" 0 + "sql.rows" 0 + "_dd.tracer_kr" 1.0}}] + [{"name" "mariadb.query.fetchall" + "service" "mariadb" + "resource" "SELECT dummy_key, dummy_value FROM dummy ORDER BY dummy_key" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 2 + "parent_id" nil + "start" 1626718453412328000 + "duration" 331000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "out.port" 3306 + "db.rowcount" 2 + "sql.rows" 2 + "_dd.tracer_kr" 1.0}}]] diff --git a/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_query_proc_snapshot.snap b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_query_proc_snapshot.snap new file mode 100644 index 00000000000..2700354fb46 --- /dev/null +++ b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_query_proc_snapshot.snap @@ -0,0 +1,22 @@ +[[{"name" "mariadb.query" + "service" "mariadb" + "resource" "sp_sum" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 0 + "parent_id" nil + "start" 1626718453505520000 + "duration" 1564000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_dd.measured" 1 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "out.port" 3306 + "db.rowcount" 0 + "sql.rows" 0 + "_dd.tracer_kr" 1.0}}]] diff --git a/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_query_with_several_rows_fetchall_snapshot.snap b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_query_with_several_rows_fetchall_snapshot.snap new file mode 100644 index 00000000000..81fc8d0b3c5 --- /dev/null +++ b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_query_with_several_rows_fetchall_snapshot.snap @@ -0,0 +1,43 @@ +[[{"name" "mariadb.query" + "service" "mariadb" + "resource" "SELECT n FROM (SELECT 42 n UNION SELECT 421 UNION SELECT 4210) m" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 0 + "parent_id" nil + "start" 1626718453355264000 + "duration" 1786000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_dd.measured" 1 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "out.port" 3306 + "db.rowcount" 0 + "sql.rows" 0 + "_dd.tracer_kr" 1.0}}] + [{"name" "mariadb.query.fetchall" + "service" "mariadb" + "resource" "SELECT n FROM (SELECT 42 n UNION SELECT 421 UNION SELECT 4210) m" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 1 + "parent_id" nil + "start" 1626718453359605000 + "duration" 113000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "out.port" 3306 + "db.rowcount" 3 + "sql.rows" 3 + "_dd.tracer_kr" 1.0}}]] diff --git a/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_query_with_several_rows_snapshot.snap b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_query_with_several_rows_snapshot.snap new file mode 100644 index 00000000000..d61cef80afa --- /dev/null +++ b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_query_with_several_rows_snapshot.snap @@ -0,0 +1,22 @@ +[[{"name" "mariadb.query" + "service" "mariadb" + "resource" "SELECT n FROM (SELECT 42 n UNION SELECT 421 UNION SELECT 4210) m" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 0 + "parent_id" nil + "start" 1626718453319829000 + "duration" 1217000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_dd.measured" 1 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "out.port" 3306 + "db.rowcount" 0 + "sql.rows" 0 + "_dd.tracer_kr" 1.0}}]] diff --git a/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_simple_malformed_query_snapshot.snap b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_simple_malformed_query_snapshot.snap new file mode 100644 index 00000000000..13895395297 --- /dev/null +++ b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_simple_malformed_query_snapshot.snap @@ -0,0 +1,24 @@ +[[{"name" "mariadb.query" + "service" "mariadb" + "resource" "SELEC 1" + "type" "sql" + "error" 1 + "span_id" 0 + "trace_id" 0 + "parent_id" nil + "start" 1626718453234358000 + "duration" 3750000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test" + "error.msg" "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELEC 1' at line 1" + "error.type" "mariadb.ProgrammingError" + "error.stack" "Traceback (most recent call last):\n File \"/root/project/ddtrace/contrib/dbapi/__init__.py\", line 73, in _trace_method\n return method(*args, **kwargs)\nmariadb.ProgrammingError: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELEC 1' at line 1\n"} + "metrics" {"_dd.agent_psr" 1.0 + "_dd.measured" 1 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "out.port" 3306 + "db.rowcount" -1 + "_dd.tracer_kr" 1.0}}]] diff --git a/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_simple_query_fetchall_snapshot.snap b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_simple_query_fetchall_snapshot.snap new file mode 100644 index 00000000000..0be28f3f7e8 --- /dev/null +++ b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_simple_query_fetchall_snapshot.snap @@ -0,0 +1,43 @@ +[[{"name" "mariadb.query" + "service" "mariadb" + "resource" "SELECT 1" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 0 + "parent_id" nil + "start" 1626718453278969000 + "duration" 1180000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_dd.measured" 1 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "out.port" 3306 + "db.rowcount" 0 + "sql.rows" 0 + "_dd.tracer_kr" 1.0}}] + [{"name" "mariadb.query.fetchall" + "service" "mariadb" + "resource" "SELECT 1" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 1 + "parent_id" nil + "start" 1626718453281057000 + "duration" 156000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "out.port" 3306 + "db.rowcount" 1 + "sql.rows" 1 + "_dd.tracer_kr" 1.0}}]] diff --git a/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_simple_query_snapshot.snap b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_simple_query_snapshot.snap new file mode 100644 index 00000000000..475c473f12c --- /dev/null +++ b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_simple_query_snapshot.snap @@ -0,0 +1,22 @@ +[[{"name" "mariadb.query" + "service" "mariadb" + "resource" "SELECT 1" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 0 + "parent_id" nil + "start" 1626718453185258000 + "duration" 824000 + "meta" {"runtime-id" "0cbfb96da3ee4e86be3cf3b8a4004f86" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_dd.measured" 1 + "_sampling_priority_v1" 1 + "system.pid" 1502 + "out.port" 3306 + "db.rowcount" 0 + "sql.rows" 0 + "_dd.tracer_kr" 1.0}}]] diff --git a/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_user_specified_dd_mariadb_service_snapshot.snap b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_user_specified_dd_mariadb_service_snapshot.snap new file mode 100644 index 00000000000..65417795c3d --- /dev/null +++ b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_user_specified_dd_mariadb_service_snapshot.snap @@ -0,0 +1,22 @@ +[[{"name" "mariadb.query" + "service" "mysvc" + "resource" "SELECT 1" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 0 + "parent_id" nil + "start" 1626718453097564000 + "duration" 1121000 + "meta" {"runtime-id" "659d2043e2704c97ac93280150cb1ce6" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_dd.measured" 1 + "_sampling_priority_v1" 1 + "system.pid" 1511 + "out.port" 3306 + "db.rowcount" 0 + "sql.rows" 0 + "_dd.tracer_kr" 1.0}}]] diff --git a/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_user_specified_dd_service_snapshot.snap b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_user_specified_dd_service_snapshot.snap new file mode 100644 index 00000000000..6f457179fbe --- /dev/null +++ b/tests/snapshots/tests.contrib.mariadb.test_mariadb.test_user_specified_dd_service_snapshot.snap @@ -0,0 +1,22 @@ +[[{"name" "mariadb.query" + "service" "mariadb" + "resource" "SELECT 1" + "type" "sql" + "error" 0 + "span_id" 0 + "trace_id" 0 + "parent_id" nil + "start" 1626718452059170000 + "duration" 1491000 + "meta" {"runtime-id" "cf25a26f85404c2fa6542978216544cd" + "out.host" "127.0.0.1" + "db.user" "test" + "db.name" "test"} + "metrics" {"_dd.agent_psr" 1.0 + "_dd.measured" 1 + "_sampling_priority_v1" 1 + "system.pid" 1508 + "out.port" 3306 + "db.rowcount" 0 + "sql.rows" 0 + "_dd.tracer_kr" 1.0}}]]