-
Notifications
You must be signed in to change notification settings - Fork 199
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
YII2 : cant get traceId in logMessage #1487
Comments
That looks like it should work. Can you confirm that you have an active span at the time that the log was generated? It's important that it's active, since $span = $tracer->spanBuilder('test');
var_dump(Span::getCurrent()->getContext()->getTraceId()); //all 0's
$scope = $span->activate();
var_dump(Span::getCurrent()->getContext()->getTraceId()); //a trace id
$logger->log('test');
$scope->detach();
$span->end(); |
i can get a trace id in controller. But I want to write each traceId to the log, so I implemented |
Looking at Yii's documentation, I think your issue is that logs are collected in memory, then only flushed when a request finishes or the buffer is full.
That means that your code in |
So, How can I write traceId into log with yii2? |
If you're willing to try out auto-instrumentation, our psr-3 auto-instrumentation does what you want: https://github.com/open-telemetry/opentelemetry-php-contrib/blob/main/src/Instrumentation/Psr3/tests/phpt/inject_yii.phpt If you want to know how to do it with your current approach, you might need to ask this question in the yii2 support/help place. The question you need answered is how you can modify a log record immediately, rather than when they are flushed. |
code :
output:
{"timestamp":1737686232.099166,"level":1,"category":"application","message":"test","trace":[{"file":"\/var\/www\/html\/controllers\/SiteController.php","line":68,"function":"error","class":"yii\\BaseYii","type":"::"}],"traceId":"00000000000000000000000000000000","spanId":"0000000000000000"}
why the traceId and spanId is 000000...
The text was updated successfully, but these errors were encountered: