Closed markvdlaan93 closed 2 years ago
Currently, I try to create a single trace with multiple spans. Is this something that is supported at the moment?
Yes, it is. Take a look at this example:
/**
* Create the Tracer
*/
$tracerProvider = new TracerProvider(
new SimpleSpanProcessor(new OtlpHttpExporter),
new AlwaysOnSampler()
);
$tracer = $tracerProvider->getTracer();
/**
* Create some tracing data
*/
echo 'Start Logging ...' . PHP_EOL;
$rootSpan = $tracer->spanBuilder('root')->startSpan();
$rootSpan->activate();
$spans = [];
for ($i = 0; $i < 5; $i++) {
usleep(200000);
$span = $tracer->spanBuilder('log.span' . ($i + 1))->startSpan();
usleep(20000);
$spans[] = $span;
}
$spans = array_reverse($spans);
foreach ($spans as $span) {
usleep(200000);
$span->end();
}
$rootSpan->end();
echo 'Finished!' . PHP_EOL;
Thanks for the example. The crucial thing that I was missing was the order of the end calls. The last child span end must be called first. Quite logical if you think about it but maybe good to add this example somewhere so that it is clear for other how to implement this feature.
Thanks for the report @markvdlaan93 ! Will be happy to merge a PR if you open one adding this example.
@bobstrecansky Okay sure. Somewhere this week, I'll open a PR.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed because it has not had recent activity, but it can be reopened. Thank you for your contributions.
Currently, I try to create a single trace with multiple spans. Is this something that is supported at the moment? I've tried to explicitly call the storeInContext method but that doesn't seem to work. This will create a separate trace per span. My code looks like this: