{"record":{"id":"70f11c3979025733","repo":"apache/skywalking","slug":"sourceattribute-requires-exactly-one-string-lite","errorCode":null,"errorMessage":"sourceAttribute() requires exactly one string literal argument, e.g. sourceAttribute(\"os.name\")","messagePattern":"sourceAttribute\\(\\) requires exactly one string literal argument, e\\.g\\. sourceAttribute\\(\"os\\.name\"\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/v2/compiler/LALValueCodegen.java","lineNumber":767,"sourceCode":"                throw new IllegalArgumentException(\n                    \"tag() reads LogData tags but the input type is \"\n                        + genCtx.inputType.getName()\n                        + \". Use a json{}/yaml{}/text{} parser, or access \"\n                        + \"typed fields via parsed.* instead.\");\n            }\n            sb.append(\"h.tagValue(\\\"\");\n            final String key = value.getFunctionCallArgs().get(0)\n                .getValue().getSegments().get(0);\n            sb.append(DslJavaSourceText.toLiteral(key)).append(\"\\\")\");\n            return;\n        }\n\n        // sourceAttribute(\"KEY\") — reads from LogMetadata.sourceAttributes (non-persistent).\n        // Available regardless of input type (reads from metadata, not input).\n        if (\"sourceAttribute\".equals(value.getFunctionCallName())) {\n            if (value.getFunctionCallArgs().size() != 1\n                    || !value.getFunctionCallArgs().get(0).getValue().isStringLiteral()) {\n                throw new IllegalArgumentException(\n                    \"sourceAttribute() requires exactly one string literal argument, \"\n                        + \"e.g. sourceAttribute(\\\"os.name\\\")\");\n            }\n            sb.append(\"h.sourceAttributeValue(\\\"\");\n            final String key = value.getFunctionCallArgs().get(0)\n                .getValue().getSegments().get(0);\n            sb.append(DslJavaSourceText.toLiteral(key)).append(\"\\\")\");\n            return;\n        }\n\n        // Handle string/number literals\n        if (value.isStringLiteral() && value.getChain().isEmpty()) {\n            sb.append(\"\\\"\").append(DslJavaSourceText.toLiteral(value.getSegments().get(0)))\n              .append(\"\\\"\");\n            return;\n        }\n        if (value.isNumberLiteral() && value.getChain().isEmpty()) {\n            final String num = value.getSegments().get(0);","sourceCodeStart":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/apache/skywalking/blob/102af09b4a56064e22050dded10e2c52e490d040/oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/v2/compiler/LALValueCodegen.java#L749-L785","documentation":"Thrown at LAL compile time when sourceAttribute(...) is called with zero arguments, more than one argument, or a non-literal (variable/expression) argument. sourceAttribute(key) reads non-persistent attributes from LogMetadata.sourceAttributes and the codegen embeds the key as a string literal into the generated Java source, so the key must be a compile-time string literal.","triggerScenarios":"sourceAttribute() with no args; sourceAttribute(\"a\", \"b\") with two args; sourceAttribute(someVar) or sourceAttribute(parsed.key) where the argument is not a plain quoted string.","commonSituations":"Trying to parametrize the attribute key from parsed data; copy-paste from tag() usage leaving a mismatched arity; a typo like sourceAttribute(os.name) without quotes.","solutions":["Pass exactly one double-quoted string literal, e.g. sourceAttribute(\"os.name\")","If the key must be dynamic, read the whole attribute map through a typed input or def chain instead — sourceAttribute cannot take variables","If you meant persistent LogData tags, use tag(\"KEY\") (LogData input only)"],"exampleFix":"# before\nsourceAttribute(os.name)\n\n# after\nsourceAttribute(\"os.name\")","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always quote sourceAttribute keys as string literals","Pass exactly one argument","Remember dynamic keys are unsupported by design — restructure the rule instead"],"tags":["lal","log-analyzer","compiler","arguments"],"backgroundTag":null,"analyzedSha":"102af09b4a56064e22050dded10e2c52e490d040","analyzedAt":"2026-08-14T10:47:52.647Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}