Credits:
Created
January 28, 2017 20:45
-
-
Save chooh/6d18be254d209a27889513caa5997a8f to your computer and use it in GitHub Desktop.
Setting up Error Reporting for a PHP app running on GKE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"require": { | |
"php": ">=5.6.4", | |
"fluent/logger":"^1.0" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
use Fluent\Logger\FluentLogger; | |
$GLOBALS['logger'] = new FluentLogger('localhost', '24224'); | |
function fluentd_exception_handler(Throwable $e) | |
{ | |
global $logger; | |
// Creates the log entry with the exception trace | |
// PHP: Must start with PHP (Notice|Parse error|Fatal error|Warning) and contain the result of (string)$exception. | |
$msg = array( | |
'serviceContext' => array('service' => 'myapp'), | |
'message' => sprintf('PHP Warning: %s', $e), | |
); | |
// Writes the log entry | |
$logger->post('errors', $msg); | |
print("Exception logged to Stack Driver Error Reporting" . PHP_EOL); | |
}; | |
// Sets PHP's default exception handler | |
set_exception_handler('fluentd_exception_handler'); | |
throw new Exception('This will be logged to Stack Driver Error Reporting'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: fluentd-config | |
data: | |
fluentd.conf: | | |
<source> | |
@type forward | |
port 24224 | |
</source> | |
<match **> | |
type google_cloud | |
</match> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: Pod | |
metadata: | |
name: fluentd | |
spec: | |
containers: | |
- name: fluentd-agent | |
image: gcr.io/google_containers/fluentd-gcp:1.30 | |
env: | |
- name: FLUENTD_ARGS | |
value: -c /etc/fluentd-config/fluentd.conf | |
volumeMounts: | |
- name: config-volume | |
mountPath: /etc/fluentd-config | |
volumes: | |
- name: config-volume | |
configMap: | |
name: fluentd-config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment