Skip to content

Commit f9910cd

Browse files
committed
More tests
1 parent 678872a commit f9910cd

File tree

3 files changed

+361
-25
lines changed

3 files changed

+361
-25
lines changed

docker/mysql/init.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
CREATE DATABASE IF NOT EXISTS otel_db;
2-
CREATE USER IF NOT EXISTS 'otel_user'@'%' IDENTIFIED BY 'otel_passwd';
3-
GRANT ALL PRIVILEGES ON otel_db.* TO 'otel_user'@'%';
1+
-- CREATE DATABASE IF NOT EXISTS otel_db;
2+
-- DROP USER IF EXISTS 'otel_user'@'%';
3+
-- CREATE USER 'otel_user'@'%' IDENTIFIED BY 'otel_passwd';
4+
5+
GRANT ALL PRIVILEGES ON *.* TO 'otel_user'@'%';
46
FLUSH PRIVILEGES;
57

8+
69
USE otel_db;
710

811
CREATE TABLE users (

src/Instrumentation/MySqli/src/MySqliInstrumentation.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,12 @@ private static function constructPreHook(string $spanName, int $paramsOffset, Ca
353353

354354
private static function constructPostHook(int $paramsOffset, CachedInstrumentation $instrumentation, MySqliTracker $tracker, $obj, array $params, mixed $retVal, ?\Throwable $exception)
355355
{
356-
357356
$mysqliObject = null;
358357

359358
if ($obj && $retVal !== false) { // even if constructor fails, we will get and temporary object which will be assigned (or not) alter in user code
360359
$mysqliObject = $obj;
361360
} elseif ($retVal instanceof mysqli) { // procedural mode
362-
$mySqliObject = $retVal;
361+
$mysqliObject = $retVal;
363362
} elseif ($paramsOffset == self::MYSQLI_REAL_CONNECT_ARG_OFFSET && $retVal !== false && $params[0] instanceof mysqli) { // real_connect procedural mode
364363
$mysqliObject = $params[0];
365364
}
@@ -369,7 +368,6 @@ private static function constructPostHook(int $paramsOffset, CachedInstrumentati
369368
}
370369

371370
self::endSpan([], $exception, ($retVal === false && !$exception) ? mysqli_connect_error() : null);
372-
373371
}
374372

375373
/** @param non-empty-string $spanName */
@@ -380,11 +378,11 @@ private static function queryPreHook(string $spanName, CachedInstrumentation $in
380378

381379
private static function queryPostHook(CachedInstrumentation $instrumentation, MySqliTracker $tracker, $obj, array $params, mixed $retVal, ?\Throwable $exception)
382380
{
383-
384381
$mysqli = $obj ? $obj : $params[0];
385382
$query = $obj ? $params[0] : $params[1];
386383

387384
$attributes = $tracker->getMySqliAttributes($mysqli);
385+
388386
$attributes[TraceAttributes::DB_STATEMENT] = mb_convert_encoding($query, 'UTF-8');
389387
$attributes[TraceAttributes::DB_OPERATION_NAME] = self::extractQueryCommand($query);
390388

0 commit comments

Comments
 (0)