Skip to content

Conversation

@jsvd
Copy link
Member

@jsvd jsvd commented Jan 12, 2026

The implementation adds version-accurate OTTL (OpenTelemetry Transformation Language) autocomplete, validation, and IDE-like features to the ottl-playground web application. The features adapt automatically based on which collector version is selected.

Architecture

pkg/ottl/metadata/           # Upstream-ready metadata extraction
  * metadata.go              # Core types: FunctionInfo, ParameterInfo, PathInfo, EnumInfo
  * introspect.go            # Reflection-based factory introspection
  * functions.go             # Function extraction from StandardFuncs registry
  * contexts.go              # Context paths and enums (log, span, metric, etc.)

wasm/
  * main.go                  # Added 6 new WASM exports
  * internal/metadata.go     # Bridge between pkg/ottl/metadata and WASM
  * internal/validator.go    # Native OTTL parser validation dispatcher
  * internal/validator_ptr.go    # Validators for OTTL v0.142.0+ (pointer contexts)
  * internal/validator_noptr.go  # Validators for older OTTL versions
  * internal/completion_context.go # Lexer-based completion context detection

web/src/components/
  * ottl-completion.js       # CodeMirror 6 extensions
  * panels/config-panel.js   # Integrates extensions into editor
  * playground.js            # Clears cache on version change

Features Implemented

  1. Autocompletion
  • Function completions with parameter snippets
  • Context-aware path completions (body, attributes, trace_id, etc.)
  • Enum completions (SEVERITY_NUMBER_, SPAN_KIND_, etc.)
  • Triggers: Cmd+., Alt+Space, or typing
  1. Signature Help
  • Shows function signature while typing arguments
  • Highlights current parameter
  • Updates as cursor moves between arguments
  1. Validation/Linting
  • Uses native OTTL parsers (ottllog.NewParser, etc.)
  • Real-time squiggly underlines for errors
  • Accurate error positioning within statements
  • Context-aware (log, span, metric, datapoint, resource, scope)
  1. Hover Documentation
  • Function hover: signature, parameters, editor vs converter
  • Path hover: type, description, key support
  • Enum hover: name and numeric value
  1. Go-to-Definition
  • Cmd/Ctrl+Click on function names
  • Opens OTTL documentation on GitHub

Version Accuracy

All metadata is extracted at WASM compile time via reflection:

// pkg/ottl/metadata/functions.go
func ExtractStandardFunctions[K any]() []FunctionInfo {
    factories := ottlfuncs.StandardFuncs[K]()  // Version-specific!
    return ExtractAndSortFunctions(factories)
}

WASM Exports

// Available on window after WASM loads
window.getOTTLFunctions()           // All functions with parameters
window.getContextPaths(context)     // Paths for log/span/metric/etc.
window.getContextEnums(context)     // Enums for the context
window.getOTTLMetadata()            // Complete metadata bundle
window.validateStatements(config, dataType, payload, executor)
window.getCompletionContext(statement)  // Lexer-based cursor context

Multi-Version Support

Tested with two WASM binaries:

  • ottlplayground-v0.142.0.wasm
  • ottlplayground-v0.138.0.wasm

Usage Flow

  1. User selects version from dropdown
  2. Corresponding WASM binary loads
  3. clearOTTLMetadataCache() called
  4. On first completion request, metadata fetched from WASM
  5. Functions/paths/enums reflect exact version capabilities
  6. Validation uses native parsers from that version

@jsvd jsvd force-pushed the autocompletion_pr27 branch from e2c59df to 975bed1 Compare January 12, 2026 12:07
jsvd added 3 commits January 12, 2026 13:08
The implementation adds version-accurate OTTL (OpenTelemetry Transformation Language) autocomplete, validation, and IDE-like features to the ottl-playground web application. The features adapt automatically based on which collector version is selected.

Architecture

pkg/ottl/metadata/           # Upstream-ready metadata extraction
  * metadata.go              # Core types: FunctionInfo, ParameterInfo, PathInfo, EnumInfo
  * introspect.go            # Reflection-based factory introspection
  * functions.go             # Function extraction from StandardFuncs registry
  * contexts.go              # Context paths and enums (log, span, metric, etc.)

wasm/
  * main.go                  # Added 6 new WASM exports
  * internal/metadata.go     # Bridge between pkg/ottl/metadata and WASM
  * internal/validator.go    # Native OTTL parser validation dispatcher
  * internal/validator_ptr.go    # Validators for OTTL v0.142.0+ (pointer contexts)
  * internal/validator_noptr.go  # Validators for older OTTL versions
  * internal/completion_context.go # Lexer-based completion context detection

web/src/components/
  * ottl-completion.js       # CodeMirror 6 extensions
  * panels/config-panel.js   # Integrates extensions into editor
  * playground.js            # Clears cache on version change

Features Implemented

1. Autocompletion
- Function completions with parameter snippets
- Context-aware path completions (body, attributes, trace_id, etc.)
- Enum completions (SEVERITY_NUMBER_*, SPAN_KIND_*, etc.)
- Triggers: Cmd+., Alt+Space, or typing

2. Signature Help
- Shows function signature while typing arguments
- Highlights current parameter
- Updates as cursor moves between arguments

3. Validation/Linting
- Uses native OTTL parsers (ottllog.NewParser, etc.)
- Real-time squiggly underlines for errors
- Accurate error positioning within statements
- Context-aware (log, span, metric, datapoint, resource, scope)

4. Hover Documentation
- Function hover: signature, parameters, editor vs converter
- Path hover: type, description, key support
- Enum hover: name and numeric value

5. Go-to-Definition
- Cmd/Ctrl+Click on function names
- Opens OTTL documentation on GitHub

Version Accuracy

All metadata is extracted at WASM compile time via reflection:

// pkg/ottl/metadata/functions.go
func ExtractStandardFunctions[K any]() []FunctionInfo {
    factories := ottlfuncs.StandardFuncs[K]()  // Version-specific!
    return ExtractAndSortFunctions(factories)
}

WASM Exports

// Available on window after WASM loads
window.getOTTLFunctions()           // All functions with parameters
window.getContextPaths(context)     // Paths for log/span/metric/etc.
window.getContextEnums(context)     // Enums for the context
window.getOTTLMetadata()            // Complete metadata bundle
window.validateStatements(config, dataType, payload, executor)
window.getCompletionContext(statement)  // Lexer-based cursor context

Multi-Version Support

Tested with two WASM binaries:
- ottlplayground-v0.138.0.wasm (92 functions)
- ottlplayground-v0.125.0.wasm (82 functions)

Usage Flow

1. User selects version from dropdown
2. Corresponding WASM binary loads
3. clearOTTLMetadataCache() called
4. On first completion request, metadata fetched from WASM
5. Functions/paths/enums reflect exact version capabilities
6. Validation uses native parsers from that version
@jsvd jsvd force-pushed the autocompletion_pr27 branch from 975bed1 to 19ebb9e Compare January 12, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant