@@ -106,7 +106,7 @@ func Middleware(logger LoggerInterface) echo.MiddlewareFunc {
106106 // Execute the handler
107107 err := next (c )
108108
109- applyRequestModelResolution (entry , c .Request ().Context ())
109+ applyExecutionPlan (entry , c .Request ().Context ())
110110
111111 // Calculate duration
112112 entry .DurationNs = time .Since (start ).Nanoseconds ()
@@ -156,34 +156,35 @@ func Middleware(logger LoggerInterface) echo.MiddlewareFunc {
156156 }
157157}
158158
159- func applyRequestModelResolution (entry * LogEntry , ctx context.Context ) {
159+ func applyExecutionPlan (entry * LogEntry , ctx context.Context ) {
160160 if entry == nil || ctx == nil {
161161 return
162162 }
163163
164- resolution := core .GetRequestModelResolution (ctx )
165- if resolution == nil {
166- return
164+ if plan := core .GetExecutionPlan (ctx ); plan != nil {
165+ enrichEntryWithExecutionPlan (entry , plan )
167166 }
168-
169- enrichEntryWithResolution (entry , resolution )
170167}
171168
172- func enrichEntryWithResolution (entry * LogEntry , resolution * core.RequestModelResolution ) {
173- if entry == nil || resolution == nil {
169+ func enrichEntryWithExecutionPlan (entry * LogEntry , plan * core.ExecutionPlan ) {
170+ if entry == nil || plan == nil {
174171 return
175172 }
176173
177- if requestedModel := resolution .RequestedQualifiedModel (); requestedModel != "" {
174+ if requestedModel := plan .RequestedQualifiedModel (); requestedModel != "" {
178175 entry .Model = requestedModel
179176 }
180- if resolvedModel := resolution .ResolvedQualifiedModel (); resolvedModel != "" {
177+ if resolvedModel := plan .ResolvedQualifiedModel (); resolvedModel != "" {
181178 entry .ResolvedModel = resolvedModel
182179 }
183- if strings .TrimSpace (resolution .ProviderType ) != "" {
184- entry .Provider = strings .TrimSpace (resolution .ProviderType )
180+ if providerType := strings .TrimSpace (plan .ProviderType ); providerType != "" {
181+ entry .Provider = providerType
182+ } else if plan .Resolution != nil && strings .TrimSpace (plan .Resolution .ProviderType ) != "" {
183+ entry .Provider = strings .TrimSpace (plan .Resolution .ProviderType )
184+ }
185+ if plan .Resolution != nil {
186+ entry .AliasUsed = plan .Resolution .AliasApplied
185187 }
186- entry .AliasUsed = resolution .AliasApplied
187188}
188189
189190func captureRequestBodyForLogging (entry * LogEntry , req * http.Request ) {
@@ -336,9 +337,10 @@ func EnrichEntry(c *echo.Context, model, provider string) {
336337 entry .Provider = provider
337338}
338339
339- // EnrichEntryWithResolution attaches resolved model and alias metadata to the live audit entry.
340- // This is used before handler execution completes so streaming audit entries inherit the same data.
341- func EnrichEntryWithResolution (c * echo.Context , resolution * core.RequestModelResolution ) {
340+ // EnrichEntryWithExecutionPlan attaches execution-plan metadata to the live
341+ // audit entry. This is preferred over resolution-only enrichment once planning
342+ // has completed for the request.
343+ func EnrichEntryWithExecutionPlan (c * echo.Context , plan * core.ExecutionPlan ) {
342344 entryVal := c .Get (string (LogEntryKey ))
343345 if entryVal == nil {
344346 return
@@ -349,7 +351,7 @@ func EnrichEntryWithResolution(c *echo.Context, resolution *core.RequestModelRes
349351 return
350352 }
351353
352- enrichEntryWithResolution (entry , resolution )
354+ enrichEntryWithExecutionPlan (entry , plan )
353355}
354356
355357// EnrichEntryWithError adds error information to the log entry.
0 commit comments