Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Scope::setTransactionName() #1719

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
@@ -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;

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

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

/**
* @var callable[] List of event processors
*
@@ -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();

@@ -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;
6 changes: 6 additions & 0 deletions src/Tracing/Transaction.php
Original file line number Diff line number Diff line change
@@ -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.
@@ -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;
}