Skip to content
Open
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 @@ -137,6 +137,17 @@ public static function register(): void
}
);

hook(
null,
'pg_query_params',
pre: static function (...$args) use ($instrumentation, $tracker) {
return self::basicPreHookWithContextPropagator('pg_query_params', $instrumentation, $tracker, ...$args);
},
post: static function (...$args) use ($instrumentation, $tracker) {
self::queryPostHook($instrumentation, $tracker, ...$args);
}
);

hook(
null,
'pg_select',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,34 @@ public function test_pg_query(): void
$this->assertDatabaseAttributesForAllSpans($offset);
}

public function test_pg_query_params(): void
{
$conn = pg_connect('host=' . $this->pgsqlHost . ' dbname=' . $this->database . ' user=' . $this->user . ' password=' . $this->passwd);
$this->assertTrue($conn instanceof Connection);

$offset = 0;
$this->assertSame('pg_connect', $this->storage->offsetGet($offset)->getName());
$offset++;

$res = pg_query_params($conn, 'SELECT * FROM users WHERE id = $1', [1]);
$this->assertTrue($res instanceof Result);

$this->assertSame('pg_query_params', $this->storage->offsetGet($offset)->getName());
$this->assertAttributes($offset, [
TraceAttributes::DB_QUERY_TEXT => 'SELECT * FROM users WHERE id = $1',
TraceAttributes::DB_OPERATION_NAME => 'SELECT',
]);

while ($row = pg_fetch_assoc($res)) {
}
$offset++;
Comment on lines +145 to +147
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this increment happen within the loop?


pg_close($conn);

$this->assertCount($offset, $this->storage);
$this->assertDatabaseAttributesForAllSpans($offset);
}

public function test_pg_convert(): void
{
$conn = pg_connect('host=' . $this->pgsqlHost . ' dbname=' . $this->database . ' user=' . $this->user . ' password=' . $this->passwd);
Expand Down