@@ -966,6 +966,7 @@ func (h *PreHandler) handleOperation(req *http.Request, variablesParser *astjson
966966 if ! requestContext .operation .traceOptions .ExcludePlannerStats {
967967 httpOperation .traceTimings .StartPlanning ()
968968 }
969+
969970 startPlanning := time .Now ()
970971
971972 _ , enginePlanSpan := h .tracer .Start (req .Context (), "Operation - Plan" ,
@@ -984,22 +985,26 @@ func (h *PreHandler) handleOperation(req *http.Request, variablesParser *astjson
984985 err = h .planner .plan (requestContext .operation , planOptions )
985986 if err != nil {
986987 httpOperation .requestLogger .Debug ("failed to plan operation" , zap .Error (err ))
987- rtrace .AttachErrToSpan (enginePlanSpan , err )
988988
989989 if ! requestContext .operation .traceOptions .ExcludePlannerStats {
990990 httpOperation .traceTimings .EndPlanning ()
991991 }
992992
993+ requestContext .operation .planningTime = time .Since (startPlanning )
994+
995+ rtrace .AttachErrToSpan (enginePlanSpan , err )
993996 enginePlanSpan .End ()
994997
995998 return err
996999 }
9971000
998- enginePlanSpan .SetAttributes (otel .WgEnginePlanCacheHit .Bool (requestContext .operation .planCacheHit ))
1001+ if ! requestContext .operation .traceOptions .ExcludePlannerStats {
1002+ httpOperation .traceTimings .EndPlanning ()
1003+ }
9991004
10001005 requestContext .operation .planningTime = time .Since (startPlanning )
1001- httpOperation .traceTimings .EndPlanning ()
10021006
1007+ enginePlanSpan .SetAttributes (otel .WgEnginePlanCacheHit .Bool (requestContext .operation .planCacheHit ))
10031008 enginePlanSpan .End ()
10041009
10051010 planningAttrs := * requestContext .telemetry .AcquireAttributes ()
@@ -1015,6 +1020,17 @@ func (h *PreHandler) handleOperation(req *http.Request, variablesParser *astjson
10151020
10161021 requestContext .telemetry .ReleaseAttributes (& planningAttrs )
10171022
1023+ if requestContext .operation .planningTime > 4 * time .Second {
1024+ h .log .Warn ("Planning time exceeded threshold" ,
1025+ zap .Duration ("planning_time" , requestContext .operation .planningTime ),
1026+ zap .String ("operation_id" , requestContext .operation .name ),
1027+ zap .String ("operation_type" , requestContext .operation .opType ),
1028+ zap .String ("operation_client" , requestContext .operation .clientInfo .Name ),
1029+ zap .String ("operation_client_version" , requestContext .operation .clientInfo .Version ),
1030+ zap .String ("operation_content" , requestContext .operation .content ),
1031+ )
1032+ }
1033+
10181034 // we could log the query plan only if query plans are calculated
10191035 if (h .queryPlansEnabled && requestContext .operation .executionOptions .IncludeQueryPlanInResponse ) ||
10201036 h .alwaysIncludeQueryPlan {
0 commit comments