Skip to content

Commit b2967fa

Browse files
committed
Merge branch 'master' into logs
2 parents a6281e8 + 93247f9 commit b2967fa

File tree

5 files changed

+46
-10
lines changed

5 files changed

+46
-10
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Changelog
22

3+
## 4.14.0
4+
5+
### Bug Fixes
6+
7+
- Fix tracing when using Laravel Octane [(#997)](https://github.com/getsentry/sentry-laravel/pull/997)
8+
9+
When using Laravel Octane, the SDK now correctly cleans up it's state after each request, ensuring that traces are correctly reported.
10+
11+
### Misc
12+
13+
- Add `sentry` prefix to publish group name [(#992)](https://github.com/getsentry/sentry-laravel/pull/992)
14+
15+
When running `php artisan vendor:publish`, the Sentry package exports are now prefixed with `sentry`, making it easier to distinguish from other packages.
16+
17+
- Remove support for `traceparent` header [(#994)](https://github.com/getsentry/sentry-laravel/pull/994)
18+
19+
The W3C's `traceparent` header is no longer automatically picked up and emitted by the SDK to prevent non-Sentry SDKs from starting a trace that is unwanted.
20+
321
## 4.13.0
422

523
The Sentry SDK team is happy to announce the immediate availability of Sentry Laravel SDK v4.13.0.

src/Sentry/Laravel/Console/PublishCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ private function setEnvValues(array $values): bool
105105

106106
$this->info("Updated {$envKey} with new value in your `.env` file.");
107107
} else {
108+
// Ensure there is a newline before writing env variables
109+
if (substr($envFileContents, -1) !== "\n") {
110+
$envFileContents .= "\n";
111+
}
108112
$envFileContents .= "{$envKey}={$envValue}\n";
109113

110114
$this->info("Added {$envKey} to your `.env` file.");

src/Sentry/Laravel/ServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function boot(): void
107107
if ($this->app instanceof Laravel) {
108108
$this->publishes([
109109
__DIR__ . '/../../../config/sentry.php' => config_path(static::$abstract . '.php'),
110-
], 'config');
110+
], 'sentry-config');
111111
}
112112

113113
$this->registerArtisanCommands();

src/Sentry/Laravel/Tracing/Middleware.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct(bool $continueAfterResponse = true)
7373
public function handle(Request $request, Closure $next)
7474
{
7575
if (app()->bound(HubInterface::class)) {
76-
$this->startTransaction($request, app(HubInterface::class));
76+
$this->startTransaction($request);
7777
}
7878

7979
return $next($request);
@@ -89,12 +89,14 @@ public function handle(Request $request, Closure $next)
8989
*/
9090
public function terminate(Request $request, $response): void
9191
{
92-
// If there is no transaction or the HubInterface is not bound in the container there is nothing for us to do
93-
if ($this->transaction === null || !app()->bound(HubInterface::class)) {
92+
// If there is no transaction there is nothing for us to do
93+
if ($this->transaction === null) {
9494
return;
9595
}
9696

9797
if ($this->shouldRouteBeIgnored($request)) {
98+
$this->discardTransaction();
99+
98100
return;
99101
}
100102

@@ -132,10 +134,12 @@ public function setBootedTimestamp(?float $timestamp = null): void
132134
$this->bootedTimestamp = $timestamp ?? microtime(true);
133135
}
134136

135-
private function startTransaction(Request $request, HubInterface $sentry): void
137+
private function startTransaction(Request $request): void
136138
{
139+
$hub = SentrySdk::getCurrentHub();
140+
137141
// Prevent starting a new transaction if we are already in a transaction
138-
if ($sentry->getTransaction() !== null) {
142+
if ($hub->getTransaction() !== null) {
139143
return;
140144
}
141145

@@ -168,9 +172,9 @@ private function startTransaction(Request $request, HubInterface $sentry): void
168172
'http.request.method' => strtoupper($request->method()),
169173
]);
170174

171-
$transaction = $sentry->startTransaction($context);
175+
$transaction = $hub->startTransaction($context);
172176

173-
SentrySdk::getCurrentHub()->setSpan($transaction);
177+
$hub->setSpan($transaction);
174178

175179
// If this transaction is not sampled, we can stop here to prevent doing work for nothing
176180
if (!$transaction->getSampled()) {
@@ -188,7 +192,17 @@ private function startTransaction(Request $request, HubInterface $sentry): void
188192
->setStartTimestamp($bootstrapSpan ? $bootstrapSpan->getEndTimestamp() : microtime(true))
189193
);
190194

191-
SentrySdk::getCurrentHub()->setSpan($this->appSpan);
195+
$hub->setSpan($this->appSpan);
196+
}
197+
198+
private function discardTransaction(): void
199+
{
200+
$this->appSpan = null;
201+
$this->transaction = null;
202+
$this->didRouteMatch = false;
203+
$this->bootedTimestamp = null;
204+
205+
SentrySdk::getCurrentHub()->setSpan(null);
192206
}
193207

194208
private function addAppBootstrapSpan(): ?Span

src/Sentry/Laravel/Version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
final class Version
66
{
77
public const SDK_IDENTIFIER = 'sentry.php.laravel';
8-
public const SDK_VERSION = '4.13.0';
8+
public const SDK_VERSION = '4.14.0';
99
}

0 commit comments

Comments
 (0)