Commit dd479d5
committed
OTTL Playground Autocomplete Implementation Summary
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 version1 parent ffdd018 commit dd479d5
File tree
18 files changed
+2790
-41
lines changed- .github/workflows
- pkg/ottl/metadata
- wasm
- internal
- web
- public/wasm
- src/components
- panels
18 files changed
+2790
-41
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
6 | 10 | | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
16 | 24 | | |
17 | | - | |
18 | | - | |
19 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
20 | 31 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
27 | 39 | | |
| 40 | + | |
| 41 | + | |
28 | 42 | | |
29 | 43 | | |
30 | 44 | | |
| |||
34 | 48 | | |
35 | 49 | | |
36 | 50 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
44 | 58 | | |
45 | 59 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | 60 | | |
53 | 61 | | |
54 | | - | |
| 62 | + | |
55 | 63 | | |
56 | 64 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
67 | 70 | | |
68 | 71 | | |
69 | 72 | | |
70 | | - | |
| 73 | + | |
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
74 | 77 | | |
75 | | - | |
| 78 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | | - | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | | - | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
0 commit comments