Skip to content

Commit 0ed567f

Browse files
authored
adds environment variable population to error reporting example (GoogleCloudPlatform#312)
1 parent 12eb153 commit 0ed567f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

error_reporting/quickstart/quickstart.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
// Imports the Google Cloud client library
88
use Google\Cloud\Logging\LoggingClient;
99

10-
// Your Google Cloud Platform project ID
11-
$projectId = 'YOUR_PROJECT_ID';
10+
// These variables are set by the App Engine environment. To test locally,
11+
// ensure these are set or manually change their values.
12+
$projectId = getenv('GCLOUD_PROJECT') ?: 'YOUR_PROJECT_ID';
13+
$service = getenv('GAE_SERVICE') ?: 'error_reporting_quickstart';
14+
$version = getenv('GAE_VERSION') ?: '1.0-dev';
1215

1316
// Instantiates a client
1417
$logging = new LoggingClient([
@@ -21,13 +24,13 @@
2124
// Selects the log to write to
2225
$logger = $logging->logger($logName);
2326

24-
$handlerFunction = function (Exception $e) use ($logger) {
27+
$handlerFunction = function (Exception $e) use ($logger, $service, $version) {
2528
// Creates the log entry with the exception trace
2629
$entry = $logger->entry([
2730
'message' => sprintf('PHP Warning: %s', $e),
2831
'serviceContext' => [
29-
'service' => 'error_reporting_quickstart',
30-
'version' => '1.0-dev',
32+
'service' => $service,
33+
'version' => $version,
3134
]
3235
]);
3336
// Writes the log entry

0 commit comments

Comments
 (0)