Skip to content

[pkg/ottl] Add map literals #32388

Closed
Closed
@evan-bradley

Description

@evan-bradley

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:

  1. Update buildLexer in grammar.go to understand map literals.
  2. Update the AST in grammar.go to capture keys and values in the map.
  3. Update the parser to create pdata map objects from map literal nodes in the AST.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions