Skip to content

Commit

Permalink
Add user data to incident reports (#44) (#45)
Browse files Browse the repository at this point in the history
* Add user data to incident reports

* Refactor user data retrieval in README
  • Loading branch information
tvup authored Jul 27, 2024
1 parent a799ae1 commit cc39bea
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"php":"8.3.9","version":"3.60.0:v3.60.0#e595e4e070d17c5d42ed8c4206f630fcc5f401a4","indent":" ","lineEnding":"\n","rules":{"array_syntax":{"syntax":"short"},"blank_line_after_namespace":true,"blank_line_after_opening_tag":true,"braces":true,"cast_spaces":true,"concat_space":{"spacing":"one"},"declare_equal_normalize":true,"elseif":true,"encoding":true,"full_opening_tag":true,"fully_qualified_strict_types":true,"function_declaration":true,"function_typehint_space":true,"heredoc_to_nowdoc":true,"include":true,"increment_style":{"style":"post"},"indentation_type":true,"linebreak_after_opening_tag":true,"line_ending":true,"lowercase_cast":true,"lowercase_keywords":true,"lowercase_static_reference":true,"magic_method_casing":true,"magic_constant_casing":true,"method_argument_space":true,"native_function_casing":true,"no_extra_blank_lines":{"tokens":["extra","throw","use","use_trait"]},"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_closing_tag":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_mixed_echo_print":{"use":"echo"},"no_multiline_whitespace_around_double_arrow":true,"multiline_whitespace_before_semicolons":{"strategy":"no_multi_line"},"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"no_useless_return":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"phpdoc_indent":true,"phpdoc_no_access":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_scalar":true,"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_types":true,"phpdoc_var_without_name":true,"short_scalar_cast":true,"single_blank_line_at_eof":true,"single_blank_line_before_namespace":true,"single_import_per_statement":true,"single_line_after_imports":true,"single_line_comment_style":{"comment_types":["hash"]},"single_quote":true,"space_after_semicolon":true,"standardize_not_equals":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"ternary_operator_spaces":true,"trim_array_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"constant_case":{"case":"lower"},"general_phpdoc_tag_rename":true,"phpdoc_inline_tag_normalizer":true,"phpdoc_tag_type":true,"trailing_comma_in_multiline":{"elements":["arrays"]},"binary_operator_spaces":{"default":"single_space","operators":{"=>":null}},"blank_line_before_statement":{"statements":["return"]},"class_attributes_separation":{"elements":{"const":"one","method":"one","property":"one"}},"class_definition":{"multi_line_extends_each_single_line":true,"single_item_single_line":true,"single_line":true},"ordered_imports":{"sort_algorithm":"alpha"},"no_unneeded_control_parentheses":{"statements":["break","clone","continue","echo_print","return","switch_case","yield"]},"no_spaces_around_offset":{"positions":["inside","outside"]},"visibility_required":{"elements":["property","method","const"]},"no_unused_imports":true},"hashes":{"src\/LaravelFejlvarpServiceProvider.php":"19fe369cd6960c3ad8d83d165ed362c4","src\/Http\/Controllers\/Api\/IncidentController.php":"6dafcdc98cb4c0c9e2653f611c2ff27b","src\/Http\/Controllers\/IncidentController.php":"c14c13a8c0416bf2667c8d14587cce8d","src\/Http\/Requests\/IncidentStoreRequest.php":"e0b96cfc5d90cfabb27d367f43eef821","src\/Http\/Requests\/ApiRequest.php":"7e5c417b68cecb46aed8b1e6b9a99404","src\/Exceptions\/LaravelFejlvarpExceptionHandler.php":"978343aed8cfd23f2c8a52dc51a74326","src\/Incident.php":"7aaddda4539d097f350f8f4d5e020def","src\/LaravelFejlvarp.php":"bc4c671834d59581b772f524cb896bb0","src\/Facades\/LaravelFejlvarp.php":"c79bb7365c831eb5cab20675593432d6","src\/Components\/Ago.php":"3f73676fbcb3200c3d3db540736c00f8","tests\/ExampleTest.php":"3991be89aec886561a4e2d089f261a2a","tests\/TestCase.php":"858f3585ee2e14df08dc659956ef13bc","tests\/Pest.php":"015a8f313bac5fe4743f5a6d3026ba96"}}
{"php":"8.3.9","version":"3.60.0:v3.60.0#e595e4e070d17c5d42ed8c4206f630fcc5f401a4","indent":" ","lineEnding":"\n","rules":{"array_syntax":{"syntax":"short"},"blank_line_after_namespace":true,"blank_line_after_opening_tag":true,"braces":true,"cast_spaces":true,"concat_space":{"spacing":"one"},"declare_equal_normalize":true,"elseif":true,"encoding":true,"full_opening_tag":true,"fully_qualified_strict_types":true,"function_declaration":true,"function_typehint_space":true,"heredoc_to_nowdoc":true,"include":true,"increment_style":{"style":"post"},"indentation_type":true,"linebreak_after_opening_tag":true,"line_ending":true,"lowercase_cast":true,"lowercase_keywords":true,"lowercase_static_reference":true,"magic_method_casing":true,"magic_constant_casing":true,"method_argument_space":true,"native_function_casing":true,"no_extra_blank_lines":{"tokens":["extra","throw","use","use_trait"]},"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_closing_tag":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_mixed_echo_print":{"use":"echo"},"no_multiline_whitespace_around_double_arrow":true,"multiline_whitespace_before_semicolons":{"strategy":"no_multi_line"},"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"no_useless_return":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"phpdoc_indent":true,"phpdoc_no_access":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_scalar":true,"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_types":true,"phpdoc_var_without_name":true,"short_scalar_cast":true,"single_blank_line_at_eof":true,"single_blank_line_before_namespace":true,"single_import_per_statement":true,"single_line_after_imports":true,"single_line_comment_style":{"comment_types":["hash"]},"single_quote":true,"space_after_semicolon":true,"standardize_not_equals":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"ternary_operator_spaces":true,"trim_array_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"constant_case":{"case":"lower"},"general_phpdoc_tag_rename":true,"phpdoc_inline_tag_normalizer":true,"phpdoc_tag_type":true,"trailing_comma_in_multiline":{"elements":["arrays"]},"binary_operator_spaces":{"default":"single_space","operators":{"=>":null}},"blank_line_before_statement":{"statements":["return"]},"class_attributes_separation":{"elements":{"const":"one","method":"one","property":"one"}},"class_definition":{"multi_line_extends_each_single_line":true,"single_item_single_line":true,"single_line":true},"ordered_imports":{"sort_algorithm":"alpha"},"no_unneeded_control_parentheses":{"statements":["break","clone","continue","echo_print","return","switch_case","yield"]},"no_spaces_around_offset":{"positions":["inside","outside"]},"visibility_required":{"elements":["property","method","const"]},"no_unused_imports":true},"hashes":{"src\/LaravelFejlvarpServiceProvider.php":"19fe369cd6960c3ad8d83d165ed362c4","src\/Http\/Controllers\/Api\/IncidentController.php":"2538f615e5511756ff9c5606c2b0664b","src\/Http\/Controllers\/IncidentController.php":"c14c13a8c0416bf2667c8d14587cce8d","src\/Http\/Requests\/IncidentStoreRequest.php":"e0b96cfc5d90cfabb27d367f43eef821","src\/Http\/Requests\/ApiRequest.php":"7e5c417b68cecb46aed8b1e6b9a99404","src\/Exceptions\/LaravelFejlvarpExceptionHandler.php":"b76a18e224604aed6ec57016e2f42a73","src\/Incident.php":"7aaddda4539d097f350f8f4d5e020def","src\/LaravelFejlvarp.php":"bc4c671834d59581b772f524cb896bb0","src\/Facades\/LaravelFejlvarp.php":"c79bb7365c831eb5cab20675593432d6","src\/Components\/Ago.php":"3f73676fbcb3200c3d3db540736c00f8","tests\/ExampleTest.php":"3991be89aec886561a4e2d089f261a2a","tests\/TestCase.php":"858f3585ee2e14df08dc659956ef13bc","tests\/Pest.php":"015a8f313bac5fe4743f5a6d3026ba96"}}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ $hash = config('app.name')
. $exception->getMessage()
. preg_replace('~revisions/[0-9]{14}/~', '--', $exception->getFile())
. $exception->getLine();
$user = request()->user();

