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 support for W3C traceparent header #834

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"require": {
"php": "^7.2 | ^8.0",
"illuminate/support": "^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0",
"sentry/sentry": "^4.3",
"sentry/sentry": "^4.4",
"symfony/psr-http-message-bridge": "^1.0 | ^2.0 | ^6.0 | ^7.0",
"nyholm/psr7": "^1.0"
},
Expand Down
4 changes: 3 additions & 1 deletion src/Sentry/Laravel/Features/HttpClientIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Sentry\Tracing\SpanStatus;
use function Sentry\getBaggage;
use function Sentry\getTraceparent;
use function Sentry\getW3CTraceparent;

class HttpClientIntegration extends Feature
{
Expand Down Expand Up @@ -55,7 +56,8 @@ public function attachTracingHeadersToRequest(RequestInterface $request)
if ($this->shouldAttachTracingHeaders($request)) {
return $request
->withHeader('baggage', getBaggage())
->withHeader('sentry-trace', getTraceparent());
->withHeader('sentry-trace', getTraceparent())
->withHeader('traceparent', getW3CTraceparent());
}

return $request;
Expand Down
13 changes: 12 additions & 1 deletion src/Sentry/Laravel/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use function Sentry\configureScope;
use function Sentry\getBaggage;
use function Sentry\getTraceparent;
use function Sentry\getW3CTraceparent;

class Integration implements IntegrationInterface
{
Expand Down Expand Up @@ -168,7 +169,7 @@ static function ($carry, $key) use ($routeData) {
*/
public static function sentryMeta(): string
{
return self::sentryTracingMeta() . self::sentryBaggageMeta();
return self::sentryTracingMeta() . self::sentryW3CTracingMeta() . self::sentryBaggageMeta();
}

/**
Expand All @@ -181,6 +182,16 @@ public static function sentryTracingMeta(): string
return sprintf('<meta name="sentry-trace" content="%s"/>', getTraceparent());
}

/**
* Retrieve the `traceparent` meta tag with tracing information to link this request to front-end requests.
*
* @return string
*/
public static function sentryW3CTracingMeta(): string
{
return sprintf('<meta name="traceparent" content="%s"/>', getW3CTraceparent());
}

/**
* Retrieve the `baggage` meta tag with information to link this request to front-end requests.
* This propagates the Dynamic Sampling Context.
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Laravel/Tracing/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private function startTransaction(Request $request, HubInterface $sentry): void
);

$context = continueTrace(
$request->header('sentry-trace', ''),
$request->header('sentry-trace') ?? $request->header('traceparent', ''),
$request->header('baggage', '')
);

Expand Down
Loading