Basic Operations
Simple field assignment, string operations, numeric calculations, and boolean operations with edx_code.
3 minute read
edx_code
is a Beta feature introduced in Edge Delta Agent v2.6.0 that executes inline JavaScript expressions within OTTL transform statements. This function enables sophisticated data transformations that would be difficult or impossible using native OTTL alone, including conditional logic, array manipulation, nested object operations, and multi-step computations—all within a secure sandbox environment.
Edge Delta provides a visual Code processor in the pipeline builder interface that simplifies working with edx_code
. This processor offers:
edx_code()
OTTL statementWhen you use the Code processor, you write plain JavaScript (e.g., item.attributes["new_field"] = "Hello"
), and Edge Delta automatically generates the complete OTTL statement (e.g., edx_code("item.attributes[\"new_field\"] = \"Hello\";")
). This eliminates the need to manually escape quotes and format the edx_code()
function call.
Code Processor vs. Custom Processor:
code
in YAMLedx_code()
statements manually in OTTL, type: ottl_transform
in YAMLBoth approaches produce the same runtime behavior—use the Code processor for convenience or write edx_code()
manually in custom processors when you prefer direct control over the OTTL statements.
To use edx_code
in your pipelines, you need:
log_parsing_mode: full
) for field accessedx_code
executes JavaScript code in a restricted sandbox that has access to the telemetry event through the item
object. The JavaScript runtime supports ES6+ features including arrow functions, template literals, const/let declarations, and all standard built-in objects (Math, Date, JSON, RegExp, Array, Object, etc.). The function modifies fields in place and returns control to the OTTL pipeline for subsequent processing.
Syntax
edx_code("JavaScript expression")
JavaScript expression
: A string containing valid JavaScript code that operates on the item
objectitem['attributes']
path provides access to event attributesitem['body']
path provides access to parsed JSON body contentReturn Value
edx_code
modifies the telemetry event in place and does not return a value that can be assigned. Any fields set within the JavaScript code are directly applied to the event attributes.
edx_code("item['attributes']['greeting'] = 'Hello from Edge Delta';")
edx_code("item['attributes']['timestamp'] = Date.now();")
edx_code("item['attributes']['full_name'] = item['attributes']['first'] + ' ' + item['attributes']['last'];")
edx_code("item['attributes']['level_category'] = item['attributes']['score'] > 50 ? 'high' : 'low';")
Explore the detailed guides for specific use cases:
Feature | Native OTTL | edx_code | Advantage |
---|---|---|---|
Simple field assignment | ✅ Easy | ✅ Easy | Equal |
Conditional logic | ⚠️ where clauses only | ✅ Full if/else/ternary | edx_code |
Array manipulation | ❌ Very limited | ✅ All array methods | edx_code |
Nested object creation | ❌ Difficult | ✅ Easy with null-safe checks | edx_code |
JSON operations | ❌ Not available | ✅ Full JSON support | edx_code |
Performance | ✅ Native Go speed | ⚠️ JavaScript overhead | OTTL |
Use edx_code
when you need capabilities beyond native OTTL. Use native OTTL for simple operations where performance is critical.
Simple field assignment, string operations, numeric calculations, and boolean operations with edx_code.
Conditional logic, nested objects, array operations, and multi-step transformations with edx_code.
Complete pipeline configurations demonstrating edx_code in real-world scenarios.
Understanding the JavaScript sandbox environment, capabilities, and restrictions.
Performance considerations, type conversions, known limitations, and best practices.