Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/State/Hub.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ public function getIntegration(string $className): ?IntegrationInterface
public function startTransaction(TransactionContext $context, array $customSamplingContext = []): Transaction
{
$transaction = new Transaction($context, $this);

// Sync the transaction name with the scope
$this->getScope()->setTransactionName($transaction->getName());

$client = $this->getClient();
$options = $client !== null ? $client->getOptions() : null;

Expand Down
28 changes: 28 additions & 0 deletions src/State/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class Scope
*/
private $span;

/**
* @var string|null The transaction name
*/
private $transactionName;

/**
* @var callable[] List of event processors
*
Expand Down Expand Up @@ -363,6 +368,10 @@ public function applyToEvent(Event $event, ?EventHint $hint = null, ?Options $op
$event->setExtra(array_merge($this->extra, $event->getExtra()));
}

if ($this->transactionName !== null) {
$event->setTransaction($this->transactionName);
}

if ($this->user !== null) {
$user = $event->getUser();

Expand Down Expand Up @@ -460,6 +469,25 @@ public function getTransaction(): ?Transaction
return null;
}

/**
* Set the transaction name on the scope as well as on the transaction
* attached to the scope (if there is one).
*/
public function setTransactionName(string $name): self
{
$this->transactionName = $name;

// If we have an active transaction, update its name as well
if ($this->span !== null) {
$transaction = $this->span->getTransaction();
if ($transaction !== null) {
$transaction->setName($name);
}
}

return $this;
}

public function getPropagationContext(): PropagationContext
{
return $this->propagationContext;
Expand Down
6 changes: 6 additions & 0 deletions src/Tracing/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Sentry\Profiling\Profiler;
use Sentry\SentrySdk;
use Sentry\State\HubInterface;
use Sentry\State\Scope;

/**
* This class stores all the information about a Transaction.
Expand Down Expand Up @@ -77,6 +78,11 @@ public function setName(string $name): self
{
$this->name = $name;

// Sync the transaction name with the scope
$this->hub->configureScope(function (Scope $scope) use ($name) {
$scope->setTransactionName($name);
});

return $this;
}

Expand Down