Skip to content

Commit 9fdf629

Browse files
authored
Merge branch 'master' into 3.x
2 parents 3e6e5be + fd85d9b commit 9fdf629

File tree

5 files changed

+17
-65
lines changed

5 files changed

+17
-65
lines changed

src/Sentry/Laravel/Console/TestCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ public function log($level, $message, array $context = []): void
139139
$transactionContext = new TransactionContext();
140140
$transactionContext->setSampled(true);
141141
$transactionContext->setName('Sentry Test Transaction');
142-
$transactionContext->setSource(TransactionSource::custom());
143142
$transactionContext->setOp('sentry.test');
144143

145144
$transaction = $hub->startTransaction($transactionContext);

src/Sentry/Laravel/Integration.php

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Illuminate\Support\Str;
77
use Sentry\SentrySdk;
88
use Sentry\Tracing\Span;
9-
use Sentry\Tracing\TransactionSource;
109
use function Sentry\addBreadcrumb;
1110
use function Sentry\configureScope;
1211
use Sentry\Breadcrumb;
@@ -123,48 +122,27 @@ public static function flushEvents(): void
123122
* @param \Illuminate\Routing\Route $route
124123
*
125124
* @return string
126-
*
127-
* @internal This helper is used in various places to extra meaninful info from a Laravel Route object.
128-
* @deprecated This will be removed in version 3.0, use `extractNameAndSourceForRoute` instead.
129125
*/
130126
public static function extractNameForRoute(Route $route): string
131127
{
132-
return self::extractNameAndSourceForRoute($route)[0];
133-
}
134-
135-
/**
136-
* Extract the readable name for a route and the transaction source for where that route name came from.
137-
*
138-
* @param \Illuminate\Routing\Route $route
139-
*
140-
* @return array{0: string, 1: \Sentry\Tracing\TransactionSource}
141-
*
142-
* @internal This helper is used in various places to extra meaninful info from a Laravel Route object.
143-
*/
144-
public static function extractNameAndSourceForRoute(Route $route): array
145-
{
146-
$source = null;
147128
$routeName = null;
148129

149-
// some.action (route name/alias)
130+
// someaction (route name/alias)
150131
if ($route->getName()) {
151-
$source = TransactionSource::component();
152132
$routeName = self::extractNameForNamedRoute($route->getName());
153133
}
154134

155135
// Some\Controller@someAction (controller action)
156136
if (empty($routeName) && $route->getActionName()) {
157-
$source = TransactionSource::component();
158137
$routeName = self::extractNameForActionRoute($route->getActionName());
159138
}
160139

161-
// /some/{action} // Fallback to the route uri (with parameter placeholders)
140+
// /someaction // Fallback to the url
162141
if (empty($routeName) || $routeName === 'Closure') {
163-
$source = TransactionSource::route();
164142
$routeName = '/' . ltrim($route->uri(), '/');
165143
}
166144

167-
return [$routeName, $source];
145+
return $routeName;
168146
}
169147

170148
/**
@@ -228,25 +206,7 @@ public static function sentryTracingMeta(): string
228206
}
229207

230208
$content = sprintf('<meta name="sentry-trace" content="%s"/>', $span->toTraceparent());
231-
232-
return $content;
233-
}
234-
235-
/**
236-
* Retrieve the meta tags with baggage information to link this request to front-end requests.
237-
* This propagates the Dynamic Sampling Context.
238-
*
239-
* @return string
240-
*/
241-
public static function sentryBaggageMeta(): string
242-
{
243-
$span = self::currentTracingSpan();
244-
245-
if ($span === null) {
246-
return '';
247-
}
248-
249-
$content = sprintf('<meta name="baggage" content="%s"/>', $span->toBaggage());
209+
// $content .= sprintf('<meta name="sentry-trace-data" content="%s"/>', $span->getDescription());
250210

251211
return $content;
252212
}

src/Sentry/Laravel/Tracing/EventHandler.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@
1616
use Sentry\Tracing\SpanContext;
1717
use Sentry\Tracing\SpanStatus;
1818
use Sentry\Tracing\TransactionContext;
19-
use Sentry\Tracing\TransactionSource;
2019

