Closed iNviNho closed 1 year ago
Hey @iNviNho,
thanks for the bug report, that function was called with NULL in flushing after a refactor in 0.81.0, causing that issue. We'll add a regression test and fix it.
Thank you @bwoebi
So how should we proceed from our side?
We are tracing in long running CLI command so we start global tracer and close/flush manually after each message we process.
Like this we start the tracing
protected function startDatadogTracing(
string $topicName,
string $traceId = null,
string $parentId = null
): void {
if (!empty($traceId) && !empty($parentId)) {
set_distributed_tracing_context($traceId, $parentId);
}
$tracer = new Tracer();
GlobalTracer::set($tracer);
$resourceName = $topicName . '::process';
$options = ['start_time' => Time::now()];
$rootSpan = $tracer->startRootSpan(
'Jobs',
$options
)
->getSpan();
$rootSpan->setTag(Tag::SPAN_TYPE, Type::CLI);
$rootSpan->setTag(Tag::SERVICE_NAME, 'broker.offer-service');
$rootSpan->setTag(Tag::RESOURCE_NAME, $resourceName, true);
$rootSpan->setTag('command_origin', $this->signature);
// set up tracing ...
}
Like this we send traces
GlobalTracer::get()->getRootScope()?->close();
GlobalTracer::get()->flush();
Thank you for your fast reaction.
Currently DDTrace\flush() with DD_AUTOFINISH_SPANS=1 is completely broken.
An equivalent would be:
ini_set("datadog.autofinish_spans", 0);
DDTrace\close_spans_until(null);
GlobalTracer::get()->flush();
ini_set("datadog.autofinish_spans", 1);
If you want to generally use autofinish functionality.
Does DD_AUTOFINISH_SPANS=1 mean SDK automatically closes global/root span?
Can we set DD_AUTOFINISH_SPANS=0 in Dockerfile for all the commands? Indeed we do close manually all global spans before we flush them.
We do
Yes, it means that it will automagically close spans, which happen to not be closed manually - otherwise you may lose unclosed spans.
If you do not need that feature, just turn it off altogether :-)
Just for my understanding...
Why would spans not be closed automatically?
If I define tracing a method of a class like this
trace_method(Producer::class, 'produce', function (SpanData $span) {
$span->service = 'broker.offer-service.kafka';
});
Doesn't SDK start span right before this method is called and close span right after the execution?
It's just about manually started spans, automatic root spans and tracing spans are always automatically properly started and closed.
Thank you for your help.
Setting DD_AUTOFINISH_SPANS=false
did the trick :)
@iNviNho And now 0.84.0 is out, and you can revert to DD_AUTOFINISH_SPANS=true
again :-)
Bug description
Hi,
When calling
in our Laravel commands, the application fails with
This is how we install the datadog-php-trace.php
PHP version
Tracer version
Installed extensions
OS info
Diagnostics and configuration
Output of phpinfo() (ddtrace >= 0.47.0)
Output from Valgrind
Upgrading info
We encountered this issue after upgrading from 0.73.0 to 0.83.1.