Skip to content

Commit fd85d9b

Browse files
authored
Revert "feat: Add support for Dynamic Sampling (#572)" (#584)
This reverts commit b9bb0e3.
1 parent fe691ea commit fd85d9b

File tree

7 files changed

+25
-96
lines changed

7 files changed

+25
-96
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"require": {
2424
"php": "^7.2 | ^8.0",
2525
"illuminate/support": "5.0 - 5.8 | ^6.0 | ^7.0 | ^8.0 | ^9.0",
26-
"sentry/sentry": "^3.9",
26+
"sentry/sentry": "^3.3",
2727
"sentry/sdk": "^3.1",
2828
"symfony/psr-http-message-bridge": "^1.0 | ^2.0",
2929
"nyholm/psr7": "^1.0"

src/Sentry/Laravel/Console/TestCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ public function log($level, $message, array $context = []): void
145145
$transactionContext = new TransactionContext();
146146
$transactionContext->setSampled(true);
147147
$transactionContext->setName('Sentry Test Transaction');
148-
$transactionContext->setSource(TransactionSource::custom());
149148
$transactionContext->setOp('sentry.test');
150149

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

src/Sentry/Laravel/EventHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function __call($method, $arguments)
283283
*/
284284
protected function routerMatchedHandler(Route $route)
285285
{
286-
[$routeName] = Integration::extractNameAndSourceForRoute($route);
286+
$routeName = Integration::extractNameForRoute($route);
287287

288288
Integration::addBreadcrumb(new Breadcrumb(
289289
Breadcrumb::LEVEL_INFO,

src/Sentry/Laravel/Integration.php

Lines changed: 7 additions & 69 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
/**
@@ -174,45 +152,24 @@ public static function extractNameAndSourceForRoute(Route $route): array
174152
* @param string $path The path of the request
175153
*
176154
* @return string
177-
*
178-
* @internal This helper is used in various places to extra meaninful info from a Lumen route data.
179-
* @deprecated This will be removed in version 3.0, use `extractNameAndSourceForLumenRoute` instead.
180155
*/
181156
public static function extractNameForLumenRoute(array $routeData, string $path): string
182157
{
183-
return self::extractNameAndSourceForLumenRoute($routeData, $path)[0];
184-
}
185-
186-
/**
187-
* Extract the readable name for a Lumen route and the transaction source for where that route name came from.
188-
*
189-
* @param array $routeData The array of route data
190-
* @param string $path The path of the request
191-
*
192-
* @return array{0: string, 1: \Sentry\Tracing\TransactionSource}
193-
*
194-
* @internal This helper is used in various places to extra meaninful info from a Lumen route data.
195-
*/
196-
public static function extractNameAndSourceForLumenRoute(array $routeData, string $path): array
197-
{
198-
$source = null;
199158
$routeName = null;
200159

201160
$route = $routeData[1] ?? [];
202161

203-
// some.action (route name/alias)
162+
// someaction (route name/alias)
204163
if (!empty($route['as'])) {
205-
$source = TransactionSource::component();
206164
$routeName = self::extractNameForNamedRoute($route['as']);
207165
}
208166

209167
// Some\Controller@someAction (controller action)
210168
if (empty($routeName) && !empty($route['uses'])) {
211-
$source = TransactionSource::component();
212169
$routeName = self::extractNameForActionRoute($route['uses']);
213170
}
214171

215-
// /some/{action} // Fallback to the route uri (with parameter placeholders)
172+
// /someaction // Fallback to the url
216173
if (empty($routeName) || $routeName === 'Closure') {
217174
$routeUri = array_reduce(
218175
array_keys($routeData[2]),
@@ -222,11 +179,10 @@ static function ($carry, $key) use ($routeData) {
222179
$path
223180
);
224181

225-
$source = TransactionSource::url();
226182
$routeName = '/' . ltrim($routeUri, '/');
227183
}
228184

229-
return [$routeName, $source];
185+
return $routeName;
230186
}
231187

232188
/**
@@ -291,25 +247,7 @@ public static function sentryTracingMeta(): string
291247
}
292248

293249
$content = sprintf('<meta name="sentry-trace" content="%s"/>', $span->toTraceparent());
294-
295-
return $content;
296-
}
297-
298-
/**
299-
* Retrieve the meta tags with baggage information to link this request to front-end requests.
300-
* This propagates the Dynamic Sampling Context.
301-
*
302-
* @return string
303-
*/
304-
public static function sentryBaggageMeta(): string
305-
{
306-
$span = self::currentTracingSpan();
307-
308-
if ($span === null) {
309-
return '';
310-
}
311-
312-
$content = sprintf('<meta name="baggage" content="%s"/>', $span->toBaggage());
250+
// $content .= sprintf('<meta name="sentry-trace-data" content="%s"/>', $span->getDescription());
313251

314252
return $content;
315253
}

src/Sentry/Laravel/Tracing/EventHandler.php

Lines changed: 3 additions & 7 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
*
@@ -156,7 +153,6 @@ public function subscribeQueueEvents(QueueManager $queue): void
156153

157154
if ($currentSpan !== null && $payload !== null) {
158155
$payload[self::QUEUE_PAYLOAD_TRACE_PARENT_DATA] = $currentSpan->toTraceparent();
159-
$payload[self::QUEUE_PAYLOAD_BAGGAGE_DATA] = $currentSpan->toBaggage();
160156
}
161157

162158
return $payload;
@@ -297,10 +293,11 @@ protected function queueJobProcessingHandler(QueueEvents\JobProcessing $event)
297293
}
298294

299295
if ($parentSpan === null) {
300-
$baggage = $event->job->payload()[self::QUEUE_PAYLOAD_BAGGAGE_DATA] ?? null;
301296
$traceParent = $event->job->payload()[self::QUEUE_PAYLOAD_TRACE_PARENT_DATA] ?? null;
302297

303-
$context = TransactionContext::fromHeaders($traceParent ?? '', $baggage ?? '');
298+
$context = $traceParent === null
299+
? new TransactionContext
300+
: TransactionContext::fromSentryTrace($traceParent);
304301

305302
// If the parent transaction was not sampled we also stop the queue job from being recorded
306303
if ($context->getParentSampled() === false) {
@@ -328,7 +325,6 @@ protected function queueJobProcessingHandler(QueueEvents\JobProcessing $event)
328325

329326
if ($context instanceof TransactionContext) {
330327
$context->setName($resolvedJobName ?? $event->job->getName());
331-
$context->setSource(TransactionSource::task());
332328
}
333329

334330
$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: 12 additions & 14 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
@@ -103,11 +102,11 @@ public function setBootedTimestamp(?float $timestamp = null): void
103102
private function startTransaction(Request $request, HubInterface $sentry): void
104103
{
105104
$requestStartTime = $request->server('REQUEST_TIME_FLOAT', microtime(true));
105+
$sentryTraceHeader = $request->header('sentry-trace');
106106

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

112111
$context->setOp('http.server');
113112
$context->setData([
@@ -181,19 +180,19 @@ private function hydrateRequestData(Request $request): void
181180
$route = $request->route();
182181

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

188187
$this->transaction->setData([
189188
'name' => $route->getName(),
190189
'action' => $route->getActionName(),
191190
'method' => $request->getMethod(),
192191
]);
193192
} elseif (is_array($route) && count($route) === 3) {
194-
[$transactionName, $transactionSource] = Integration::extractNameAndSourceForLumenRoute($route, $request->path());
195-
196-
$this->updateTransactionNameIfDefault($transactionName, $transactionSource);
193+
$this->updateTransactionNameIfDefault(
194+
Integration::extractNameForLumenRoute($route, $request->path())
195+
);
197196

198197
$action = $route[1] ?? [];
199198

@@ -204,15 +203,15 @@ private function hydrateRequestData(Request $request): void
204203
]);
205204
}
206205

207-
$this->updateTransactionNameIfDefault('/' . ltrim($request->path(), '/'), TransactionSource::url());
206+
$this->updateTransactionNameIfDefault('/' . ltrim($request->path(), '/'));
208207
}
209208

210209
private function hydrateResponseData(Response $response): void
211210
{
212211
$this->transaction->setHttpStatus($response->getStatusCode());
213212
}
214213

215-
private function updateTransactionNameIfDefault(?string $name, ?TransactionSource $source): void
214+
private function updateTransactionNameIfDefault(?string $name): void
216215
{
217216
// Ignore empty names (and `null`) for caller convenience
218217
if (empty($name)) {
@@ -227,6 +226,5 @@ private function updateTransactionNameIfDefault(?string $name, ?TransactionSourc
227226
}
228227

229228
$this->transaction->setName($name);
230-
$this->transaction->getMetadata()->setSource($source ?? TransactionSource::custom());
231229
}
232230
}

0 commit comments

Comments
 (0)