EDXCode Troubleshooting

Common issues and solutions when using edx_code.

edx_code Statements Not Executing

Symptoms: Fields are not being created or modified

Common causes:

  • edx_code not placed in a sequence multiprocessor
  • OTTL syntax errors preventing statement execution
  • Field paths incorrect (check body vs attributes)
  • Agent version older than v2.6.0

Debug steps:

  1. Verify agent version: kubectl logs <edgedelta-pod> | grep version
  2. Check for OTTL validation errors in agent logs
  3. Add a simple test: edx_code("item['attributes']['debug'] = 'test';")
  4. Verify field appears in destination output

Syntax Errors

Symptoms: Configuration validation fails with JavaScript compilation error

This is expected behavior: Edge Delta’s validation system catches JavaScript syntax errors at configuration time, before deployment. This prevents invalid code from reaching production agents.

Common causes:

  • Missing semicolons in JavaScript code
  • Unmatched quotes or braces
  • Invalid JavaScript syntax
  • YAML escaping issues

Example validation error:

processors.0.statements statement: 'edx_code("item['attributes']['test'] = ;")'
is not valid, err: couldn't create function: failed to create EDXCodeFunc for javascript:
JavaScript compilation failed: SyntaxError: (anonymous): Line 7:34 Unexpected token ;

Solutions:

# Bad - missing semicolon (validation will reject)
edx_code("item['attributes']['x'] = 1")

# Good - semicolon present
edx_code("item['attributes']['x'] = 1;")

# Bad - unescaped quotes (validation will reject)
edx_code("item['attributes']['msg'] = "hello"")

# Good - proper escaping
edx_code("item['attributes']['msg'] = 'hello';")

Both CLI and GUI validation consistently prevent deployment of syntax-invalid JavaScript. This is a security feature that protects production environments.

Quote Escaping Issues

Symptoms: Escaped quotes not appearing correctly in output, backslashes behaving unexpectedly

Common escaping patterns:

Basic Escaping (Works Reliably)

# Single escaped quote - works as expected
edx_code("item['attributes']['msg'] = 'She said \"yes\" to the offer';")
# Output: She said "yes" to the offer

# Single backslash - standard behavior
edx_code("item['attributes']['path'] = 'C:\\Users\\test';")
# Output: C:\Users\test

# Quotes in concatenation - works correctly
edx_code("item['attributes']['quoted'] = 'The \"' + item['attributes']['name'] + '\" value';")
# Output: The "value" value

Complex Escaping (Use with Caution)

# Triple backslashes - loses one escape level
edx_code("item['attributes']['json'] = '{\"key\":\"value with \\\"quotes\\\"\"}';")
# Expected: {"key":"value with \"quotes\""}
# Actual:   {"key":"value with "quotes""}

# Quad backslashes - becomes double instead of single
edx_code("item['attributes']['path'] = 'C\\\\Users\\\\test';")
# Expected: C:\Users\test
# Actual:   C:\\Users\\test

Best practices:

  1. Use single-level escaping (\" or \\) for predictable behavior
  2. Test complex nested escaping thoroughly before production
  3. Consider using template literals for readability: `value with "quotes"`
  4. When embedding JSON, build it with JSON.stringify() instead of manual escaping

Field Type Mismatches

Symptoms: Numeric operations failing or producing unexpected results

Solution: Convert types explicitly before edx_code:

set(attributes["numeric_id"], Int(body["id"]))
edx_code("item['attributes']['doubled'] = item['attributes']['numeric_id'] * 2;")

Runtime Errors

Note: Runtime error handling (accessing undefined properties, type mismatches, infinite loops) behavior may vary and is under active development.

Best practices for runtime errors:

  1. Validate all field paths exist before accessing
  2. Use null-safe patterns: if (item['attributes']['field']) { ... }
  3. Add type checks: if (typeof item['attributes']['value'] === 'number') { ... }
  4. Test with small data volumes first
  5. Monitor agent and destination logs for error patterns

Report any unexpected runtime error behavior to Edge Delta support for investigation.

Performance Degradation

Symptoms: Increased latency or reduced throughput

Solutions:

  • Move simple operations to native OTTL
  • Reduce edx_code complexity
  • Batch multiple field updates into single edx_code call
  • Monitor CPU usage and adjust processing parallelism

Variables Not Available Across Calls

Symptoms: Variable undefined error in second edx_code call

Cause: Variables declared with const or let in one edx_code call are not accessible to subsequent calls.

Solution: Store values in attributes or use globalThis:

// ❌ This will NOT work
edx_code("const myVar = 10;")
edx_code("item['attributes']['result'] = myVar * 2;")  // Error: myVar is undefined

// ✅ Store in attributes
edx_code("item['attributes']['myVar'] = 10;")
edx_code("item['attributes']['result'] = item['attributes']['myVar'] * 2;")

// ✅ Or use globalThis (persists across all events)
edx_code("globalThis.myVar = 10;")
edx_code("item['attributes']['result'] = globalThis.myVar * 2;")

Unexpected Global State Behavior

Symptoms: Counters incrementing across different log entries, values persisting unexpectedly

Cause: globalThis persists state across all edx_code executions within the same agent process.

This is current behavior in v2.6.0: Global state is intentionally or incidentally persistent.

Considerations:

  • Global state is per-agent-pod, not synchronized across replicas
  • State is lost on agent restart
  • Use this behavior intentionally for counters, caching, or deduplication
  • Be aware of unintended side effects if you don’t want persistence

See JavaScript Sandbox - Global State Behavior for more details.

Agent Version Issues

Symptoms: edx_code function not recognized

Solution: Verify agent version is v2.6.0 or later:

kubectl logs <edgedelta-pod> | grep version

If version is older, upgrade the agent to v2.6.0+ to use edx_code.

Getting Help

If you encounter issues not covered here:

  1. Check agent logs for detailed error messages
  2. Verify your pipeline configuration syntax
  3. Test with simplified edx_code statements to isolate the issue
  4. Contact Edge Delta support with:
    • Agent version
    • Pipeline configuration (sanitized)
    • Error logs
    • Expected vs actual behavior