Skip to content

Commit

Permalink
feat: add tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
igorgoncalves committed Dec 18, 2024
1 parent 51beb9d commit aeee2fd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
27 changes: 27 additions & 0 deletions app/components/Controller.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
<?php

use Sentry\Tracing\TransactionContext;
/**
* Controller is the customized base controller class.
* All controller classes for this application should extend from this base class.
*/


use Sentry\SentrySdk;

use Sentry\State\Hub;
use Sentry\Event;

class Controller extends CController
{
/**
Expand Down Expand Up @@ -49,6 +58,12 @@ public function init()

public function beforeAction($action)
{
$transaction = SentrySdk::getCurrentHub()->startTransaction(new TransactionContext(
Yii::app()->controller->id . '/' . $action->id,
));

SentrySdk::getCurrentHub()->setSpan($transaction);

if (parent::beforeAction($action)) {
// Verifica o timeout com base na última atividade
if (isset(Yii::app()->user->authTimeout)) {
Expand All @@ -68,4 +83,16 @@ public function beforeAction($action)
return false;
}

public function afterAction($action)
{
$transaction = SentrySdk::getCurrentHub()->getSpan();
if ($transaction) {
$transaction->finish();
}
// SentrySdk::getCurrentHub()->flush();

return parent::afterAction($action);
}


}
9 changes: 5 additions & 4 deletions app/config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,18 @@
'jsDsn' => getenv("SENTRY_DSN"),
'options' => [
'traces_sampler' => function (\Sentry\Tracing\SamplingContext $context): float {
return 1;
return 0.25;
},
'traces_sample_rate' => 1.0,
'profiles_sample_rate' => 1.0,
'traces_sample_rate' => 0.25,
'profiles_sample_rate' => 0.25,
'release' => 'tag@' . TAG_VERSION,
'environment' => INSTANCE,
'before_send' => function (\Sentry\Event $event): \Sentry\Event {
\Sentry\configureScope(function (\Sentry\State\Scope $scope): void {
$scope->setUser([
'id' => Yii::app()->user->loginInfos->id,
'username' => Yii::app()->user->loginInfos->username
'username' => Yii::app()->user->loginInfos->username,
'role' => Yii::app()->authManager->getRoles(Yii::app()->user->loginInfos->id)
]);
});
return $event;
Expand Down
1 change: 0 additions & 1 deletion app/controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public function actionIndex()
$this->redirect(yii::app()->createUrl('site/login'));
}

//$this->redirect(yii::app()->createUrl('student'));
$this->loadLogsHtml(5);

if (TagUtils::isInstructor()) {
Expand Down
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/app/vendor/autoload.php';
$yii_app=dirname(__FILE__).'/app/vendor/autoload.php';
$yii=dirname(__FILE__).'/vendor/autoload.php';

$instance=dirname(__FILE__).'/instance.php';
Expand Down Expand Up @@ -37,6 +37,7 @@
require_once $turma_t;

require_once $yii;
require_once $yii_app;
require_once $configtag;
require_once $instance;

Expand Down

0 comments on commit aeee2fd

Please sign in to comment.