更新
This commit is contained in:
@@ -969,7 +969,8 @@ class DiagnosisController extends BaseAdminController
|
||||
$profile = (string) $metadata['model_key'];
|
||||
$emit = $this->openAssistantSse();
|
||||
$sseStartedAt = hrtime(true);
|
||||
$started = $emit('start', $metadata + ['request_id' => $requestId, 'message' => '已连接,正在整理资料']);
|
||||
$started = $emit('start', $metadata + ['request_id' => $requestId,
|
||||
'trace_id' => $timing->id(), 'message' => '已连接,正在整理资料']);
|
||||
$timing->log('sse_start', ['status' => $started ? 'ok' : 'disconnected']);
|
||||
return true;
|
||||
},
|
||||
|
||||
@@ -533,6 +533,13 @@ class DiagnosisAiLogic extends BaseLogic
|
||||
$retryMs = 0;
|
||||
$status = 'error';
|
||||
$upstreamStartedAt = hrtime(true);
|
||||
if ($timing !== null) {
|
||||
$priorObserver = $options['on_upstream_timing'] ?? null;
|
||||
$options['on_upstream_timing'] = static function (\app\common\service\DifyStreamTiming $stages) use ($timing, $priorObserver): void {
|
||||
$timing->logUpstream($stages);
|
||||
if (is_callable($priorObserver)) $priorObserver($stages);
|
||||
};
|
||||
}
|
||||
$forwardDelta = static function (string $delta) use (&$deliveredDelta, &$deltaCount, &$deltaBytes, $onDelta) {
|
||||
$accepted = $onDelta($delta);
|
||||
if ($accepted !== false) {
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\adminapi\service;
|
||||
|
||||
use app\common\service\DifyStreamTiming;
|
||||
use think\facade\Log;
|
||||
|
||||
/** A request-local, patient-free timing record for the diagnosis assistant SSE path. */
|
||||
@@ -91,4 +92,15 @@ final class AssistantSseTiming
|
||||
// Telemetry must never interrupt the clinical request.
|
||||
}
|
||||
}
|
||||
|
||||
/** The typed collector exposes only bounded numeric timing and enum metadata. */
|
||||
public function logUpstream(DifyStreamTiming $upstream): void
|
||||
{
|
||||
try {
|
||||
Log::write('diagnosis ai upstream stages ' . json_encode([
|
||||
'trace_id' => $this->traceId, 'request_elapsed_ms' => self::elapsedMs($this->startedAt),
|
||||
'timing' => $upstream->snapshot(),
|
||||
]), 'info');
|
||||
} catch (\Throwable $ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user