Skip to content

Conversation

@jsvd
Copy link
Member

@jsvd jsvd commented Jan 5, 2026

The implementation adds version-accurate OTTL (OpenTelemetry Transformation Language) autocomplete, validation, and IDE-like features. 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                    # WASM exports for JS interop
  internal/
    metadata.go              # Bridge between pkg/ottl/metadata and WASM
    validator.go             # Native OTTL parser validation
    completion_context.go    # Lexer-based cursor context detection

web/src/components/
  ottl-completion.js         # CodeMirror 6 extensions (completion, hover, linting)
  panels/config-panel.js     # Integrates extensions, forceLint() for version changes
  playground.js              # Version switching, cache invalidation

Features

  1. Autocompletion
  • Function completions with parameter snippets
  • Context-aware path completions (body, attributes, trace_id, etc.)
  • Enum completions (SEVERITY_NUMBER_, SPAN_KIND_, etc.)
  • Lexer-based context detection (handles parens inside strings, nested calls)
  • Works in where clauses: set(body, x) where HasPrefix(...)
  • 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)
  • Auto re-validates when version changes
  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 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

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(stmt)   // Lexer-based cursor context

Multi-Version Support

Version Functions Size (raw) Size (gzip)
v0.138.0 92 55MB ~10MB
v0.125.0 82 52MB ~9MB

When switching versions:

  1. New WASM binary loads
  2. Metadata cache cleared
  3. Editor re-lints with new validator
  4. Completions reflect exact version capabilities

Build

# Build WASM for specific version
PROCESSORS_VERSION=v0.138.0 make build-wasm

# Build uses -trimpath for smaller binaries
cd wasm; GOARCH=wasm GOOS=js go build -trimpath -ldflags "-s -w" ...

jsvd added 2 commits January 5, 2026 15:36
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 5 new WASM exports
  * internal/metadata.go     # Bridge between pkg/ottl/metadata and WASM
  * internal/validator.go    # Native OTTL parser validation

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)

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 closed this Jan 12, 2026
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