{"record":{"id":"f29025ef369727cf","repo":"jaegertracing/jaeger","slug":"search-depth-d-exceeds-maximum-allowed-d","errorCode":null,"errorMessage":"search depth %d exceeds maximum allowed %d","messagePattern":"search depth (.+?) exceeds maximum allowed (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/v2/clickhouse/tracestore/query_builder.go","lineNumber":131,"sourceCode":"\treturn q.String(), args\n}\n\nfunc buildFindTracesQuery(traceIDsQuery string) string {\n\tinner := indentBlock(\"SELECT trace_id FROM (\\n\" + indentBlock(strings.TrimSpace(traceIDsQuery)) + \"\\n)\")\n\tbase := strings.TrimRight(sql.SelectSpansQuery, \"\\n\")\n\treturn base + \"\\nWHERE s.trace_id IN (\\n\" + inner + \"\\n)\\nORDER BY s.trace_id\"\n}\n\nfunc (r *Reader) buildFindTraceIDsQuery(\n\tctx context.Context,\n\tquery tracestore.TraceQueryParams,\n) (string, []any, error) {\n\tlimit := query.SearchDepth\n\tif limit == 0 {\n\t\tlimit = r.config.DefaultSearchDepth\n\t}\n\tif limit > r.config.MaxSearchDepth {\n\t\treturn \"\", nil, fmt.Errorf(\"search depth %d exceeds maximum allowed %d\", limit, r.config.MaxSearchDepth)\n\t}\n\n\t// Build the inner subquery that finds distinct trace IDs from spans.\n\tvar inner strings.Builder\n\tinner.WriteString(sql.SearchTraceIDsBase)\n\targs := []any{}\n\n\tif query.ServiceName != \"\" {\n\t\tappendAnd(&inner, \"s.service_name = ?\")\n\t\targs = append(args, query.ServiceName)\n\t}\n\tif query.OperationName != \"\" {\n\t\tappendAnd(&inner, \"s.name = ?\")\n\t\targs = append(args, query.OperationName)\n\t}\n\tif query.DurationMin > 0 {\n\t\tappendAnd(&inner, \"s.duration >= ?\")\n\t\targs = append(args, query.DurationMin.Nanoseconds())","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/internal/storage/v2/clickhouse/tracestore/query_builder.go#L113-L149","documentation":"buildFindTraceIDsQuery validates the requested search depth against the repository's MaxSearchDepth configuration before constructing the trace-ID lookup SQL. The search depth caps how many spans are scanned per trace during the search, and requests beyond the configured ceiling are rejected.","triggerScenarios":"Calling the query builder (via FindTraceIDs) with a query whose SearchDepth is larger than the configured MaxSearchDepth, or a non-zero SearchDepth supplied by a client that exceeds the server's limit.","commonSituations":"A client hard-coding a large search depth while the ClickHouse store was configured with a conservative MaxSearchDepth; config drift between services sharing one storage backend.","solutions":["Lower the query's SearchDepth to at most MaxSearchDepth","Leave SearchDepth at 0 so the configured DefaultSearchDepth is used","Raise MaxSearchDepth in the storage configuration if deep searches are legitimate","Align client and server search-depth settings"],"exampleFix":"// before\nquery.SearchDepth = 500 // exceeds MaxSearchDepth=100\n// after\nquery.SearchDepth = 0 // use server DefaultSearchDepth\n// or raise config:\n// config.MaxSearchDepth = 500","handlingStrategy":"validation","validationCode":"if query.SearchDepth > repo.Config().MaxSearchDepth {\n    query.SearchDepth = repo.Config().MaxSearchDepth\n}\nif query.SearchDepth == 0 {\n    query.SearchDepth = repo.Config().DefaultSearchDepth\n}","typeGuard":null,"tryCatchPattern":"traceIDs, err := store.FindTraceIDs(ctx, query)\nvar depthErr error\nif errors.As(err, &depthErr) && strings.Contains(err.Error(), \"exceeds maximum allowed\") {\n    query.SearchDepth = 0 // fall back to default\n    traceIDs, err = store.FindTraceIDs(ctx, query)\n}","preventionTips":["Leave SearchDepth unset (0) unless deep search is required","Read MaxSearchDepth from config before setting SearchDepth","Keep client and server search-depth configs aligned"],"tags":["clickhouse","configuration","query-builder","validation"],"backgroundTag":"parameter-limit-exceeded","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}