Edge Delta's EDXCode Extension

EDXCode enables inline JavaScript execution for advanced data transformations in Edge Delta Telemetry Pipelines.

Overview

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.

Using the Code Processor (GUI)

Edge Delta provides a visual Code processor in the pipeline builder interface that simplifies working with edx_code. This processor offers:

  • JavaScript editor with syntax highlighting for writing transformation code
  • AI-assisted code generation via “Generate with AI” button
  • Automatic OTTL wrapping - your JavaScript is automatically converted to a properly formatted edx_code() OTTL statement
  • Preview of generated OTTL - see the final statement before saving
  • Integrated validation - syntax errors are caught before deployment

When 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 Processor: Visual editor with AI assistance, automatic OTTL generation, type: code in YAML
  • Custom Processor: Write edx_code() statements manually in OTTL, type: ottl_transform in YAML

Both 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.

Prerequisites

To use edx_code in your pipelines, you need:

  • Edge Delta Agent v2.6.0 or later
  • A pipeline with OTTL transform processors
  • JSON parsing enabled (typically log_parsing_mode: full) for field access
  • Understanding of JavaScript ES6+ syntax

How It Works

edx_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 object
  • The item['attributes'] path provides access to event attributes
  • The item['body'] path provides access to parsed JSON body content
  • Code can include multiple statements when wrapped in braces

Return 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.

Quick Start

Simple Example

edx_code("item['attributes']['greeting'] = 'Hello from Edge Delta';")
edx_code("item['attributes']['timestamp'] = Date.now();")

String Concatenation

edx_code("item['attributes']['full_name'] = item['attributes']['first'] + ' ' + item['attributes']['last'];")

Conditional Logic

edx_code("item['attributes']['level_category'] = item['attributes']['score'] > 50 ? 'high' : 'low';")

Learn More

Explore the detailed guides for specific use cases:

Comparison with Native OTTL

FeatureNative OTTLedx_codeAdvantage
Simple field assignment✅ Easy✅ EasyEqual
Conditional logic⚠️ where clauses only✅ Full if/else/ternaryedx_code
Array manipulation❌ Very limited✅ All array methodsedx_code
Nested object creation❌ Difficult✅ Easy with null-safe checksedx_code
JSON operations❌ Not available✅ Full JSON supportedx_code
Performance✅ Native Go speed⚠️ JavaScript overheadOTTL

Use edx_code when you need capabilities beyond native OTTL. Use native OTTL for simple operations where performance is critical.


Basic Operations

Simple field assignment, string operations, numeric calculations, and boolean operations with edx_code.

Complex Transformations

Conditional logic, nested objects, array operations, and multi-step transformations with edx_code.

End-to-End Examples

Complete pipeline configurations demonstrating edx_code in real-world scenarios.

JavaScript Sandbox

Understanding the JavaScript sandbox environment, capabilities, and restrictions.

Performance & Limitations

Performance considerations, type conversions, known limitations, and best practices.