Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add a DEBUG.md #7461

Open
bshaffer opened this issue Jun 21, 2024 · 0 comments
Open

docs: Add a DEBUG.md #7461

bshaffer opened this issue Jun 21, 2024 · 0 comments
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@bshaffer
Copy link
Contributor

See https://github.com/googleapis/google-cloud-go/blob/main/debug.md

Similary, PHP could have one. Here's an example of how to add debugging to bigquery

use Google\Cloud\BigQuery\BigQueryClient;
use GuzzleHttp\HandlerStack;
use Google\Auth\HttpHandler\HttpHandlerFactory;
use GuzzleHttp\Middleware;
use GuzzleHttp\MessageFormatter;
use Monolog\Logger;
use Monolog\Level;
use Monolog\Handler\StreamHandler;

$logger = new Logger('Logger');
$logger->pushHandler(new StreamHandler('php://stdout', Level::Debug)); // <<< uses a stream

$stack = HandlerStack::create();
$stack->push(
    Middleware::log(
        $logger,
        new MessageFormatter('{req_body} - {res_body}')
    )
);
$client = new \GuzzleHttp\Client([
    'handler' => $stack,
]);
$httpHandler = HttpHandlerFactory::build($client);

$bigQuery = new BigQueryClient([
    'httpHandler' => $httpHandler,
    'projectId' => $projectId,
]);
$datasets = $bigQuery->datasets();
foreach ($datasets as $dataset) {
    print($dataset->id() . PHP_EOL);
}

This would be similar for any GAPIC client as well, although you'd need to supply httpHandler to the transport config, and it would only work for REST requests

use Google\Cloud\Dlp\V2\Client\DlpServiceClient;
use Google\Cloud\Dlp\V2\ListInfoTypesRequest;
use GuzzleHttp\HandlerStack;
use Google\Auth\HttpHandler\HttpHandlerFactory;
use GuzzleHttp\Middleware;
use GuzzleHttp\MessageFormatter;
use Monolog\Logger;
use Monolog\Level;
use Monolog\Handler\StreamHandler;

$logger = new Logger('Logger');
$logger->pushHandler(new StreamHandler('php://stdout', Level::Debug)); // <<< uses a stream

$stack = HandlerStack::create();
$stack->push(
    Middleware::log(
        $logger,
        new MessageFormatter('{req_body} - {res_body}')
    )
);
$client = new \GuzzleHttp\Client([
    'handler' => $stack,
]);
$httpHandler = [HttpHandlerFactory::build($client), 'async'];

// Instantiate a client.
$dlp = new DlpServiceClient([
    'transportConfig' => ['rest' => ['httpHandler' => $httpHandler]],
]);

// Run request
$listInfoTypesRequest = (new ListInfoTypesRequest())
    ->setLanguageCode($languageCode)
    ->setFilter($filter);
$response = $dlp->listInfoTypes($listInfoTypesRequest);

// Print the results
print('Info Types:' . PHP_EOL);
foreach ($response->getInfoTypes() as $infoType) {
    printf(
        '  %s (%s)' . PHP_EOL,
        $infoType->getDisplayName(),
        $infoType->getName()
    );
}
@bshaffer bshaffer added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

2 participants