Skip to content

"Type safety"#21

Merged
erickhun merged 3 commits into
masterfrom
task/type-safe
Mar 11, 2020
Merged

"Type safety"#21
erickhun merged 3 commits into
masterfrom
task/type-safe

Conversation

@erickhun

Copy link
Copy Markdown
Contributor

We got few incidents when passing the wrong type of parameters. Since it makes the PHP erroring out and make a full service stop, I simply output an error message instead of stopping the script execution.

I was thinking to use the type-hint but since we use the magic function call_user_func_array i'm not too sure how to do it altogether.

@colinscape up for a review?

@erickhun erickhun requested review from colinscape and esclapes March 10, 2020 13:14

@colinscape colinscape left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wonder if we will end up 'losing' these logs which go to error_log.

What would you think about re-packaging the malformed arguments and flagging them with something like malformed: true so we could detect them?

For example, if the arguments don't satisfy the conditions in checkLogParametersType() we could instead call BuffLog with something like BuffLog::warning('Malformed BuffLog request', ['malformed' = true, 'args' => $args]); We would need to be careful of not creating an infinite loop, admittedly! 😅

@erickhun

Copy link
Copy Markdown
Contributor Author

@colinscape fantastic idea, I like it. and with that we could also monitor how engineers don't use the library correctly .
I'va made your changes suggested with 9678047 . Added the ["bufflog_error" => "XXXX"] fields, so we could follow how and how often the library being missused

Comment thread src/BuffLog/BuffLog.php
Comment on lines +48 to +53
echo json_encode([
"message" => "Can't find \DDTrace\GlobalTracer class. Did you install the Datadog APM tracer extension? It will allow you to have logs enriched with traces making troubleshooting easier. If you run a cli mode service (such as a worker), did you set the DD_TRACE_CLI_ENABLED env variable?",
"level" => 300,
"level_name" => "WARNING",
"context" => ["bufflog_error" => "no_tracer"]
]);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the logger isn't ready yet, we have to do this manually

@erickhun erickhun merged commit 45f8fb1 into master Mar 11, 2020
@erickhun erickhun deleted the task/type-safe branch March 11, 2020 03:19

@colinscape colinscape left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good @erickhun - I left a couple more thoughts for improvements/enhancements that you could potentially consider. 😀

Comment thread example.php
Comment thread composer.json
@erickhun erickhun mentioned this pull request Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants