Skip to content

Commit dd479d5

Browse files
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 version
1 parent ffdd018 commit dd479d5

File tree

18 files changed

+2790
-41
lines changed

18 files changed

+2790
-41
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
- name: Build
2525
run: make build-web build-wasm
2626
- name: Run Go Tests
27-
run: go test -v ./...
27+
run: go test -tags ottl_ptr -v ./...

Makefile

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,42 @@ GO_BUILD_LDFLAGS?="-s -w"
33
WEB_OUTPUT_DIR?=../web/public
44
WASM_OUTPUT_DIR?=../web/public/wasm
55

6+
# Versions to build (latest first)
7+
# Note: v0.125.0 not supported due to missing ProfileStatements in transformprocessor
8+
WASM_VERSIONS?=v0.142.0 v0.138.0
9+
610
.PHONY: clean
711
clean:
812
rm -rf web/node_modules
913
rm -rf web/public/wasm
1014
rm -f web/public/bundle.js
1115
rm -f web/public/bundle.js.map
1216

13-
.PHONY: build-test-server
14-
build-build-test-server:
15-
CGO_ENABLED=0 $(GOCMD) build -ldflags $(GO_BUILD_LDFLAGS) -o server
17+
.PHONY: build-web
18+
build-web:
19+
cd web; npm install; npm run build
20+
21+
.PHONY: update-wasm-exec
22+
update-wasm-exec:
23+
cp "$(shell go env GOROOT)/misc/wasm/wasm_exec.js" web/src/wasm_exec.js || cp "$(shell go env GOROOT)/lib/wasm/wasm_exec.js" web/src/wasm_exec.js || true
1624

17-
.PHONY: validate-registered-versions
18-
validate-registered-versions:
19-
$(GOCMD) run ci-tools/main.go validate-registered-versions
25+
.PHONY: build-wasm
26+
build-wasm:
27+
$(eval PROCESSORS_VERSION ?= $(shell $(GOCMD) run ci-tools/main.go get-version))
28+
$(eval BUILD_TAGS := $(shell echo "$(PROCESSORS_VERSION)" | sed 's/v//' | awk -F. '{if ($$1 > 0 || ($$1 == 0 && $$2 >= 142)) print "-tags ottl_ptr"}'))
29+
$(GOCMD) run ci-tools/main.go generate-constants -version=$(PROCESSORS_VERSION)
30+
cd wasm; GOARCH=wasm GOOS=js $(GOCMD) build $(BUILD_TAGS) -trimpath -ldflags $(GO_BUILD_LDFLAGS) -o $(WASM_OUTPUT_DIR)/ottlplayground-$(PROCESSORS_VERSION).wasm
2031

21-
.PHONY: build-unregistered-versions
22-
build-unregistered-versions:
23-
$(eval PROCESSORS_VERSIONS ?= $(shell $(GOCMD) run ci-tools/main.go get-unregistered-versions))
24-
for v in $(PROCESSORS_VERSIONS); do \
25-
export PROCESSORS_VERSION=$$v ; \
26-
$(MAKE) update-processor-version && $(MAKE) build-wasm && $(MAKE) register-version ; \
32+
.PHONY: build-all-wasm
33+
build-all-wasm:
34+
@for v in $(WASM_VERSIONS); do \
35+
echo "Building WASM for $$v..."; \
36+
PROCESSORS_VERSION=$$v $(MAKE) update-processor-version && \
37+
PROCESSORS_VERSION=$$v $(MAKE) build-wasm && \
38+
PROCESSORS_VERSION=$$v $(MAKE) register-version || exit 1; \
2739
done
40+
@echo "Restoring to latest version..."
41+
PROCESSORS_VERSION=$(firstword $(WASM_VERSIONS)) $(MAKE) update-processor-version
2842

