php [哨兵] sentry.io #monitoring

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [哨兵] sentry.io #monitoring相关的知识,希望对你有一定的参考价值。

<?php
/*
https://docs.sentry.io/clients/php/
*/
//creation of the raven client
$sentryClient = $client = new Raven_Client('https://16f49115dc5845f89a3f5481e985971a@sentry.io/179825');

//enable the automatic error
$error_handler = new Raven_ErrorHandler($client);
$error_handler->registerExceptionHandler();
$error_handler->registerErrorHandler();
$error_handler->registerShutdownFunction();

//adding context
# about the current user
$client->user_context(array(
    'email' => $USER->getEmail()
));
// Basic Reporting
try{
}
catch(Exception $e){
	$event_id = $sentryClient->captureException($ex);	//return event id capture
  //or
  $sentryClient->getLastEventID();
}
// Provide some additional data with an exception
$sentryClient->captureException($ex, array(
    'extra' => array(
        'php_version' => phpversion()
    ),
));

//don’t have an actual exception object? Capture a message
$sentryClient->captureMessage('my log message');

# support parameterized formatting:
$sentryClient->captureMessage('my %s message', array('log'), array(
    'extra' => array(
        'foo' => 'bar',
    ),
));

/**
Attributes
*/
array(
	//Additional context for event
    'extra' => array('key' => 'value'),
	
	//grouping this event.
	'fingerprint' => ['{{ default }}', 'other value'],
	
	//level of the event: debug,info,warning,error,fatal
	'level' => 'warning',
	
	//name for the event
	'logger' => 'default'
	
	//Tags to index with this event
	'tags' => array('key' => 'value'),
	
	//user
	'user' => array(
        'id' => 42,
        'email' => 'clever-girl'
    )
);
//know when an event fails to record?
if ($sentryClient->getLastError() !== null) {
    echo "Something went very, very wrong";
    // $sentryClient->getLastError() contains the error that occurred
}
#https://docs.sentry.io/clients/php/usage/

以上是关于php [哨兵] sentry.io #monitoring的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Python 中向 Sentry 发送日志记录附件?

如何在 react-native 中动态加载模块?

使用 Laravel 6.20.27 (PHP v7.4.19) 的 Sentry v2.10 的 SSL 错误

Sentry.io 与 GitLab 的集成

在 Laravel 8 上安装 Sentry 时出错

项目集成sentry