Skip to content

Commit e44cd91

Browse files
seunghuneepront
andauthored
docs(website): fix incorrect example about the contains function (#22724)
* docs(website): fix incorrect example about the `contains` function The `contains` function is now infallible and always returns a boolean value. This commit fixes the example in the `transformation` guide. * docs(website): add section on context-specific execution differences * Update website/content/en/guides/level-up/transformation.md Co-authored-by: Pavlos Rontidis <[email protected]> * docs(website): remove trailing space --------- Co-authored-by: Pavlos Rontidis <[email protected]>
1 parent 56fd462 commit e44cd91

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

website/content/en/guides/level-up/transformation.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ transforms:
138138
# If the log message contains the phrase "Great Scott!", set the new field
139139
# "critical" to true, otherwise set it to false. If the "contains" function
140140
# errors, log the error (instead of aborting the script, as above).
141-
if (is_critical, err = contains(.message, "Great Scott!"); err != null) {
142-
log(err, level: "error")
141+
if (is_critical = contains(.message, "Great Scott!"); is_critical) {
142+
log("It contains 'Great Scott!'", level: "info")
143143
}
144144
145145
.critical = is_critical
@@ -158,6 +158,15 @@ A few things to notice about this script:
158158
`.foo[0]`, `.foo.bar`, `.foo.bar[0]`, and so on to reference subfields, array
159159
indices, and more.
160160

161+
{{< info >}}
162+
Note that VRL functions can behave differently depending on the execution context.
163+
For example, the `contains` function above is infallible when ran inside a Vector/Remap process if the compiler can detect that the type of `.message` is a string.
164+
The same code might behave differently when run in the [VRL Playground][urls.playground],
165+
VRL CLI, or when `schema.log_namespace` is set to `true`.
166+
167+
[urls.playground]: https://playground.vrl.dev/?state=eyJwcm9ncmFtIjoiLmlzX2NyaXRpY2FsID0gY29udGFpbnMoLm1lc3NhZ2UsIFwiR3JlYXQgU2NvdHQhXCIpIiwiZXZlbnQiOnsibWVzc2FnZSI6IkdyZWF0IFNjb3R0ISJ9LCJpc19qc29ubCI6ZmFsc2UsImVycm9yIjpudWxsfQ%3D%3D
168+
{{< /info >}}
169+
161170
If you stop and restart Vector, you should see log lines like this (again
162171
reformatted for readability):
163172

0 commit comments

Comments
 (0)