### Run VRL Release (Default) Source: https://github.com/vectordotdev/vrl/blob/main/release/README.md Executes the default release flow: bumps minor version, generates changelog, publishes, tags, and creates a PR. No setup is required beyond having the tool installed. ```shell cargo run -p release ``` -------------------------------- ### Install VRL CLI Source: https://context7.com/vectordotdev/vrl/llms.txt Installs the VRL command-line interface using Cargo. ```sh # Install cargo install vrl --features cli,stdlib ``` -------------------------------- ### Example Breaking Change Fragment Source: https://github.com/vectordotdev/vrl/blob/main/changelog.d/README.md This example shows the content of a changelog fragment for a breaking change. Content should be renderable as a markdown list item and can span multiple lines. ```markdown This change is so great. It's such a great change that this sentence has to span multiple lines of text. It even necessitates a line break. It is a breaking change after all. ``` -------------------------------- ### Open Interactive VRL REPL Source: https://context7.com/vectordotdev/vrl/llms.txt Starts the VRL interactive Read-Eval-Print Loop (REPL) without any arguments. ```sh # Open interactive REPL (no arguments) vrl ``` -------------------------------- ### Example VRL Diagnostic Message Source: https://github.com/vectordotdev/vrl/blob/main/lib/tests/tests/diagnostics/README.md This is an example of a compile-time diagnostic message in VRL, indicating an unnecessary error assignment. It includes details about the error location, a hint for correction, and links to relevant documentation and the VRL REPL. ```text error: unnecessary error assignment ┌─ :2:1 │ 2 │ ok, err = 5; │ ^^^^^^^ - because this expression cannot fail │ │ │ this error assignment is unnecessary │ = hint: assign to "ok", without assigning to "err" = see language documentation at: https://vector.dev/docs/reference/vrl/ = try your code in the VRL REPL, learn more at https://vrl.dev/examples ``` -------------------------------- ### CoffeeScript Unhandled Error Reporting Source: https://github.com/vectordotdev/vrl/blob/main/changelog.d/1759.fix.md This CoffeeScript example demonstrates how the compiler now reports multiple unhandled errors in a single pass. Previously, only the last error would be visible after fixing preceding ones. ```coffeescript { push(.x, 1) .b = push(.y, 2) } ``` -------------------------------- ### Implement Target Trait with TargetValue Source: https://context7.com/vectordotdev/vrl/llms.txt Demonstrates the use of `TargetValue`, the standard `Target` trait implementation, for managing event values, metadata, and secrets. Shows how to insert, get, and remove fields using `OwnedTargetPath`. ```rust use vrl::compiler::{TargetValue, Target}; use vrl::path::OwnedTargetPath; use vrl::value::{Secrets, Value}; use std::collections::BTreeMap; fn main() { let mut target = TargetValue { value: vrl::value!({ host: "server-01", port: 8080 }), metadata: Value::Object(BTreeMap::new()), secrets: Secrets::default(), }; // Insert a new field let path = OwnedTargetPath::event("env".into()); target.target_insert(&path, "production".into()).unwrap(); // Retrieve a field let host_path = OwnedTargetPath::event("host".into()); let host = target.target_get(&host_path).unwrap(); assert_eq!(host, Some(&Value::from("server-01"))); // Remove a field target.target_remove(&OwnedTargetPath::event("port".into()), false).unwrap(); } ``` -------------------------------- ### CoffeeScript Compile Error Example Source: https://github.com/vectordotdev/vrl/blob/main/changelog.d/453.fix.md This CoffeeScript example demonstrates a scenario where an unhandled error in a fallible call was incorrectly flagged on a later assignment line. Adding '!' or ', err =' to the fallible expression resolves the issue. ```coffeescript { .a = 1 push(.x, 1) # the unhandled error is actually here .b = 2 # but the compiler used to flag this line } ``` -------------------------------- ### Timestamp Operations Source: https://context7.com/vectordotdev/vrl/llms.txt Functions for handling timestamps, including getting the current time, formatting, parsing from strings, and converting to/from Unix epoch. ```vrl # Current UTC timestamp ts = now() ``` ```vrl # Format a timestamp format_timestamp!(ts, format: "%Y-%m-%dT%H:%M:%SZ") # => "2024-06-01T12:00:00Z" ``` ```vrl # Parse a timestamp from a string parsed = parse_timestamp!("2024-06-01T12:00:00Z", format: "%+") # => timestamp("2024-06-01T12:00:00Z") ``` ```vrl # Unix epoch to timestamp from_unix_timestamp!(1_717_243_200) # => timestamp("2024-06-01T08:00:00Z") ``` ```vrl # Timestamp to unix epoch to_unix_timestamp(ts) # => 1717243200 ``` -------------------------------- ### VRL Object Initialization Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Shows how to initialize objects with key-value pairs in VRL. ```vrl {true; 1+1; null} ``` -------------------------------- ### VRL Comparison Operators Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Demonstrates the use of comparison operators in VRL. ```vrl 1 == 1 2 > 1 1 < 2 ``` -------------------------------- ### VRL Base64 and Gzip Encoding Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Illustrates encoding a string with Gzip and then Base64 encoding the result. ```vrl encode_base64(encode_gzip("please encode me")) ``` -------------------------------- ### Field Manipulation Source: https://context7.com/vectordotdev/vrl/llms.txt Core operations for accessing and modifying fields within data structures. Supports deletion, setting, getting by dynamic path, and checking existence. ```vrl # del: remove a field .sensitive = "secret" del(.sensitive) # .sensitive is now absent ``` ```vrl # set: insert at a computed path (dynamic path as array) key = "region" . = set!(., [key], "us-east-1") # => .region = "us-east-1" ``` ```vrl # get: retrieve by dynamic path field_name = "host" value = get!(., [field_name]) ``` ```vrl # exists: conditional logic if exists(.user.email) { .has_email = true } ``` -------------------------------- ### VRL Sequential Execution Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Illustrates sequential execution of expressions in VRL. ```vrl 1;2;3 ``` -------------------------------- ### VRL String Splitting Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Demonstrates splitting a string into chunks of a specified size. ```vrl chunks("abcdefgh", 4) ``` -------------------------------- ### VRL Regular Expression Matching Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Shows how to define and use regular expressions in VRL. ```vrl . (a|b) = "foo" ``` -------------------------------- ### value! macro Source: https://context7.com/vectordotdev/vrl/llms.txt A macro for constructing `vrl::value::Value` instances ergonomically using JSON-like syntax. ```APIDOC ## value! macro — Construct `Value` literals ### Description A macro for ergonomically constructing `vrl::value::Value` instances inline using JSON-like syntax. ### Usage `value!() ### Parameters Accepts JSON-like structures (objects, arrays) and scalar types (string, number, boolean, null). ### Request Example ```rust use vrl::value; use vrl::value::Value; fn main() { let v: Value = value!({ user: { id: 42, name: "Alice", active: true, scores: [98, 85, 100], meta: null, } }); // Scalars let n: Value = value!(3.14); let b: Value = value!(false); let s: Value = value!("hello"); // Access nested fields assert_eq!(v.get("user.id"), Some(&value!(42))); } ``` ### Response - **Success Response**: Constructs a `vrl::value::Value` instance. #### Response Example ```rust // Example constructed Value vrl::value!({ "key": "value" }) ``` ``` -------------------------------- ### Run VRL Release (Link GitHub Issue) Source: https://github.com/vectordotdev/vrl/blob/main/release/README.md Links a specific GitHub issue to the release process. Ensure the provided URL is valid and points to an existing issue in the vectordotdev/vrl repository. ```shell cargo run -p release -- --issue https://github.com/vectordotdev/vrl/issues/123 ``` -------------------------------- ### Check Changelog Syntax Source: https://github.com/vectordotdev/vrl/blob/main/changelog.d/README.md Run this command to validate the syntax of your changelog fragments before committing. ```bash cargo run -p release -- check-changelog ``` -------------------------------- ### VRL Arithmetic and String Concatenation Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Demonstrates basic arithmetic operations and string concatenation in VRL. ```vrl 1+1 1-1 1*1 1/1 "Hello" + "World" ``` -------------------------------- ### Run VRL Release (Dry Run) Source: https://github.com/vectordotdev/vrl/blob/main/release/README.md Performs a dry run of the release process, previewing all changes without making any actual modifications or publications. This is useful for verifying the release steps before committing. ```shell cargo run -p release -- --dry-run ``` -------------------------------- ### Load All Standard Library Functions Source: https://context7.com/vectordotdev/vrl/llms.txt Retrieves all built-in VRL functions as a `Vec>` using `vrl::stdlib::all`. This vector can be directly passed to any `compile*` function. Alternatively, a selective subset of functions can be loaded. ```rust fn main() { let fns = vrl::stdlib::all(); println!("Available functions: {}", fns.len()); // ~180+ // Or load a selective subset using individual structs: let selective: Vec> = vec![ Box::new(vrl::stdlib::ParseJson), Box::new(vrl::stdlib::EncodeJson), Box::new(vrl::stdlib::Upcase), Box::new(vrl::stdlib::Replace), ]; let _ = vrl::compiler::compile(r#"upcase(.msg)"#, &selective).unwrap(); } ``` -------------------------------- ### VRL: Preferring Immutability Over Mutation Source: https://github.com/vectordotdev/vrl/blob/main/DESIGN.md Demonstrates VRL's preference for returning new data copies over mutating existing data. This approach enhances code clarity at a potential performance cost. ```VRL # explicitly assign the parsed JSON to ".message" .message = parse_json(.message) ``` ```VRL # mutate ".message" in place parse_json(.message) ``` -------------------------------- ### Compile VRL for WebAssembly Source: https://github.com/vectordotdev/vrl/blob/main/README.md Use this command to check VRL code targeting the wasm32-unknown-unknown platform. Ensure to exclude default features and include the stdlib. ```sh cargo check --target wasm32-unknown-unknown --no-default-features --features stdlib ``` -------------------------------- ### VRL Zlib and Base64 Decoding Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Illustrates decoding a Base64 encoded string that contains Zlib compressed data. ```vrl decode_zlib!(decode_base64!("eJwNy4ENwCAIBMCNXIlQ/KqplUSgCdvXAS41qPMHshCB2R1zJlWIVlR6UURX2+wx2YcuK3kAb9C1wd6dn7Fa+QH9gRxr")) ``` -------------------------------- ### vrl::stdlib::all Source: https://context7.com/vectordotdev/vrl/llms.txt Loads all built-in VRL functions, returning them as a `Vec>`. This can be passed directly to any `compile*` function. ```APIDOC ## vrl::stdlib::all — Load all standard library functions ### Description Returns all built-in VRL functions as a `Vec>`. Pass the result directly to any `compile*` function. ### Method `vrl::stdlib::all()` ### Parameters None ### Request Example ```rust fn main() { let fns = vrl::stdlib::all(); println!("Available functions: {}", fns.len()); // ~180+ // Or load a selective subset using individual structs: let selective: Vec> = vec![ Box::new(vrl::stdlib::ParseJson), Box::new(vrl::stdlib::EncodeJson), Box::new(vrl::stdlib::Upcase), Box::new(vrl::stdlib::Replace), ]; let _ = vrl::compiler::compile(r#"upcase(.msg)"#, &selective).unwrap(); } ``` ### Response - **Success Response**: A `Vec>` containing all standard library functions. ### Usage Used to provide the set of available functions during VRL compilation. ``` -------------------------------- ### VRL Base64 Encoding Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Shows how to encode a string into Base64 format. ```vrl encode_base64("please encode me") ``` -------------------------------- ### Run VRL Program File Source: https://context7.com/vectordotdev/vrl/llms.txt Executes a VRL program from a file against JSON events from another file. ```sh # Run a program file against a JSON event file (one JSON object per line) vrl --program transform.vrl --input events.json ``` -------------------------------- ### VRL Basic Data Types Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Demonstrates the basic data types supported in VRL, including null, booleans, numbers, and strings. ```vrl .foo = null # comment [1, "two", .x] true false 1.0 1_000.0 1000 null {"foo": "bar"} {"foo2": true} regex = r'^Hello, World!$' .msg = "message" ``` -------------------------------- ### Run VRL Release (Specific Version Bump) Source: https://github.com/vectordotdev/vrl/blob/main/release/README.md Bumps a specific component of the version (major, minor, or patch) or sets an exact version for the release process. Use this when a standard minor version bump is not appropriate. ```shell cargo run -p release -- major ``` ```shell cargo run -p release -- patch ``` ```shell cargo run -p release -- 1.2.3 ``` -------------------------------- ### VRL Base64 and Gzip Decoding Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Demonstrates decoding a Base64 encoded string that contains Gzip compressed data. ```vrl decode_gzip!(decode_base64!("H4sIAHEAymMAA6vML1XISCxLVSguTU5OLS5OK83JqVRISU3OT0lNUchNBQD7BGDaIAAAAA==")) ``` -------------------------------- ### Run VRL Program Inline Source: https://context7.com/vectordotdev/vrl/llms.txt Executes a VRL program directly on an empty event. ```sh # Run a program inline against an empty event vrl '.message = "hello"' ``` -------------------------------- ### Compile VRL Program with Standard Library Source: https://context7.com/vectordotdev/vrl/llms.txt Compiles a VRL source string into an executable Program using the full standard library. Handles type errors and unhandled fallible calls at compile time. Requires explicit handling of fallible functions. ```rust use std::collections::BTreeMap; use vrl::compiler::{Context, TargetValue, TimeZone, state::RuntimeState}; use vrl::value::{Secrets, Value}; use vrl::value; fn main() { // VRL source: parse a JSON string field and extract a nested value let src = r#"parsed = parse_json!(.message) .status = parsed.level .user_id = to_int!(parsed.user_id) del(.message)"#; // Load the full standard library let fns = vrl::stdlib::all(); // Compile — fails at compile time if there are type errors or unhandled fallible calls let result = vrl::compiler::compile(src, &fns).unwrap(); let mut target = TargetValue { value: value!({ message: r#"{"level":"warn","user_id":"42"}"# }), metadata: Value::Object(BTreeMap::new()), secrets: Secrets::default(), }; let mut state = RuntimeState::default(); let timezone = TimeZone::default(); let mut ctx = Context::new(&mut target, &mut state, &timezone); let _value = result.program.resolve(&mut ctx).unwrap(); // target.value is now: { "status": "warn", "user_id": 42 } assert_eq!(target.value.get("status"), Some(&value!("warn"))); assert_eq!(target.value.get("user_id"), Some(&value!(42))); } ``` -------------------------------- ### Regenerate VRL Docs Source: https://github.com/vectordotdev/vrl/blob/main/docs/generated/README.md Use this command to regenerate the VRL stdlib function documentation JSON files. ```sh ./scripts/generate_docs.sh ``` -------------------------------- ### Suppress VRL Startup Banner Source: https://context7.com/vectordotdev/vrl/llms.txt Runs the VRL CLI in quiet mode to suppress the startup banner. ```sh # Suppress the startup banner (quiet mode) vrl --quiet ``` -------------------------------- ### VRL Control Flow Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Illustrates VRL's conditional statements and logical operators. ```vrl abort if true { null } else { 4 } if false { .x = 5 } true && false .x || 4 !false ``` -------------------------------- ### Parse Logfmt String Source: https://context7.com/vectordotdev/vrl/llms.txt A convenience alias for parsing strings in the logfmt format. ```vrl parse_logfmt!(s'level=info msg="task complete"') ``` -------------------------------- ### Compile VRL Program with External Environment and Config Source: https://context7.com/vectordotdev/vrl/llms.txt Compiles a VRL program with a custom ExternalEnv to define expected event shapes at compile time and a CompileConfig for settings like read-only paths. Ensures type safety based on the provided environment. ```rust use vrl::compiler::{ compile_with_external, CompileConfig, Context, TargetValue, TimeZone, state::{ExternalEnv, RuntimeState}, type_def::Details, }; use vrl::value::{Secrets, Value, kind::Kind}; use vrl::path::OwnedValuePath; use std::collections::BTreeMap; fn main() { let src = ".severity = upcase(string!(.level))"; let fns = vrl::stdlib::all(); let mut external = ExternalEnv::default(); // Tell the compiler that `.level` is always a string external.set_event_field( &"level".into(), Details { type_def: vrl::compiler::TypeDef::bytes(), value: None }, ); let mut config = CompileConfig::default(); config.set_read_only_path( vrl::path::OwnedTargetPath::event("level".into()), false, ); let result = compile_with_external(src, &fns, &external, config).unwrap(); let mut target = TargetValue { value: vrl::value!({ level: "info" }), metadata: Value::Object(BTreeMap::new()), secrets: Secrets::default(), }; let mut state = RuntimeState::default(); let tz = TimeZone::default(); let mut ctx = Context::new(&mut target, &mut state, &tz); result.program.resolve(&mut ctx).unwrap(); // target.value == { "level": "info", "severity": "INFO" } } ``` -------------------------------- ### CompileConfig Source: https://context7.com/vectordotdev/vrl/llms.txt Configuration options for compiling VRL programs. Controls aspects like read-only path enforcement, unused expression warnings, and custom context injection for functions. ```APIDOC ## CompileConfig — Compilation configuration ### Description Controls read-only path enforcement, unused expression warnings, and custom context injection for functions that need external data at compile time. ### Methods - `CompileConfig::default()`: Creates a new `CompileConfig` with default settings. - `config.set_read_only()`: Marks the entire event as read-only, preventing mutations. - `config.set_custom(data)`: Injects custom context data accessible by custom functions. - `config.disable_unused_expression_check()`: Disables warnings for unused expressions. ### Parameters None directly for `CompileConfig` itself, but methods accept parameters. ### Request Example ```rust use vrl::compiler::{CompileConfig, compile_with_external, state::ExternalEnv}; use vrl::path::OwnedTargetPath; fn main() { let mut config = CompileConfig::default(); // Mark the entire event as read-only (no mutation allowed) config.set_read_only(); // Inject custom context data accessible by custom functions #[derive(Debug)] struct MyConfig { tenant_id: String } config.set_custom(MyConfig { tenant_id: "acme".into() }); // Disable unused-expression warnings config.disable_unused_expression_check(); let external = ExternalEnv::default(); let fns = vrl::stdlib::all(); // compile_with_external(".foo", &fns, &external, config) } ``` ### Response N/A - This is a configuration struct, not an endpoint. ### Usage Used as an argument to compilation functions like `compile_with_external`. ``` -------------------------------- ### Show Warnings in VRL Output Source: https://context7.com/vectordotdev/vrl/llms.txt Enables the display of warnings in the VRL CLI output. ```sh # Show warnings in output vrl --print-warnings '.foo = "bar"' ``` -------------------------------- ### Issue Tracking Link for VRL Tests Source: https://github.com/vectordotdev/vrl/blob/main/lib/tests/tests/fixme/README.md Provide a link to the relevant open tracking issue for the bug being tested. This helps in tracking the resolution progress. ```text issue: ``` -------------------------------- ### Make HTTP requests Source: https://context7.com/vectordotdev/vrl/llms.txt Performs synchronous HTTP requests. Supports various methods, headers, and body content. Not supported on wasm32. ```vrl # Simple GET and parse JSON response . = parse_json!(http_request!("https://httpbin.org/get")) ``` ```vrl # POST with JSON body and Authorization header response = http_request!( "https://api.example.com/events", method: "post", headers: { "Authorization": "Bearer my_token", "Content-Type": "application/json" }, body: encode_json({ "source": "vrl", "level": "info" }) ) parse_json!(response) ``` ```vrl # PUT request . = parse_json!(http_request!("https://httpbin.org/put", method: "put")) ``` -------------------------------- ### Parse Regex All Source: https://context7.com/vectordotdev/vrl/llms.txt Parses a string using a regular expression and returns all matches as an array of objects. ```vrl parse_regex_all!("one=1 two=2 three=3", r'(?P\w+)=(?P\d+)') ``` -------------------------------- ### VRL JSON Parsing Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Demonstrates parsing JSON strings using the `parse_json` function in VRL. ```vrl result, err = parse_json("1234") .result, .err = parse_json("1234") ``` -------------------------------- ### VRL Percent Encoding Decoding Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Demonstrates decoding a percent-encoded string. ```vrl decode_percent("foo%20bar%3F") ``` -------------------------------- ### http_request Source: https://context7.com/vectordotdev/vrl/llms.txt Makes a synchronous HTTP request to a specified URL. ```APIDOC ## http_request — Make a synchronous HTTP request ### Description Makes an HTTP request and returns the response body as bytes. Supports GET, POST, PUT, PATCH, DELETE methods, custom headers, body, and optional proxy configuration. Fallible. **Not supported on wasm32.** ### Parameters - `url` (string) - The URL to make the request to. - `method` (string, optional) - The HTTP method to use (e.g., "GET", "POST"). Defaults to "GET". - `headers` (object, optional) - A map of custom headers to include in the request. - `body` (bytes, optional) - The request body. - `proxy` (object, optional) - Proxy configuration. ### Request Example ```vrl # Simple GET and parse JSON response . = parse_json!(http_request!("https://httpbin.org/get")) # POST with JSON body and Authorization header response = http_request!( "https://api.example.com/events", method: "post", headers: { "Authorization": "Bearer my_token", "Content-Type": "application/json" }, body: encode_json({ "source": "vrl", "level": "info" }) ) parse_json!(response) # PUT request . = parse_json!(http_request!("https://httpbin.org/put", method: "put")) ``` ``` -------------------------------- ### VRL Base16 Decoding Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Shows how to decode a Base16 encoded string. ```vrl decode_base16!("796f752068617665207375636365737366756c6c79206465636f646564206d65") ``` -------------------------------- ### VRL Zstd and Base64 Decoding Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Shows how to decode a Base64 encoded string containing Zstandard compressed data. ```vrl decode_zstd!(decode_base64!("KLUv/QBY/QEAYsQOFKClbQBedqXsb96EWDax/f/F/z+gNU4ZTInaUeAj82KqPFjUzKqhcfDqAIsLvAsnY1bI/N2mHzDixRQA")) ``` -------------------------------- ### Execute Compiled VRL Program with Context Source: https://context7.com/vectordotdev/vrl/llms.txt Executes a compiled VRL program against a target within a given context. Mutates the target in place and returns the final expression's value. Requires `vrl::compiler::Context`, `Program`, and `RuntimeState`. ```rust use vrl::compiler::{Context, Program, state::RuntimeState}; fn run_program(program: &Program, target: &mut impl vrl::compiler::Target) -> vrl::value::Value { let mut state = RuntimeState::default(); let tz = vrl::compiler::TimeZone::default(); let mut ctx = Context::new(target, &mut state, &tz); program.resolve(&mut ctx).expect("runtime error") } ``` -------------------------------- ### Compile VRL Program with Full TypeState Source: https://context7.com/vectordotdev/vrl/llms.txt Compiles a VRL program using a fully specified TypeState, which combines LocalEnv and ExternalEnv. This is useful for incremental compilation or stateful multi-program pipelines where the complete type information is known. ```rust use vrl::compiler::{compile_with_state, CompileConfig, TypeState}; fn main() { let src = "upcase(.host)"; let fns = vrl::stdlib::all(); let state = TypeState::default(); let config = CompileConfig::default(); match compile_with_state(src, &fns, &state, config) { Ok(result) => println!("Compiled OK, {} warnings", result.warnings.len()), Err(diagnostics) => eprintln!("Compile error: {:?}", diagnostics), } } ``` -------------------------------- ### String Case Conversion Source: https://context7.com/vectordotdev/vrl/llms.txt Provides functions for converting strings between various cases like uppercase, lowercase, camelCase, and snake_case. ```vrl upcase("hello world") # => "HELLO WORLD" ``` ```vrl downcase("HELLO WORLD") # => "hello world" ``` ```vrl camelcase("hello world") # => "helloWorld" ``` ```vrl snakecase("Hello World") # => "hello_world" ``` ```vrl pascalcase("hello world") # => "HelloWorld" ``` ```vrl kebabcase("Hello World") # => "hello-world" ``` ```vrl screaming_snakecase("Hello World") # => "HELLO_WORLD" ``` -------------------------------- ### Avoid In-place Mutation in VRL Source: https://github.com/vectordotdev/vrl/blob/main/DESIGN.md Refrain from mutating fields directly with function calls; prefer explicit assignment for clarity and predictability. ```coffee # mutate ".message" in place parse_json(.message) ``` -------------------------------- ### vrl::compiler::compile_with_external Source: https://context7.com/vectordotdev/vrl/llms.txt Compiles a VRL program with a custom external environment and compile configuration, allowing for more control over compile-time type checking and environment assumptions. ```APIDOC ## vrl::compiler::compile_with_external — Compile with external environment and config ### Description Compiles a VRL program with a custom `ExternalEnv` (describing the expected shape of the target event at compile time) and a `CompileConfig` (e.g., read-only paths, custom context data). ### Method `vrl::compiler::compile_with_external(src: &str, fns: &FunctionCollection, external: &ExternalEnv, config: CompileConfig) -> Result` ### Parameters - `src` (string): The VRL source code to compile. - `fns` (FunctionCollection): A collection of available VRL functions. - `external` (ExternalEnv): Defines the expected shape of the target event at compile time. - `config` (CompileConfig): Configuration options for compilation, such as read-only paths. ### Request Example ```rust use vrl::compiler::{ compile_with_external, CompileConfig, Context, TargetValue, TimeZone, state::{ExternalEnv, RuntimeState}, type_def::Details, }; use vrl::value::{Secrets, Value, kind::Kind}; use vrl::path::OwnedValuePath; use std::collections::BTreeMap; let src = ".severity = upcase(string!(.level))"; let fns = vrl::stdlib::all(); let mut external = ExternalEnv::default(); external.set_event_field( &"level".into(), Details { type_def: vrl::compiler::TypeDef::bytes(), value: None }, ); let mut config = CompileConfig::default(); config.set_read_only_path( vrl::path::OwnedTargetPath::event("level".into()), false, ); let result = compile_with_external(src, &fns, &external, config).unwrap(); let mut target = TargetValue { value: vrl::value!({ level: "info" }), metadata: Value::Object(BTreeMap::new()), secrets: Secrets::default(), }; let mut state = RuntimeState::default(); let tz = TimeZone::default(); let mut ctx = Context::new(&mut target, &mut state, &tz); result.program.resolve(&mut ctx).unwrap(); // target.value == { "level": "info", "severity": "INFO" } ``` ### Response #### Success Response `CompilationResult` containing the compiled `Program` and any warnings. #### Error Response `DiagnosticList` if compilation fails. ``` -------------------------------- ### Pipe JSON Event to VRL CLI Source: https://context7.com/vectordotdev/vrl/llms.txt Processes a JSON event piped from stdin using the VRL CLI. ```sh # Pipe a JSON event from stdin echo '{"level":"info","msg":"started"}' | vrl '.level = upcase(.level)' # Output: "INFO" ``` -------------------------------- ### Parse Key-Value Strings Source: https://context7.com/vectordotdev/vrl/llms.txt Parses strings formatted as key-value pairs. Supports custom delimiters and is fallible. ```vrl parse_key_value!("name=Alice age=30 active=true") ``` ```vrl parse_key_value!(s'level="info" msg="task done" duration=1.5', field_delimiter: " ", value_delimiter: "=") ``` -------------------------------- ### VRL MIME Base64 Decoding Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Shows how to decode a MIME Base64 encoded string. ```vrl decode_mime_q!("=?utf-8?b?SGVsbG8sIFdvcmxkIQ==?=") ``` -------------------------------- ### Encode Proto with Integer Key Map Source: https://github.com/vectordotdev/vrl/blob/main/changelog.d/1762.fix.md Use `encode_proto` to serialize a message containing a proto map with an integer key. The integer key '42' is represented as a string '42'. ```coffee encode_proto({ "by_id": { "42": "alice" } }, "schema.desc", "MyMessage") ``` -------------------------------- ### Print Full Object with VRL Source: https://context7.com/vectordotdev/vrl/llms.txt Configures the VRL CLI to print the entire modified object instead of just the last expression's value. ```sh # Print the full (modified) target object instead of the last expression's value vrl --print-object --program transform.vrl --input events.json ``` -------------------------------- ### Stateful Runtime Execution of VRL Programs Source: https://context7.com/vectordotdev/vrl/llms.txt Enables repeated execution of VRL programs against multiple targets while preserving state between calls using `Runtime`. Initializes a `Runtime` and `TimeZone`, then iterates through targets, resolving each with the compiled program. ```rust use vrl::compiler::{TargetValue, TimeZone, runtime::Runtime}; use vrl::value::{Secrets, Value}; use std::collections::BTreeMap; fn main() { let src = ".count = (.count ?? 0) + 1"; let fns = vrl::stdlib::all(); let compilation = vrl::compiler::compile(src, &fns).unwrap(); let mut runtime = Runtime::default(); let tz = TimeZone::default(); for i in 0..3 { let mut target = TargetValue { value: vrl::value!({ count: i }), metadata: Value::Object(BTreeMap::new()), secrets: Secrets::default(), }; let result = runtime.resolve(&mut target, &compilation.program, &tz).unwrap(); println!("Iteration {i}: result = {result}"); // 1, 2, 3 } } ``` -------------------------------- ### Handle Type Mismatches in VRL String Concatenation Source: https://github.com/vectordotdev/vrl/blob/main/DESIGN.md Address potential runtime errors caused by concatenating strings with fields of unknown or incompatible types. ```coffee .message = "log message: " + .log ``` -------------------------------- ### VRL Timestamp Literal Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Shows the syntax for VRL timestamp literals. ```vrl t'2021-02-11T10:32:50.553955473Z' ``` -------------------------------- ### VRL Base16 Encoding Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Demonstrates encoding a string into Base16 format. ```vrl encode_base16("please encode me") ``` -------------------------------- ### Program::resolve Source: https://context7.com/vectordotdev/vrl/llms.txt Executes a compiled VRL program within a given context. It mutates the target in place and returns the value of the final expression. ```APIDOC ## Program::resolve — Execute a compiled VRL program ### Description Resolves (executes) a compiled VRL `Program` within a `Context`. Mutates the target in place and returns the value of the final expression. ### Method `program.resolve(&mut ctx)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use vrl::compiler::{Context, Program, state::RuntimeState}; fn run_program(program: &Program, target: &mut impl vrl::compiler::Target) -> vrl::value::Value { let mut state = RuntimeState::default(); let tz = vrl::compiler::TimeZone::default(); let mut ctx = Context::new(target, &mut state, &tz); program.resolve(&mut ctx).expect("runtime error") } ``` ### Response #### Success Response (200) - **Value** (vrl::value::Value) - The value of the final expression in the VRL program. #### Response Example ```rust // Example return value vrl::value!(123) ``` ``` -------------------------------- ### Base64 encoding and decoding Source: https://context7.com/vectordotdev/vrl/llms.txt Encodes bytes to Base64 strings and decodes Base64 strings back to bytes. Supports standard and URL-safe charsets. ```vrl encode_base64("Hello, World!") # => "SGVsbG8sIFdvcmxkIQ==" ``` ```vrl encode_base64("Hello, World!", charset: "url_safe") # => "SGVsbG8sIFdvcmxkIQ==" ``` ```vrl decode_base64!("SGVsbG8sIFdvcmxkIQ==") # => b"Hello, World!" ``` ```vrl # Round-trip original = "binary \x00 data" encoded = encode_base64(original) decoded = decode_base64!(encoded) assert_eq!(original, string!(decoded)) ``` -------------------------------- ### Runtime::resolve Source: https://context7.com/vectordotdev/vrl/llms.txt Provides stateful runtime execution for VRL programs. It wraps a persistent `RuntimeState`, allowing repeated execution of programs against multiple targets while preserving state between calls. ```APIDOC ## Runtime::resolve — Stateful runtime execution ### Description `Runtime` wraps a persistent `RuntimeState`, enabling repeated execution of programs against many targets while preserving state between calls. ### Method `runtime.resolve(&mut target, &compilation.program, &tz)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use vrl::compiler::{TargetValue, TimeZone, runtime::Runtime}; use vrl::value::{Secrets, Value}; use std::collections::BTreeMap; fn main() { let src = ".count = (.count ?? 0) + 1"; let fns = vrl::stdlib::all(); let compilation = vrl::compiler::compile(src, &fns).unwrap(); let mut runtime = Runtime::default(); let tz = TimeZone::default(); for i in 0..3 { let mut target = TargetValue { value: vrl::value!({ count: i }), metadata: Value::Object(BTreeMap::new()), secrets: Secrets::default(), }; let result = runtime.resolve(&mut target, &compilation.program, &tz).unwrap(); println!("Iteration {i}: result = {result}"); // 1, 2, 3 } } ``` ### Response #### Success Response (200) - **Value** (vrl::value::Value) - The result of executing the VRL program against the target. #### Response Example ```rust // Example return value for the first iteration vrl::value!(1) ``` ``` -------------------------------- ### Parse URL String with `parse_url` Source: https://context7.com/vectordotdev/vrl/llms.txt Parses a URL string into structured fields like host, path, query, etc. The `default_known_ports` flag can auto-fill standard ports. This function is fallible. ```vrl parse_url!("ftp://foo:bar@example.com:4343/foobar?hello=world#123") # => { # "fragment": "123", # "host": "example.com", # "password": "bar", # "path": "/foobar", # "port": 4343, # "query": { "hello": "world" }, # "scheme": "ftp", # "username": "foo" # } parse_url!("https://example.com", default_known_ports: true) # => { "host": "example.com", "port": 443, "scheme": "https", ... } ``` -------------------------------- ### Construct Value Literals with value! Macro Source: https://context7.com/vectordotdev/vrl/llms.txt Ergonomically constructs `vrl::value::Value` instances inline using JSON-like syntax with the `value!` macro. Supports nested objects, arrays, scalars, and null values. Allows accessing nested fields using dot notation. ```rust use vrl::value; use vrl::value::Value; fn main() { let v: Value = value!({ user: { id: 42, name: "Alice", active: true, scores: [98, 85, 100], meta: null, } }); // Scalars let n: Value = value!(3.14); let b: Value = value!(false); let s: Value = value!("hello"); // Access nested fields assert_eq!(v.get("user.id"), Some(&value!(42))); } ``` -------------------------------- ### Map Object Keys or Values Source: https://context7.com/vectordotdev/vrl/llms.txt Applies a closure to transform keys or values of an object, returning a new object. Supports recursive transformation. ```vrl map_keys({"Hello": 1, "World": 2}) -> |key| { downcase(key) } # => { "hello": 1, "world": 2 } ``` ```vrl map_values({"a": 1, "b": 2, "c": 3}) -> |value| { value * 10 } # => { "a": 10, "b": 20, "c": 30 } ``` ```vrl # Recursive key normalization map_keys({"Foo": {"Bar": 1}}, recursive: true) -> |key| { downcase(key) } # => { "foo": { "bar": 1 } } ``` -------------------------------- ### VRL Array Manipulation Source: https://github.com/vectordotdev/vrl/blob/main/lib/fuzz/inputs.txt Shows functions for manipulating arrays in VRL, such as appending and pushing elements. ```vrl append([1, 2], [3, 4]) push([1, 2], 3) ``` -------------------------------- ### Parse Nginx Log Line with `parse_nginx_log` Source: https://context7.com/vectordotdev/vrl/llms.txt Parses Nginx access and error logs in `combined`, `error`, `ingress_upstreaminfo`, or `main` format. This function is fallible. ```vrl parse_nginx_log( s'172.17.0.1 - alice [01/Apr/2021:12:02:31 +0000] "POST /not-found HTTP/1.1" 404 153 "http://localhost/" "Mozilla/5.0"', "combined", ) # => { # "agent": "Mozilla/5.0", # "client": "172.17.0.1", # "method": "POST", # "path": "/not-found", # "protocol": "HTTP/1.1", # "referrer": "http://localhost/", # "request": "POST /not-found HTTP/1.1", # "size": 153, # "status": 404, # "timestamp": "2021-04-01T12:02:31+00:00", # "user": "alice" # } ``` -------------------------------- ### Parse String with Grok Patterns using `parse_grok` Source: https://context7.com/vectordotdev/vrl/llms.txt Parses a string against a Grok pattern. Supports all standard Grok patterns. This function is fallible. ```vrl value = "2020-10-02T23:22:12.223222Z info Hello world" pattern = "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:level} %{GREEDYDATA:message}" parse_grok!(value, pattern) # => { # "timestamp": "2020-10-02T23:22:12.223222Z", # "level": "info", # "message": "Hello world" # } ``` -------------------------------- ### Symmetric encryption and decryption Source: https://context7.com/vectordotdev/vrl/llms.txt Performs symmetric encryption and decryption using various algorithms like AES and ChaCha20. Requires key and initialization vector (IV). ```vrl # Encrypt with AES-256-CFB iv = "0123456789012345" # 16 bytes; use random_bytes(16) in production key = "01234567890123456789012345678912" # 32 bytes encrypted = encrypt!("secret data", "AES-256-CFB", key: key, iv: iv) encode_base64(encrypted) # => "c/dIOA==" ``` ```vrl # Encrypt with AES-128-CBC-PKCS7 iv2 = "1234567890123456" # 16 bytes key2 = "16_byte_keyxxxxx" # 16 bytes ciphertext = encrypt!("super secret message", "AES-128-CBC-PKCS7", key: key2, iv: iv2) encode_base64(ciphertext) # => "GBw8Mu00v0Kc38+/PvsVtGgWuUJ+ZNLgF8Opy8ohIYE=" ``` ```vrl # Decrypt plaintext = decrypt!(ciphertext, "AES-128-CBC-PKCS7", key: key2, iv: iv2) string!(plaintext) # => "super secret message" ```