As a Vector observability expert, I'll explain the key differences between these two AWS ALB log parsing functions, focusing on their behavior, error handling, and use cases:
1. strparse_aws_alb_log(.message)
Behavior & Return Values
- Returns two values:
(structured, err)
structured: Parsed log as a structured object (e.g., {"field": "value"}) if successful.
err: Error object if parsing fails, or null if successful.
- Non-destructive: The original event remains intact even if parsing fails. You must explicitly handle errors.
Error Handling
- Explicit error management: You must check
err to decide what to do with failed events (e.g., log, drop, or retry).
- No automatic event drops: Failed events continue down the pipeline unless you manually handle them.
Use Case
[transforms.parse_alb]
type = "remap"
source = '''
structured, err = strparse_aws_alb_log(.message)
if err != null {
log("ALB parse failed: " + err, level: "warn")
# Option 1: Drop the event
abort
# Option 2: Keep the raw message
# . = {"original_message": .message}
} else {
. = structured
}
'''
When to use:
- When you need graceful error handling (e.g., logging failures, fallback logic).
- For debugging or monitoring parse errors.
- If malformed logs should be retained for alternative processing.
2. parse_aws_alb_log!(.message)
Behavior & Return Values
- Returns one value:
structured (the parsed log object).
- Destructive: If parsing fails, the event is automatically dropped with an error log.
Error Handling
- Implicit error handling: Failed events are discarded immediately. No manual error checks needed.
- Automatic event drops: Vector handles failures by dropping the event and logging an error.
Use Case
[transforms.parse_alb]
type = "remap"
source = '''
. = parse_aws_alb_log!(.message) # Fails silently (drops event)
'''
When to use:
- When you only want valid ALB logs downstream (e.g., strict schema enforcement).
- For simpler pipelines where malformed logs should be discarded without extra logic.
- If you prioritize performance over error visibility (fewer operations).
Key Differences Summary
| Aspect | strparse_aws_alb_log(.message) | parse_aws_alb_log!(.message) |
|---|
| Return Values | (structured, err) | structured only |
| Error Handling | Explicit (you check err) | Implicit (auto-drop on failure) |
| Event Fate on Failure | Event preserved (decide action manually) | Event dropped automatically |
| Complexity | More code (error checks) | Minimal code (no error checks) |
| Performance | Slightly slower (extra operations) | Faster (no error handling overhead) |
| Use Case | Debugging, fallbacks, error monitoring | Strict pipelines, drop-on-failure |
Practical Recommendations
-
Use strparse_aws_alb_log when:
- You need to audit parse failures (e.g., send errors to a dedicated sink).
- Malformed logs should be rerouted (e.g., to a dead-letter queue).
- You want to preserve raw logs for troubleshooting.
-
Use parse_aws_alb_log! when:
- Your pipeline requires strict ALB log compliance.
- You want to minimize code complexity and trust Vector to handle failures.
- Performance is critical, and dropping invalid logs is acceptable.
Underlying Vector Philosophy
strparse_*: Follows Vector's "explicit is better" principle. Gives you control at the cost of verbosity.
parse_*!: Embodies "convention over configuration." Optimizes for simplicity and speed.
By choosing the right function, you balance between resilience (handling errors) and efficiency (dropping failures). Always align your choice with your observability goals! 🚀