Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sashengpeng committed Sep 30, 2020
1 parent 7ad1308 commit d1be98c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
25 changes: 25 additions & 0 deletions src/Base/EApmEventBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,4 +712,29 @@ public function getParentEventStat(string $spanId) : array

return $parentEventStat;
}

/**
* Clear registered events
* In Swoole framework, some variables do not clears automatically after request ended.
* So, related events in $registeredEvents should be cleared manually.
*
* @param string $transactionId
* @return void
*/
public static function registeredEventsClear(string $transactionId) : void
{
if (isset(self::$registeredEvents[$transactionId])) {
$transactionEvent = self::$registeredEvents[$transactionId];
if ($transactionEvent["eventType"] !== EApmTransaction::EVENT_TYPE) {
return;
}

$traceId = $transactionEvent["traceId"];
foreach (self::$registeredEvents as $eventId => $event) {
if ($event["traceId"] === $traceId) {
unset(self::$registeredEvents[$eventId]);
}
}
}
}
}
12 changes: 6 additions & 6 deletions src/EApmComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class EApmComposer
* Agent version
* @const
*/
public const AGENT_VERSION = "1.1.0";
public const AGENT_VERSION = "1.1.1";

/**
* Agent name
Expand Down Expand Up @@ -323,11 +323,7 @@ public function setSampleRate(float $sampleRate) : void
*/
public function getCurrentTransaction()
{
return $this->currentTransaction
?? $this->startNewTransaction(
$this->getDefaultTransactionName(),
self::DEFAULT_TRANSACTION_TYPE
);
return $this->currentTransaction;
}

/**
Expand Down Expand Up @@ -560,6 +556,10 @@ public function addEvent(EApmEventBase $event) : void
*/
public function eventsPush() : void
{
if (is_null($this->getCurrentTransaction())) {
return;
}

if (is_null($this->getConfigure())) {
$this->setConfigure(new EApmConfigure("", "", "eapm-php-project"));
}
Expand Down
3 changes: 3 additions & 0 deletions src/EApmEventIntake.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ public function eventPush() : bool
return false;
} finally {
$this->eventsReset();
EApmEventBase::registeredEventsClear(
$this->getComposer()->getCurrentTransaction()->getId()
);
}

/*
Expand Down
14 changes: 14 additions & 0 deletions src/Events/EApmMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace EApmPhp\Events;

use EApmPhp\Base\EApmContainer;
use EApmPhp\Base\EApmEventBase;
use EApmPhp\EApmComposer;
use EApmPhp\Util\EApmServiceUtil;
Expand All @@ -28,6 +29,19 @@ class EApmMetadata extends EApmEventBase implements \JsonSerializable
*/
public const EVENT_TYPE = "metadata";

/**
* EApmMetadata constructor.
* @param EApmEventBase|null $parentEvent
*/
public function __construct(?EApmEventBase $parentEvent = null)
{
$this->setComposer(EApmContainer::make("GAgent"));
if (!is_null($this->getComposer()->getCurrentTransaction())) {
$parentEvent = $this->getComposer()->getCurrentTransaction();
}
parent::__construct($parentEvent);
}

/**
* Json serialize transaction event object
* @link https://www.elastic.co/guide/en/apm/server/master/metadata-api.html
Expand Down

0 comments on commit d1be98c

Please sign in to comment.