{"record":{"id":"7fef98d47d4ce178","repo":"SigNoz/signoz","slug":"max-spans-allowed-in-trace-limit-reached-please-c","errorCode":null,"errorMessage":"max spans allowed in trace limit reached, please contact support for more details","messagePattern":"max spans allowed in trace limit reached, please contact support for more details","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/query-service/app/clickhouseReader/reader.go","lineNumber":5283,"sourceCode":"\t\t\tIsSubTree: false,\n\t\t\tEvents:    make([][]interface{}, 0),\n\t\t},\n\t}\n\n\tvar traceSummary model.TraceSummary\n\tsummaryQuery := fmt.Sprintf(\"SELECT trace_id, min(start) AS start, max(end) AS end, sum(num_spans) AS num_spans FROM %s.%s WHERE trace_id=$1 GROUP BY trace_id\", r.TraceDB, r.traceSummaryTable)\n\terr := r.db.QueryRow(ctx, summaryQuery, params.TraceID).Scan(&traceSummary.TraceID, &traceSummary.Start, &traceSummary.End, &traceSummary.NumSpans)\n\tif err != nil {\n\t\tif err == sql.ErrNoRows {\n\t\t\treturn &searchSpansResult, nil\n\t\t}\n\t\tr.logger.Error(\"Error in processing sql query\", errorsV2.Attr(err))\n\t\treturn nil, fmt.Errorf(\"error in processing sql query\")\n\t}\n\n\tif traceSummary.NumSpans > uint64(params.MaxSpansInTrace) {\n\t\tr.logger.Error(\"Max spans allowed in a trace limit reached\", \"MaxSpansInTrace\", params.MaxSpansInTrace, \"Count\", traceSummary.NumSpans)\n\t\treturn nil, fmt.Errorf(\"max spans allowed in trace limit reached, please contact support for more details\")\n\t}\n\n\tvar startTime, endTime, durationNano uint64\n\tvar searchScanResponses []model.SpanItemV2\n\n\tquery := fmt.Sprintf(\"SELECT timestamp, duration_nano, span_id, trace_id, has_error, kind, resource_string_service$$name, name, links as references, attributes_string, attributes_number, attributes_bool, resources_string, events, status_message, status_code_string, kind_string FROM %s.%s WHERE trace_id=$1 and ts_bucket_start>=$2 and ts_bucket_start<=$3\", r.TraceDB, r.traceTableName)\n\terr = r.db.Select(ctx, &searchScanResponses, query, params.TraceID, strconv.FormatInt(traceSummary.Start.Unix()-1800, 10), strconv.FormatInt(traceSummary.End.Unix(), 10))\n\tif err != nil {\n\t\tr.logger.Error(\"Error in processing sql query\", errorsV2.Attr(err))\n\t\treturn nil, fmt.Errorf(\"error in processing sql query\")\n\t}\n\n\tsearchSpansResult[0].Events = make([][]interface{}, len(searchScanResponses))\n\n\tsearchSpanResponses := []model.SearchSpanResponseItem{}\n\n\tfor _, item := range searchScanResponses {\n\t\tref := []model.OtelSpanRef{}","sourceCodeStart":5265,"sourceCodeEnd":5301,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/clickhouseReader/reader.go#L5265-L5301","documentation":"SearchTraces refuses to return a trace whose span count (traceSummary.NumSpans) exceeds params.MaxSpansInTrace. This is a protective limit so the UI/backend does not explode rendering or fetching gigantic traces.","triggerScenarios":"GET /api/v1/traces/{traceID} (SearchTraces) where the trace has more spans than MaxSpansInTrace — e.g. a trace with hundreds of thousands of spans from a hot loop, recursive service calls, or an instrumentation bug creating excessive spans.","commonSituations":"Microservice recursion or retry storms producing huge traces, missing sampling rules so every request is recorded, or MaxSpansInTrace set too low in query-service config.","solutions":["Raise MaxSpansInTrace in the query-service configuration if genuinely need the full trace","Apply tail/head sampling to reduce span volume at the collector","Find and fix the service generating excessive spans (recursion, tight-loop spans, unbatched work)","View the trace summary or a filtered subset instead of the full trace"],"exampleFix":"// before\nif traceSummary.NumSpans > uint64(params.MaxSpansInTrace) {\n    return nil, fmt.Errorf(\"max spans allowed in trace limit reached, please contact support for more details\")\n}\n\n// after (honour a client limit param with a clear message)\nif traceSummary.NumSpans > uint64(params.MaxSpansInTrace) {\n    return nil, fmt.Errorf(\"trace has %d spans which exceeds the maximum of %d; narrow the time range or raise MaxSpansInTrace\", traceSummary.NumSpans, params.MaxSpansInTrace)\n}","handlingStrategy":"validation","validationCode":"// Fetch the summary first and check size before requesting full trace\nsummary, _ := getTraceSummary(traceID)\nif summary.NumSpans > uint64(maxSpans) {\n    return fmt.Errorf(\"trace too large (%d spans) to render; use sampling or summary view\", summary.NumSpans)\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"max spans allowed in trace limit reached\") {\n        // show summary UI instead of failing hard\n        renderTraceSummary(traceID)\n        return\n    }\n    return err\n}","preventionTips":["Configure collector sampling to cap spans per trace","Set MaxSpansInTrace appropriate to your UI capacity","Instrument high-span services with coarser spans"],"tags":["traces","limit","span-count","signoz"],"backgroundTag":"result-size-limit-exceeded","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}