apache/skywalking · error · IllegalArgumentException

sourceAttribute() requires exactly one string literal argume

Error message

sourceAttribute() requires exactly one string literal argument, e.g. sourceAttribute("os.name")

What it means

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.

Source

Thrown at oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/v2/compiler/LALValueCodegen.java:767

                throw new IllegalArgumentException(
                    "tag() reads LogData tags but the input type is "
                        + genCtx.inputType.getName()
                        + ". Use a json{}/yaml{}/text{} parser, or access "
                        + "typed fields via parsed.* instead.");
            }
            sb.append("h.tagValue(\"");
            final String key = value.getFunctionCallArgs().get(0)
                .getValue().getSegments().get(0);
            sb.append(DslJavaSourceText.toLiteral(key)).append("\")");
            return;
        }

        // sourceAttribute("KEY") — reads from LogMetadata.sourceAttributes (non-persistent).
        // Available regardless of input type (reads from metadata, not input).
        if ("sourceAttribute".equals(value.getFunctionCallName())) {
            if (value.getFunctionCallArgs().size() != 1
                    || !value.getFunctionCallArgs().get(0).getValue().isStringLiteral()) {
                throw new IllegalArgumentException(
                    "sourceAttribute() requires exactly one string literal argument, "
                        + "e.g. sourceAttribute(\"os.name\")");
            }
            sb.append("h.sourceAttributeValue(\"");
            final String key = value.getFunctionCallArgs().get(0)
                .getValue().getSegments().get(0);
            sb.append(DslJavaSourceText.toLiteral(key)).append("\")");
            return;
        }

        // Handle string/number literals
        if (value.isStringLiteral() && value.getChain().isEmpty()) {
            sb.append("\"").append(DslJavaSourceText.toLiteral(value.getSegments().get(0)))
              .append("\"");
            return;
        }
        if (value.isNumberLiteral() && value.getChain().isEmpty()) {
            final String num = value.getSegments().get(0);

View on GitHub (pinned to 102af09b4a)

Solutions

  1. Pass exactly one double-quoted string literal, e.g. sourceAttribute("os.name")
  2. If the key must be dynamic, read the whole attribute map through a typed input or def chain instead — sourceAttribute cannot take variables
  3. If you meant persistent LogData tags, use tag("KEY") (LogData input only)

Example fix

# before
sourceAttribute(os.name)

# after
sourceAttribute("os.name")
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/skywalking@102af09b4a (2026-08-14). Data as JSON: /api/errors/70f11c3979025733. Report an issue: GitHub.