2943
.PHONY: update-processor-version
3044
update-processor-version:
@@ -34,42 +48,31 @@ update-processor-version:
3448
COLLECTOR_DEPENDENCIES=$$($(GOCMD) mod graph | grep $$FIRST_PROCESSOR | grep "go.opentelemetry.io/collector/" | awk '{print $$2}' | sort -u); \
3549
COLLECTOR_PARAMS=""; \
3650
for DEP in $$COLLECTOR_DEPENDENCIES; do \
37-
DEP_NAME=$$(echo $$DEP | cut -d'@' -f1); \
38-
DEP_VERSION=$$(echo $$DEP | cut -d'@' -f2); \
39-
if ! $(GOCMD) list -m -json $$DEP_NAME | grep -q "\"Indirect\":true"; then \
40-
COLLECTOR_PARAMS="$$DEP_NAME@$$DEP_VERSION $$COLLECTOR_PARAMS"; \
41-
fi; \
42-
done; \
43-
$(GOCMD) get $$COLLECTOR_PARAMS;
51+
DEP_NAME=$$(echo $$DEP | cut -d'@' -f1); \
52+
DEP_VERSION=$$(echo $$DEP | cut -d'@' -f2); \
53+
if ! $(GOCMD) list -m -json $$DEP_NAME | grep -q "\"Indirect\":true"; then \
54+
COLLECTOR_PARAMS="$$DEP_NAME@$$DEP_VERSION $$COLLECTOR_PARAMS"; \
55+
fi; \
56+
done; \
57+
$(GOCMD) get $$COLLECTOR_PARAMS;
4458
$(MAKE) tidy
4559

46-
.PHONY: build-wasm
47-
build-wasm:
48-
$(eval PROCESSORS_VERSION ?= $(shell $(GOCMD) run ci-tools/main.go get-version))
49-
$(GOCMD) run ci-tools/main.go generate-constants -version=$(PROCESSORS_VERSION)
50-
cd wasm; GOARCH=wasm GOOS=js $(GOCMD) build -ldflags $(GO_BUILD_LDFLAGS) -o $(WASM_OUTPUT_DIR)/ottlplayground-$(PROCESSORS_VERSION).wasm
51-
5260
.PHONY: register-version
5361
register-version:
54-
$(eval PROCESSORS_VERSION ?= $(shell go run ci-tools/main.go get-version))
62+
$(eval PROCESSORS_VERSION ?= $(shell $(GOCMD) run ci-tools/main.go get-version))
5563
$(GOCMD) run ci-tools/main.go register-wasm -version=$(PROCESSORS_VERSION)
5664

57-
.PHONY: build-web
58-
build-web:
59-
cd web; npm install; npm run build
60-
61-
.PHONY: update-wasm-exec
62-
update-wasm-exec:
63-
cp "$(shell go env GOROOT)/misc/wasm/wasm_exec.js" web/src/wasm_exec.js || cp "$(shell go env GOROOT)/lib/wasm/wasm_exec.js" web/src/wasm_exec.js || true
64-
6565
.PHONY: build
66-
build: update-wasm-exec build-web build-wasm register-version
66+
build: update-wasm-exec build-web build-wasm
67+
68+
.PHONY: build-all
69+
build-all: update-wasm-exec build-web build-all-wasm
6770

6871
.PHONY: fmt
6972
fmt:
70-
gofmt -w -s ./
73+
gofmt -w -s ./
7174

7275
.PHONY: tidy
7376
tidy:
7477
rm -fr go.sum
75-
$(GOCMD) mod tidy -compat=1.22.0
78+
$(GOCMD) mod tidy -compat=1.22.0

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ module github.com/elastic/ottl-playground
33
go 1.24.0
44

55
require (
6+
github.com/alecthomas/participle/v2 v2.1.4
67
github.com/go-viper/mapstructure/v2 v2.4.0
8+
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.143.0
79
github.com/open-telemetry/opentelemetry-collector-contrib/processor/filterprocessor v0.143.0
810
github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor v0.143.0
911
github.com/stretchr/testify v1.11.1
@@ -22,7 +24,6 @@ require (
2224
)
2325

2426
require (
25-
github.com/alecthomas/participle/v2 v2.1.4 // indirect
2627
github.com/antchfx/xmlquery v1.5.0 // indirect
2728
github.com/antchfx/xpath v1.3.5 // indirect
2829
github.com/cespare/xxhash/v2 v2.3.0 // indirect
@@ -54,7 +55,6 @@ require (
5455
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.143.0 // indirect
5556
github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter v0.143.0 // indirect
5657
github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil v0.143.0 // indirect
57-
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.143.0 // indirect
5858
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.143.0 // indirect
5959
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
6060
github.com/stretchr/objx v0.5.2 // indirect

0 commit comments

Comments
 (0)