Skip to content

Commit 489c17b

Browse files
authored
Merge pull request #25 from facade/add-tracking-uuid
Add tracking UUID
2 parents 47b639d + a38e32d commit 489c17b

16 files changed

+83
-17
lines changed

.github/workflows/php-cs-fixer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Fix style
1414
uses: docker://oskarstark/php-cs-fixer-ga
1515
with:
16-
args: --config=.php_cs --allow-risky=yes
16+
args: --config=.php-cs-fixer.php --allow-risky=yes
1717

1818
- name: Extract branch name
1919
shell: bash

.php-cs-fixer.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"php":"8.0.10","version":"3.1.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_opening_tag":true,"braces":{"allow_single_line_anonymous_class_with_empty_body":true},"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"sort_algorithm":"alpha"},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"method":"one"}}},"hashes":{"src\/Middleware\/AddGlows.php":2757630618,"src\/Middleware\/AnonymizeIp.php":2582237091,"src\/Middleware\/CensorRequestBodyFields.php":3157018559,"src\/Time\/Time.php":3063453905,"src\/Time\/SystemTime.php":1875330795,"src\/Solutions\/ReportSolution.php":1414311092,"src\/View.php":1758466251,"src\/Enums\/GroupingTypes.php":794823242,"src\/Enums\/MessageLevels.php":2252993314,"src\/Glows\/Glow.php":2938926460,"src\/Glows\/Recorder.php":741799100,"src\/Stacktrace\/Codesnippet.php":1758681831,"src\/Stacktrace\/File.php":2191220409,"src\/Stacktrace\/Stacktrace.php":3487330919,"src\/Stacktrace\/Frame.php":2201806026,"src\/Truncation\/ReportTrimmer.php":1411772441,"src\/Truncation\/TrimStringsStrategy.php":1149918480,"src\/Truncation\/TrimContextItemsStrategy.php":2488083767,"src\/Truncation\/TruncationStrategy.php":2876512000,"src\/Truncation\/AbstractTruncationStrategy.php":3738899546,"src\/Flare.php":615945847,"src\/Http\/Response.php":3175166434,"src\/Http\/Exceptions\/BadResponse.php":2136825932,"src\/Http\/Exceptions\/MissingParameter.php":3963873571,"src\/Http\/Exceptions\/NotFound.php":605045793,"src\/Http\/Exceptions\/BadResponseCode.php":3629899270,"src\/Http\/Exceptions\/InvalidData.php":4224780353,"src\/Http\/Client.php":3513047095,"src\/Contracts\/ProvidesFlareContext.php":3654647562,"src\/Report.php":677962539,"src\/helpers.php":878229930,"src\/Api.php":4147640268,"src\/Concerns\/UsesTime.php":2203258051,"src\/Concerns\/HasContext.php":2283577173,"src\/Context\/ContextContextDetector.php":1433590813,"src\/Context\/ConsoleContext.php":2891436865,"src\/Context\/ContextInterface.php":3556428806,"src\/Context\/RequestContext.php":916577092,"src\/Context\/ContextDetectorInterface.php":3409530978,"src\/Frame.php":1560844999,"tests\/TestClasses\/ExceptionWithContext.php":3729019575,"tests\/TestClasses\/Assert.php":151773303,"tests\/TestClasses\/DumpDriver.php":3041182929,"tests\/TestClasses\/CodeSnippetDriver.php":615657858,"tests\/TestClasses\/FakeTime.php":2977551027,"tests\/TestClasses\/ReportDriver.php":3461657491,"tests\/FlareTest.php":2320308878,"tests\/Glows\/RecorderTest.php":946753721,"tests\/Stacktrace\/FileTest.php":420603250,"tests\/Stacktrace\/__snapshots__\/StrackTraceTest__it_can_detect_application_frames__1.php":167790125,"tests\/Stacktrace\/CodesnippetTest.php":765068665,"tests\/Stacktrace\/CodeSnippetDriver.php":4244799073,"tests\/Stacktrace\/ThrowAndReturnExceptionAction.php":4198281204,"tests\/Stacktrace\/StrackTraceTest.php":757065022,"tests\/Truncation\/TrimContextItemsStrategyTest.php":112441598,"tests\/Truncation\/TrimStringsStrategyTest.php":2187306892,"tests\/TestCase.php":996592721,"tests\/Concerns\/MatchesCodeSnippetSnapshots.php":685279681,"tests\/Concerns\/MatchesDumpSnapshots.php":3419801558,"tests\/Concerns\/MatchesReportSnapshots.php":2362276842,"tests\/Mocks\/FakeClient.php":1694586070,"tests\/ReportTest.php":1195087882,"tests\/Context\/ConsoleContextTest.php":3637467343,"tests\/Context\/RequestContextTest.php":1346110003}}

.php_cs renamed to .php-cs-fixer.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
->ignoreDotFiles(true)
1515
->ignoreVCS(true);
1616

17-
return PhpCsFixer\Config::create()
17+
return (new PhpCsFixer\Config())
1818
->setRules([
19-
'@PSR2' => true,
19+
'@PSR12' => true,
2020
'array_syntax' => ['syntax' => 'short'],
21-
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
21+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
2222
'no_unused_imports' => true,
2323
'not_operator_with_successor_space' => true,
24-
'trailing_comma_in_multiline_array' => true,
24+
'trailing_comma_in_multiline' => true,
2525
'phpdoc_scalar' => true,
2626
'unary_operator_spaces' => true,
2727
'binary_operator_spaces' => true,
@@ -30,9 +30,15 @@
3030
],
3131
'phpdoc_single_line_var_spacing' => true,
3232
'phpdoc_var_without_name' => true,
33+
'class_attributes_separation' => [
34+
'elements' => [
35+
'method' => 'one',
36+
],
37+
],
3338
'method_argument_space' => [
3439
'on_multiline' => 'ensure_fully_multiline',
3540
'keep_multiple_spaces_after_comma' => true,
36-
]
41+
],
42+
'single_trait_insert_per_statement' => true,
3743
])
3844
->setFinder($finder);

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `flare-client-php` will be documented in this file
44

5+
## 1.9.0 - 2021-09-13
6+
7+
- add report tracking uuid
8+
59
## 1.8.1 - 2021-05-31
610

711
- improve compatibility with Symfony 5.3

src/Context/RequestContext.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Facade\FlareClient\Context;
44

5-
use BadMethodCallException;
65
use Symfony\Component\HttpFoundation\File\UploadedFile;
76
use Symfony\Component\HttpFoundation\Request;
87
use Symfony\Component\HttpFoundation\Session\SessionInterface;

src/Enums/GroupingTypes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/** @deprecated */
66
class GroupingTypes
77
{
8-
const TOP_FRAME = 'topFrame';
8+
public const TOP_FRAME = 'topFrame';
99

10-
const EXCEPTION = 'exceptionClass';
10+
public const EXCEPTION = 'exceptionClass';
1111
}

src/Enums/MessageLevels.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
class MessageLevels
66
{
7-
const INFO = 'info';
7+
public const INFO = 'info';
88

9-
const DEBUG = 'debug';
9+
public const DEBUG = 'debug';
1010

11-
const WARNING = 'warning';
11+
public const WARNING = 'warning';
1212

13-
const ERROR = 'error';
13+
public const ERROR = 'error';
1414

15-
const CRITICAL = 'critical';
15+
public const CRITICAL = 'critical';
1616
}

src/Glows/Recorder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Recorder
66
{
7-
const GLOW_LIMIT = 30;
7+
public const GLOW_LIMIT = 30;
88

99
private $glows = [];
1010

src/Report.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
class Report
1717
{
18-
use UsesTime, HasContext;
18+
use UsesTime;
19+
use HasContext;
1920

2021
/** @var \Facade\FlareClient\Stacktrace\Stacktrace */
2122
private $stacktrace;
@@ -65,6 +66,12 @@ class Report
6566
/** @var string */
6667
private $groupBy ;
6768

69+
/** @var string */
70+
private $trackingUuid;
71+
72+
/** @var null string|null */
73+
public static $fakeTrackingUuid = null;
74+
6875
public static function createForThrowable(
6976
Throwable $throwable,
7077
ContextInterface $context,
@@ -106,6 +113,16 @@ public static function createForMessage(string $message, string $logLevel, Conte
106113
->openFrameIndex($stacktrace->firstApplicationFrameIndex());
107114
}
108115

116+
public function __construct()
117+
{
118+
$this->trackingUuid = self::$fakeTrackingUuid ?? $this->generateUuid();
119+
}
120+
121+
public function trackingUuid(): string
122+
{
123+
return $this->trackingUuid;
124+
}
125+
109126
public function exceptionClass(string $exceptionClass)
110127
{
111128
$this->exceptionClass = $exceptionClass;
@@ -294,6 +311,25 @@ public function toArray()
294311
'open_frame_index' => $this->openFrameIndex,
295312
'application_path' => $this->applicationPath,
296313
'application_version' => $this->applicationVersion,
314+
'tracking_uuid' => $this->trackingUuid,
297315
];
298316
}
317+
318+
/*
319+
* Found on https://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid/15875555#15875555
320+
*/
321+
private function generateUuid(): string
322+
{
323+
// Generate 16 bytes (128 bits) of random data or use the data passed into the function.
324+
$data = $data ?? random_bytes(16);
325+
assert(strlen($data) == 16);
326+
327+
// Set version to 0100
328+
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
329+
// Set bits 6-7 to 10
330+
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
331+
332+
// Output the 36 character UUID.
333+
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
334+
}
299335
}

tests/FlareTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ protected function reportError(int $code)
5353
$this->flare->report($throwable);
5454
}
5555

56-
5756
/** @test */
5857
public function it_can_report_an_exception()
5958
{

0 commit comments

Comments
 (0)