From 76f023212ea35eb2e87daca9ccec3cd2ec978981 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Mon, 29 Sep 2025 12:50:48 +0800 Subject: [PATCH] refactor(sentry): remove exception message and stack trace data from tracing spans - Remove exception.message and exception.stack_trace data from all tracing spans - Remove exception.stack_trace extra tag from default configuration - Simplify exception handling in tracing aspects and listeners - Remove Feature dependency from Tracer class as it's no longer needed This reduces the amount of sensitive data captured in tracing spans while maintaining the essential exception metadata (class, code) as tags. --- src/sentry/publish/sentry.php | 1 - .../src/Tracing/Aspect/CoroutineAspect.php | 8 ---- .../Tracing/Aspect/GuzzleHttpClientAspect.php | 8 ---- .../Tracing/Listener/EventHandleListener.php | 46 ------------------- src/sentry/src/Tracing/Tracer.php | 17 +------ 5 files changed, 1 insertion(+), 79 deletions(-) diff --git a/src/sentry/publish/sentry.php b/src/sentry/publish/sentry.php index b00f47fa9..f80883b41 100644 --- a/src/sentry/publish/sentry.php +++ b/src/sentry/publish/sentry.php @@ -117,7 +117,6 @@ 'view' => env('SENTRY_TRACING_SPANS_VIEW', true), ], 'extra_tags' => [ - 'exception.stack_trace' => true, 'amqp.result' => false, 'annotation.result' => false, 'db.sql.bindings' => true, diff --git a/src/sentry/src/Tracing/Aspect/CoroutineAspect.php b/src/sentry/src/Tracing/Aspect/CoroutineAspect.php index 0f296df9f..fdb1740fe 100644 --- a/src/sentry/src/Tracing/Aspect/CoroutineAspect.php +++ b/src/sentry/src/Tracing/Aspect/CoroutineAspect.php @@ -111,15 +111,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint) 'error' => 'true', 'exception.class' => $exception::class, 'exception.code' => (string) $exception->getCode(), - ]) - ->setData([ - 'exception.message' => $exception->getMessage(), ]); - if ($this->feature->isTracingExtraTagEnabled('exception.stack_trace')) { - $coTransaction->setData([ - 'exception.stack_trace' => (string) $exception, - ]); - } throw $exception; } diff --git a/src/sentry/src/Tracing/Aspect/GuzzleHttpClientAspect.php b/src/sentry/src/Tracing/Aspect/GuzzleHttpClientAspect.php index 2c90e753d..21fa59dbb 100644 --- a/src/sentry/src/Tracing/Aspect/GuzzleHttpClientAspect.php +++ b/src/sentry/src/Tracing/Aspect/GuzzleHttpClientAspect.php @@ -161,15 +161,7 @@ function (Scope $scope) use ($proceedingJoinPoint, $options, $guzzleConfig) { 'error' => 'true', 'exception.class' => $exception::class, 'exception.code' => (string) $exception->getCode(), - ]) - ->setData([ - 'exception.message' => $exception->getMessage(), ]); - if ($this->feature->isTracingExtraTagEnabled('exception.stack_trace')) { - $span->setData([ - 'exception.stack_trace' => (string) $exception, - ]); - } } if (is_callable($onStats)) { diff --git a/src/sentry/src/Tracing/Listener/EventHandleListener.php b/src/sentry/src/Tracing/Listener/EventHandleListener.php index dd9b3fa68..3206c97ea 100644 --- a/src/sentry/src/Tracing/Listener/EventHandleListener.php +++ b/src/sentry/src/Tracing/Listener/EventHandleListener.php @@ -363,15 +363,7 @@ protected function handleRequestHandled(HttpEvent\RequestHandled|RpcEvent\Reques 'error' => 'true', 'exception.class' => $exception::class, 'exception.code' => (string) $exception->getCode(), - ]) - ->setData([ - 'exception.message' => $exception->getMessage(), - ]); - if ($this->feature->isTracingExtraTagEnabled('exception.stack_trace')) { - $span->setData([ - 'exception.stack_trace' => (string) $exception, ]); - } } } @@ -429,15 +421,7 @@ protected function handleCommandFinished(CommandEvent\AfterExecute $event): void 'error' => 'true', 'exception.class' => $exception::class, 'exception.code' => (string) $exception->getCode(), - ]) - ->setData([ - 'exception.message' => $exception->getMessage(), - ]); - if ($this->feature->isTracingExtraTagEnabled('exception.stack_trace')) { - $transaction->setData([ - 'exception.stack_trace' => (string) $exception, ]); - } } $transaction->setStatus( @@ -478,13 +462,7 @@ function (Scope $scope) use ($event) { 'error' => 'true', 'exception.class' => $exception::class, 'exception.code' => (string) $exception->getCode(), - ]) - ->setData([ - 'exception.message' => $exception->getMessage(), ]); - if ($this->feature->isTracingExtraTagEnabled('exception.stack_trace')) { - $span->setData(['exception.stack_trace' => (string) $exception]); - } } }, SpanContext::make() @@ -555,13 +533,7 @@ protected function handleCrontabTaskFinished(CrontabEvent\FailToExecute|CrontabE 'error' => 'true', 'exception.class' => $exception::class, 'exception.code' => (string) $exception->getCode(), - ]) - ->setData([ - 'exception.message' => $exception->getMessage(), ]); - if ($this->feature->isTracingExtraTagEnabled('exception.stack_trace')) { - $transaction->setData(['exception.stack_trace' => (string) $exception]); - } } } @@ -635,13 +607,7 @@ protected function handleAmqpMessageProcessed(AmqpEvent\AfterConsume|AmqpEvent\F 'error' => 'true', 'exception.class' => $exception::class, 'exception.code' => (string) $exception->getCode(), - ]) - ->setData([ - 'exception.message' => $exception->getMessage(), ]); - if ($this->feature->isTracingExtraTagEnabled('exception.stack_trace')) { - $transaction->setData(['exception.stack_trace' => (string) $exception]); - } } } @@ -707,13 +673,7 @@ protected function handleKafkaMessageProcessed(KafkaEvent\AfterConsume|KafkaEven 'error' => 'true', 'exception.class' => $exception::class, 'exception.code' => (string) $exception->getCode(), - ]) - ->setData([ - 'exception.message' => $exception->getMessage(), ]); - if ($this->feature->isTracingExtraTagEnabled('exception.stack_trace')) { - $transaction->setData(['exception.stack_trace' => (string) $exception]); - } } } @@ -766,13 +726,7 @@ protected function handleAsyncQueueJobProcessed(AsyncQueueEvent\AfterHandle|Asyn 'error' => 'true', 'exception.class' => $exception::class, 'exception.code' => (string) $exception->getCode(), - ]) - ->setData([ - 'exception.message' => $exception->getMessage(), ]); - if ($this->feature->isTracingExtraTagEnabled('exception.stack_trace')) { - $transaction->setData(['exception.stack_trace' => (string) $exception]); - } } } diff --git a/src/sentry/src/Tracing/Tracer.php b/src/sentry/src/Tracing/Tracer.php index 72e719743..8a21bb076 100644 --- a/src/sentry/src/Tracing/Tracer.php +++ b/src/sentry/src/Tracing/Tracer.php @@ -11,7 +11,6 @@ namespace FriendsOfHyperf\Sentry\Tracing; -use FriendsOfHyperf\Sentry\Feature; use Hyperf\Engine\Coroutine; use Sentry\SentrySdk; use Sentry\State\Scope; @@ -27,10 +26,6 @@ class Tracer { - public function __construct(protected Feature $feature) - { - } - /** * Starts a new Transaction and returns it. This is the entry point to manual tracing instrumentation. */ @@ -74,8 +69,6 @@ public function startTransaction(TransactionContext $transactionContext, array $ */ public function trace(callable $trace, SpanContext $context) { - $isTracingExtraTagEnabled = $this->feature->isTracingExtraTagEnabled('exception.stack_trace'); - if ($context->getStatus() === null) { $context->setStatus(SpanStatus::ok()); } @@ -87,7 +80,7 @@ public function trace(callable $trace, SpanContext $context) $context->setData(['coroutine.id' => Coroutine::id()] + $context->getData()); return trace( - function (Scope $scope) use ($trace, $isTracingExtraTagEnabled) { + function (Scope $scope) use ($trace) { try { return $trace($scope); } catch (Throwable $exception) { @@ -98,15 +91,7 @@ function (Scope $scope) use ($trace, $isTracingExtraTagEnabled) { 'error' => 'true', 'exception.class' => $exception::class, 'exception.code' => (string) $exception->getCode(), - ]) - ->setData([ - 'exception.message' => $exception->getMessage(), - ]); - if ($isTracingExtraTagEnabled) { - $span->setData([ - 'exception.stack_trace' => (string) $exception, ]); - } } throw $exception; }