// Get the parent span$parentSpan = $span->parent();// Get child spans$childSpans = $span->children();// Get all spans in the same trace$traceSpans = $span->traceSpans();
// Check if span is completedif ($span->isCompleted()) { echo "Span finished in " . $span->duration_ms . "ms";}// Check if span has errorif ($span->hasError()) { echo "Error: " . $span->error_message;}// Check if root spanif ($span->isRoot()) { echo "This is the root span";}// Get formatted durationecho $span->getFormattedDuration(); // "125ms" or "1.5s"// Get status iconecho $span->getStatusIcon(); // Check, X, or spinner icon// Get type iconecho $span->getTypeIcon(); // Robot, brain, wrench, or users icon// Get summaryecho $span->getSummary(); // "llm_call: gpt-4 - 1.2s (success)"
// Create a new trace$traceId = $tracer->createTrace( sessionId: $context->getSessionId(), agentName: 'customer_support');// Set current trace context$tracer->setCurrentTrace($traceId);// Get current trace ID$currentTraceId = $tracer->getCurrentTraceId();
// Get count of old traces$count = $tracer->getOldTracesCount(30); // 30 days// Clean up old traces with progress callback$deleted = $tracer->cleanupOldTraces(30, function($batchCount) { echo "Deleted {$batchCount} traces...\n";});
// Get all errors for a session$errors = TraceSpan::forSession($sessionId) ->withStatus('error') ->with('parent') ->get();foreach ($errors as $error) { echo "Error in {$error->name}: {$error->error_message}\n"; // Show parent context if ($error->parent) { echo " Parent: {$error->parent->name}\n"; }}