2023-01-29 18:17:50 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace EesyPHP;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Performance monitoring
|
|
|
|
*/
|
|
|
|
|
|
|
|
class SentryTransaction {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Sentry transaction object
|
|
|
|
* @var \Sentry\Tracing\Transaction
|
|
|
|
*/
|
|
|
|
private $transaction;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Sentry transaction context object
|
|
|
|
* @var \Sentry\Tracing\TransactionContext
|
|
|
|
*/
|
|
|
|
private $context;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor: start a Sentry transaction
|
|
|
|
* @param string|null $op The operation name
|
|
|
|
* @param string|null $name The transaction name
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct($op=null, $name=null) {
|
2023-03-01 11:01:54 +01:00
|
|
|
// In phpstan context, do not initialize
|
2023-07-26 16:51:16 +02:00
|
|
|
// @phpstan-ignore-next-line
|
2023-03-01 11:01:54 +01:00
|
|
|
if (defined('__PHPSTAN_RUNNING__') && constant('__PHPSTAN_RUNNING__'))
|
|
|
|
return;
|
2023-01-29 18:17:50 +01:00
|
|
|
// Setup context for the full transaction
|
|
|
|
$this->context = new \Sentry\Tracing\TransactionContext();
|
|
|
|
$this->context->setName(
|
|
|
|
$name?$name:
|
|
|
|
(php_sapi_name()=='cli'?'CLI execution':'HTTP request')
|
|
|
|
);
|
|
|
|
$this->context->setOp(
|
|
|
|
$op?$op:
|
|
|
|
(php_sapi_name()=='cli'?'cli.command':'http.request')
|
|
|
|
);
|
|
|
|
|
|
|
|
// Start the transaction
|
|
|
|
$this->transaction = \Sentry\startTransaction($this->context);
|
|
|
|
|
|
|
|
// Set the current transaction as the current span so we can retrieve it later
|
|
|
|
\Sentry\SentrySdk::getCurrentHub()->setSpan($this->transaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor: Stop the current Sentry transaction
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __destruct() {
|
2023-03-01 11:01:54 +01:00
|
|
|
// In phpstan context, do nothing
|
2023-07-26 16:51:16 +02:00
|
|
|
// @phpstan-ignore-next-line
|
2023-03-01 11:01:54 +01:00
|
|
|
if (defined('__PHPSTAN_RUNNING__') && constant('__PHPSTAN_RUNNING__'))
|
|
|
|
return;
|
2023-01-29 18:17:50 +01:00
|
|
|
SentrySpan :: finishAll();
|
|
|
|
$this->transaction->finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab
|