2120
class EventHandler
2221
{
2322
public const QUEUE_PAYLOAD_TRACE_PARENT_DATA = 'sentry_trace_parent_data';
2423

25-
public const QUEUE_PAYLOAD_BAGGAGE_DATA = 'sentry_baggage_data';
26-
2724
/**
2825
* Map event handlers to events.
2926
*
@@ -265,10 +262,11 @@ protected function queueJobProcessingHandler(QueueEvents\JobProcessing $event):
265262
}
266263

267264
if ($parentSpan === null) {
268-
$baggage = $event->job->payload()[self::QUEUE_PAYLOAD_BAGGAGE_DATA] ?? null;
269265
$traceParent = $event->job->payload()[self::QUEUE_PAYLOAD_TRACE_PARENT_DATA] ?? null;
270266

271-
$context = TransactionContext::fromHeaders($traceParent ?? '', $baggage ?? '');
267+
$context = $traceParent === null
268+
? new TransactionContext
269+
: TransactionContext::fromSentryTrace($traceParent);
272270

273271
// If the parent transaction was not sampled we also stop the queue job from being recorded
274272
if ($context->getParentSampled() === false) {
@@ -296,7 +294,6 @@ protected function queueJobProcessingHandler(QueueEvents\JobProcessing $event):
296294

297295
if ($context instanceof TransactionContext) {
298296
$context->setName($resolvedJobName ?? $event->job->getName());
299-
$context->setSource(TransactionSource::task());
300297
}
301298

302299
$context->setOp('queue.process');

src/Sentry/Laravel/Tracing/Integrations/LighthouseIntegration.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Sentry\Laravel\Integration;
1414
use Sentry\SentrySdk;
1515
use Sentry\Tracing\SpanContext;
16-
use Sentry\Tracing\TransactionSource;
1716

1817
class LighthouseIntegration implements IntegrationInterface
1918
{
@@ -158,7 +157,7 @@ private function updateTransactionName(): void
158157
return;
159158
}
160159

161-
array_walk($groupedOperations, static function (&$operations, string $operationType) {
160+
array_walk($groupedOperations, static function (array &$operations, string $operationType) {
162161
sort($operations, SORT_STRING);
163162

164163
$operations = "{$operationType}{" . implode(',', $operations) . '}';
@@ -169,7 +168,6 @@ private function updateTransactionName(): void
169168
$transactionName = 'lighthouse?' . implode('&', $groupedOperations);
170169

171170
$transaction->setName($transactionName);
172-
$transaction->getMetadata()->setSource(TransactionSource::custom());
173171

174172
Integration::setTransaction($transactionName);
175173
}

src/Sentry/Laravel/Tracing/Middleware.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Sentry\Tracing\Span;
1212
use Sentry\Tracing\SpanContext;
1313
use Sentry\Tracing\TransactionContext;
14-
use Sentry\Tracing\TransactionSource;
1514
use Symfony\Component\HttpFoundation\Response;
1615

1716
class Middleware
@@ -102,11 +101,11 @@ public function setBootedTimestamp(?float $timestamp = null): void
102101
private function startTransaction(Request $request, HubInterface $sentry): void
103102
{
104103
$requestStartTime = $request->server('REQUEST_TIME_FLOAT', microtime(true));
104+
$sentryTraceHeader = $request->header('sentry-trace');
105105

106-
$context = TransactionContext::fromHeaders(
107-
$request->header('sentry-trace', ''),
108-
$request->header('baggage', '')
109-
);
106+
$context = $sentryTraceHeader
107+
? TransactionContext::fromSentryTrace($sentryTraceHeader)
108+
: new TransactionContext;
110109

111110
$context->setOp('http.server');
112111
$context->setData([
@@ -180,9 +179,9 @@ private function hydrateRequestData(Request $request): void
180179
$route = $request->route();
181180

182181
if ($route instanceof Route) {
183-
[$transactionName, $transactionSource] = Integration::extractNameAndSourceForRoute($route);
184-
185-
$this->updateTransactionNameIfDefault($transactionName, $transactionSource);
182+
$this->updateTransactionNameIfDefault(
183+
Integration::extractNameForRoute($route)
184+
);
186185

187186
$this->transaction->setData([
188187
'name' => $route->getName(),
@@ -191,15 +190,15 @@ private function hydrateRequestData(Request $request): void
191190
]);
192191
}
193192

194-
$this->updateTransactionNameIfDefault('/' . ltrim($request->path(), '/'), TransactionSource::url());
193+
$this->updateTransactionNameIfDefault('/' . ltrim($request->path(), '/'));
195194
}
196195

197196
private function hydrateResponseData(Response $response): void
198197
{
199198
$this->transaction->setHttpStatus($response->getStatusCode());
200199
}
201200

202-
private function updateTransactionNameIfDefault(?string $name, ?TransactionSource $source): void
201+
private function updateTransactionNameIfDefault(?string $name): void
203202
{
204203
// Ignore empty names (and `null`) for caller convenience
205204
if (empty($name)) {
@@ -214,6 +213,5 @@ private function updateTransactionNameIfDefault(?string $name, ?TransactionSourc
214213
}
215214

216215
$this->transaction->setName($name);
217-
$this->transaction->getMetadata()->setSource($source ?? TransactionSource::custom());
218216
}
219217
}

0 commit comments

Comments
 (0)