EDXCode Troubleshooting
4 minute read
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
vsattributes
) - Agent version older than v2.6.0
Debug steps:
- Verify agent version:
kubectl logs <edgedelta-pod> | grep version
- Check for OTTL validation errors in agent logs
- Add a simple test:
edx_code("item['attributes']['debug'] = 'test';")
- 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:
- Use single-level escaping (
\"
or\\
) for predictable behavior - Test complex nested escaping thoroughly before production
- Consider using template literals for readability:
`value with "quotes"`
- 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:
- Validate all field paths exist before accessing
- Use null-safe patterns:
if (item['attributes']['field']) { ... }
- Add type checks:
if (typeof item['attributes']['value'] === 'number') { ... }
- Test with small data volumes first
- 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:
- Check agent logs for detailed error messages
- Verify your pipeline configuration syntax
- Test with simplified
edx_code
statements to isolate the issue - Contact Edge Delta support with:
- Agent version
- Pipeline configuration (sanitized)
- Error logs
- Expected vs actual behavior