Edge Delta's edx_code Extension

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

  5 minute read  

Overview

The Code processor is a Beta feature introduced in Edge Delta Agent v2.6.0 that enables inline JavaScript execution for advanced data transformations in Telemetry Pipelines. It provides a visual JavaScript editor that simplifies complex transformations including conditional logic, array manipulation, nested object operations, and multi-step computations—all within a secure sandbox environment.

The Code processor is the recommended way to write JavaScript transformations in Edge Delta. It provides a developer-friendly experience with:

Key Features

JavaScript Editor - Write familiar JavaScript code with syntax highlighting ✅ AI Code Generation - Generate transformations from natural language descriptions ✅ Automatic OTTL Conversion - JavaScript is auto-wrapped into proper OTTL format ✅ Live Capture Integration - Test your code with real pipeline data ✅ Immediate Feedback - See generated OTTL and validation errors instantly

How to Use the Code Processor

  1. Add a Code Processor to your pipeline sequence
  2. Write JavaScript directly in the editor (no OTTL syntax required)
  3. Test with Live Capture data to verify transformations
  4. Deploy - Edge Delta automatically generates the OTTL statement

In the Code Processor UI, you would write:

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

Note: While you write multi-line JavaScript in the Code Processor UI editor, it gets serialized as a single-line edx_code() statement in YAML:

processors:
  - type: ottl_transform
    metadata: '{"id":"transform","type":"ottl_transform","name":"Transform Data"}'
    data_types:
    - log
    statements: edx_code("item['attributes']['greeting'] = 'Hello from Edge Delta'; item['attributes']['timestamp_ms'] = Date.now();")

You never need to write the YAML manually - the Code Processor handles the conversion automatically.

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 Examples

All examples below show JavaScript code as you would write it in the Code Processor editor. Edge Delta automatically converts this to the proper OTTL format.

Simple Field Assignment

// Set a static field value
item['attributes']['greeting'] = 'Hello from Edge Delta';

// Add current timestamp
item['attributes']['timestamp_ms'] = Date.now();

String Operations

// Concatenate fields to create full name
item['attributes']['full_name'] = item['attributes']['first'] + ' ' + item['attributes']['last'];

// Use template literals for formatting
item['attributes']['summary'] = `User ${item['attributes']['name']} scored ${item['attributes']['score']}`;

Conditional Logic

// Ternary operator for simple conditions
item['attributes']['level_category'] = item['attributes']['score'] > 50 ? 'high' : 'low';

// Full if/else for complex logic
if (item['attributes']['error_count'] > 10) {
  item['attributes']['alert_level'] = 'critical';
  item['attributes']['notify'] = true;
} else {
  item['attributes']['alert_level'] = 'normal';
}

Data Access

The item object provides access to your telemetry event data:

// Access event attributes
item['attributes']['field_name']

// Access raw log body
item['body']

// Access resource attributes (host, service, k8s data)
item['resource']['host.name']
item['resource']['service.name']

Important Syntax Rules:

  • Always use bracket notation: item['attributes']['field']
  • Always use single quotes: item['attributes'] (not double quotes)
  • Never use dot notation: item.attributes.field (not supported)

Learn More

Explore the detailed guides for specific use cases:

Comparison with OTTL + EdgeDelta Extensions

FeatureOTTL + EdgeDelta ExtensionsCode ProcessorBest Choice
Simple field assignment✅ set, delete, merge✅ Full object manipulationEqual
Null coalescing✅ EDXCoalesce|| operatorEqual
Inline conditionals✅ EDXIfElse (ternary)✅ Full if/else/switchCode Processor for complex logic
Array operations⚠️ Limited✅ map, filter, reduce, etc.Code Processor
Object manipulation✅ flatten, merge_maps, edx_map_keys✅ Dynamic creationCode Processor for dynamic structures
JSON operations✅ ParseJSON, EDXUnescapeJSON✅ JSON.parse, JSON.stringifyCode Processor for complex manipulation
Date/time⚠️ Now(), Time()✅ Full Date APICode Processor for arithmetic
Environment variables✅ EDXEnv❌ No accessOTTL extensions
Compression/Encryption✅ EDXCompress, EDXEncrypt❌ No accessOTTL extensions
Redis integration✅ EDXRedis❌ No accessOTTL extensions
Performance✅ Native Go speed⚠️ JavaScript overheadOTTL for high-volume

Use Code Processor for complex conditionals, array transformations, and iterative logic. Use OTTL + EdgeDelta extensions for field operations, pattern extraction, encryption, external data access, and performance-critical paths.


Advanced: Raw edx_code() in OTTL

For advanced users who need to mix JavaScript with other OTTL functions or prefer direct OTTL control, you can write edx_code() statements manually in a Custom (OTTL Transform) processor.

When to Use Raw OTTL

Use raw edx_code() when you need to:

  • Combine JavaScript with other OTTL functions in a single statement
  • Have fine-grained control over OTTL statement composition
  • Mix multiple OTTL converters in a pipeline

Raw OTTL Syntax

edx_code("JavaScript code as string")

Example - Simple Assignment:

edx_code("item['attributes']['greeting'] = 'Hello';")

Example - Multi-line Code:

edx_code("{
  if (item['attributes']['score'] > 50) {
    item['attributes']['level'] = 'high';
  }
}")

Example - Mixed with OTTL:

edx_code("item['attributes']['severity'] = 'error';") where attributes["error_count"] > 10
set(attributes["processed_at"], Now())

In Pipeline YAML (Custom Processor)

processors:
  - type: ottl_transform
    name: custom_transform
    statements: |
      edx_code("item['attributes']['greeting'] = 'Hello from Edge Delta';")
      edx_code("item['attributes']['timestamp'] = Date.now();")      

Important Considerations

When writing raw edx_code() statements:

  1. Quote Escaping: You must escape quotes inside the JavaScript string
  2. Single-line Format: Multi-line code must be wrapped in braces
  3. No AI Assistance: You’re responsible for correct syntax
  4. Manual Testing: Errors appear at runtime, not in the editor

Most users should use the Code Processor instead - it handles all of these complexities automatically and provides a better development experience.