$data = [
'hash' => md5($hash),
'subject' => $exception->getMessage() ? $exception->getMessage() : 'Subject is empty',
Expand All @@ -141,6 +143,9 @@ $hash = config('app.name')
'SERVER' => $_SERVER ?: null,
'SESSION' => request()->hasSession() ? request()->session()->all() : null,
],
'application_data' => $user ? [
'user' => $user->toArray(),
] : null,
'queries' => app(Listener::class)->queries(),
], JSON_THROW_ON_ERROR),
];
Expand Down
15 changes: 15 additions & 0 deletions resources/views/incidents/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,21 @@
</table>
@endif

@if(isset($incident->data['application_data']) && isset($incident->data['application_data']['user']))
<h2>Application data - user</h2>
<table class="definitionlist">
<tbody>
@forelse($incident->data['application_data']['user'] as $key => $value)
<tr>
<th>{!! $key !!}</th>
<td>{!! \Illuminate\Support\Str::trim(json_encode($value, JSON_PRETTY_PRINT+JSON_UNESCAPED_SLASHES),'"') !!}</td>
</tr>
@empty
@endforelse
</tbody>
</table>
@endif


@if (isset($incident->data['environment']))
<h2>Request Context</h2>
Expand Down
5 changes: 5 additions & 0 deletions src/Exceptions/LaravelFejlvarpExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ private function fejlvarp_exception_handler(Throwable $exception) : void
. $exception->getMessage()
. preg_replace('~revisions/[0-9]{14}/~', '--', $exception->getFile())
. $exception->getLine();
$user = request()->user();

$data = [
'hash' => md5($hash),
'subject' => $exception->getMessage() ? $exception->getMessage() : 'Subject is empty',
Expand All @@ -71,6 +73,9 @@ private function fejlvarp_exception_handler(Throwable $exception) : void
'SERVER' => $_SERVER ?: null,
'SESSION' => request()->hasSession() ? request()->session()->all() : null,
],
'application_data' => $user ? [
'user' => $user->toArray(),
] : null,
'queries' => app(Listener::class)->queries(),
], JSON_THROW_ON_ERROR),
];
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Api/IncidentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function useragent(Request $request) : Response
'http' => [
'method' => 'GET',
'header' => "Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n" .
"User-Agent: BrobizzApp\r\n" .
'User-Agent: ' . config('app.name') . "\r\n" .
"Accept-Language: en-US,en;q=0.8\r\n" .
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\n",
],
Expand Down

0 comments on commit cc39bea

Please sign in to comment.