Skip to content

Commit

Permalink
fix: update to handle null context just in case
Browse files Browse the repository at this point in the history
  • Loading branch information
df-wg committed Nov 28, 2024
1 parent 6e2027b commit 2e8954d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions router/core/engine_loader_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,24 @@ func (f *engineLoaderHooks) OnHttpFinished(ctx context.Context, ds resolve.DataS
return
}

hookCtx, ok := ctx.Value(engineLoaderHooksContextKey).(*engineLoaderHooksRequestContext)
if !ok {
return
}

latency := time.Since(hookCtx.startTime)
if f.accessLogger != nil {
fields := []zap.Field{
zap.String("subgraph_name", ds.Name),
zap.String("subgraph_id", ds.ID),
zap.Int("status", response.StatusCode),
zap.Duration("latency", latency),
}
if err != nil {
fields = append(fields, zap.Any("error", err))
}
if ctx != nil {
hookCtx, ok := ctx.Value(engineLoaderHooksContextKey).(*engineLoaderHooksRequestContext)
if !ok {
return
}

latency := time.Since(hookCtx.startTime)
fields = append(fields, zap.Duration("latency", latency))
}

f.accessLogger.WriteRequestLog(request, response, fields)
}
Expand Down

0 comments on commit 2e8954d

Please sign in to comment.