-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Deeka Wong <[email protected]>
- Loading branch information
1 parent
715098a
commit e2c6861
Showing
9 changed files
with
95 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of friendsofhyperf/components. | ||
* | ||
* @link https://github.com/friendsofhyperf/components | ||
* @document https://github.com/friendsofhyperf/components/blob/main/README.md | ||
* @contact [email protected] | ||
*/ | ||
|
||
namespace FriendsOfHyperf\Sentry\Util; | ||
|
||
use Sentry\Tracing\Span; | ||
use Throwable; | ||
|
||
class CarrierPacker | ||
{ | ||
/** | ||
* @return string[] | ||
*/ | ||
public function unpack(string $data): array | ||
{ | ||
try { | ||
$carrier = json_decode($data, true, flags: JSON_THROW_ON_ERROR); | ||
|
||
return [ | ||
$carrier['sentry-trace'] ?? $carrier['traceparent'] ?? '', | ||
$carrier['baggage'] ?? '', | ||
$carrier['traceparent'] ?? '', | ||
]; | ||
} catch (Throwable) { | ||
return ['', '', '']; | ||
} | ||
} | ||
|
||
public function pack(Span $span): string | ||
{ | ||
return json_encode([ | ||
'sentry-trace' => $span->toTraceparent(), | ||
'baggage' => $span->toBaggage(), | ||
'traceparent' => $span->toW3CTraceparent(), | ||
]); | ||
} | ||
} |