Closed
Description
Component(s)
pkg/ottl
Is your feature request related to a problem? Please describe.
Currently there is no way in OTTL to create a new map. This makes certain use cases difficult and limits the language's expressiveness.
Describe the solution you'd like
Use {"key": value, [...]}
as a map literal syntax, similar to how it looks in JavaScript, JSON, or Go structs. In particular, I would like the following to be possible when retaining the original log body while parsing a log:
- set(body, {"_raw": body})
- set(body["mykey"], "myvalue")
- merge_maps(body, ParseJSON(body["_raw"]))
Describe alternatives you've considered
Instead of map literals, we could add a Map
function with optional parameters to create keys in the initial map. However, I think maps are important enough in OTLP to justify adding map literals to the language.
Additional context
Implementation will broadly look something like the following:
- Update
buildLexer
ingrammar.go
to understand map literals. - Update the AST in
grammar.go
to capture keys and values in the map. - Update the parser to create pdata map objects from map literal nodes in the AST.