{"record":{"id":"179ead1247f356d2","repo":"SigNoz/signoz","slug":"couldn-t-extract-log-fields-referenced-in-expr-s","errorCode":null,"errorMessage":"couldn't extract log fields referenced in expr %s: %w","messagePattern":"couldn't extract log fields referenced in expr (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/query-service/app/logparsingpipeline/pipelineBuilder.go","lineNumber":490,"sourceCode":"\t}\n\treturn result\n}\n\nfunc reverseString(s string) string {\n\tr := []rune(s)\n\tfor i := 0; i < len(r)/2; i++ {\n\t\tj := len(s) - 1 - i\n\t\tr[i], r[j] = r[j], r[i]\n\t}\n\treturn string(r)\n}\n\n// Generate expression for checking that all fields referenced in `expr` have a non nil value in log record.\n// Eg: `attributes.x + len(resource.y)` will return the expression `attributes.x != nil && resource.y != nil`\nfunc fieldsReferencedInExprNotNilCheck(expr string) (string, error) {\n\treferencedFields, err := logFieldsReferencedInExpr(expr)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"couldn't extract log fields referenced in expr %s: %w\", expr, err)\n\t}\n\n\t// Generating nil check for deepest fields takes care of their prefixes too.\n\t// Eg: `attributes.test.value + len(attributes.test)` needs a nil check only for `attributes.test.value`\n\tdeepestFieldRefs := []string{}\n\tfor _, field := range referencedFields {\n\t\tisPrefixOfAnotherReferencedField := slices.ContainsFunc(\n\t\t\treferencedFields, func(e string) bool {\n\t\t\t\treturn len(e) > len(field) && strings.HasPrefix(e, field)\n\t\t\t},\n\t\t)\n\t\tif !isPrefixOfAnotherReferencedField {\n\t\t\tdeepestFieldRefs = append(deepestFieldRefs, field)\n\t\t}\n\t}\n\n\tfieldExprChecks := []string{}\n\tfor _, field := range deepestFieldRefs {","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/logparsingpipeline/pipelineBuilder.go#L472-L508","documentation":"For operators carrying an `expr` (e.g. add/group with expressions), the builder extracts all log-field references from the expression to build nil checks. This error means logFieldsReferencedInExpr failed before field extraction — in practice the expression could not be parsed. The pipeline is rejected at prepare time.","triggerScenarios":"An operator with an `expr` containing invalid syntax for the embedded expr language (unbalanced parens, bad operators, unknown functions), e.g. expr \"attributes.a +\" or \"len(resource.\". fieldsReferencedInExprNotNilCheck is called from getOperators and wraps the parse failure.","commonSituations":"Hand-writing expressions without testing them; using SQL/ClickHouse functions not supported by the expr evaluator; version drift in supported expression functions; unescaped quotes inside strings.","solutions":["Fix the expression syntax (balanced parens, supported operators/functions only)","Test the expression standalone with the expr-lang/expr package or in the SigNoz UI preview","Simplify the expression and add complexity back incrementally to isolate the bad token"],"exampleFix":"// before\n{\"type\":\"add\",\"field\":\"attributes.x\",\"value\":\"expr:attributes.a +\"}\n// after\n{\"type\":\"add\",\"field\":\"attributes.x\",\"value\":\"expr:attributes.a + attributes.b\"}","handlingStrategy":"validation","validationCode":"if _, err := expr.Compile(exprStr); err != nil {\n  return fmt.Errorf(\"invalid expr %q: %w\", exprStr, err)\n}","typeGuard":"func isValidExpr(s string) bool { _, err := expr.Compile(s); return err == nil }","tryCatchPattern":"Compile expressions client-side with expr-lang before pipeline submission; report the parser error inline next to the expression editor.","preventionTips":["Use expr.Compile as a lint step in CI for pipeline-as-code","Restrict authors to documented functions","Preview operator output on sample logs"],"tags":["signoz","log-parsingpipeline","expr","expression-parsing"],"backgroundTag":"expression-parse-error","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}