Skip to content
Merged
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
9 changes: 8 additions & 1 deletion src/Trace/Integrations/PDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@
*/
class PDO implements IntegrationInterface
{
static $db_host = "";
/**
* Static method to add instrumentation to the PDO requests
*/
public static function load()
public static function load($db_host="")
{
if (!extension_loaded('opencensus')) {
trigger_error('opencensus extension required to load PDO integrations.', E_USER_WARNING);
return;
}

PDO::$db_host = $db_host;
// public int PDO::exec(string $query)
opencensus_trace_method('PDO', 'exec', [static::class, 'handleQuery']);

Expand Down Expand Up @@ -92,6 +94,7 @@ public static function handleConnect($pdo, $dsn)
{
// https://www.php.net/manual/en/ref.pdo-mysql.connection.php
// example $dsn: mysql:host=localhost;dbname=testdb
// example $dsn: mysql:unix_socket=/tmp/mysql.sock;dbname=testdb

$db_system = '';
$connection_params = [];
Expand All @@ -116,9 +119,13 @@ public static function handleConnect($pdo, $dsn)
if (array_key_exists('port', $connection_params)){
$attributes['net.peer.port'] = $connection_params['port'];
}

if (array_key_exists('host', $connection_params)){
$attributes['net.peer.name'] = $connection_params['host'];
}
else if (array_key_exists('unix_socket', $connection_params)){
$attributes['net.peer.name'] = PDO::$db_host;
}

$attributes += [
'dsn' => $dsn,
Expand Down
1 change: 0 additions & 1 deletion src/Trace/Integrations/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public static function load()
'db.type' => 'redis',
'db.system' => 'redis',
'db.connection_string' => $connection_str,
'redis.connection' => $connection_str,
'span.kind' => Span::KIND_CLIENT
],
'kind' => Span::KIND_CLIENT,
Expand Down