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

关于sql日志、请求入参、响应数据的记录 #6

Open
adebug opened this issue Jul 31, 2023 · 1 comment
Open

关于sql日志、请求入参、响应数据的记录 #6

adebug opened this issue Jul 31, 2023 · 1 comment

Comments

@adebug
Copy link
Contributor

adebug commented Jul 31, 2023

在实际项目中查看日志,我们不仅要知道入参是什么、响应数据是什么、实际执行的sql是什么样的,因此我在项目中做如下改造,希望官方能参考下。

一、sql日志里未完整呈现实际sql执行的情况:

$contents = "[{$query->time} ms] " . vsprintf(str_replace('?', "'%s'", $query->sql), $query->bindings);
$sqlSpan = $tracer->newChild($rootSpan->getContext());
$sqlSpan->setName(SQL_QUERY . ':' . $query->connectionName);
$sqlSpan->start();
$sqlSpan->tag('db.statement', $contents);
$sqlSpan->finish();

二、需要知道入参是什么:

//记录入参
$paramsSpan = $tracer->newChild($rootSpan->getContext());
$paramsSpan->setName("Request:Params");
$paramsSpan->start();
$paramsSpan->tag('request.params', json_encode($request->all(), JSON_UNESCAPED_UNICODE));
$paramsSpan->finish();

三、需要知道响应数据是什么:

//记录响应内容
$responseSpan = $tracer->newChild($rootSpan->getContext());
$responseSpan->setName("Response:body");
$responseSpan->start();
$responseSpan->tag('response.body', $result->rawBody());
$responseSpan->finish();
@walkor
Copy link
Contributor

walkor commented Jul 31, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants