ParseSeverity
2 minute read
Overview
The ParseSeverity converter maps custom severity strings to standard OpenTelemetry severity levels. It takes a target value and a severity mapping that defines how custom strings translate to standard levels: fatal, error, warn, info, and debug.
Syntax
ParseSeverity(target, severityMapping)
- target: the string value to parse as a severity level
- severityMapping: a map that defines the mapping from standard OTel severity levels to arrays of match rules
The severity mapping uses this structure:
{
"fatal": [{"equals": ["CRITICAL", "FATAL"]}],
"error": [{"equals": ["ERROR", "ERR"]}],
"warn": [{"equals": ["WARNING", "WARN"]}],
"info": [{"equals": ["INFO"]}],
"debug": [{"equals": ["DEBUG", "DBG"]}]
}
Each level maps to an array of matchers. The equals matcher checks for exact case-sensitive string matches.
Examples
Input
{
"_type": "log",
"body": {
"level_critical": "CRITICAL",
"level_warning": "WARNING",
"level_info": "INFO",
"level_debug": "DEBUG"
},
"resource": {...},
"attributes": {}
}
Statement
set(attributes["parsed_crit"], ParseSeverity(body["level_critical"], {"fatal": [{"equals": ["CRITICAL", "FATAL", "CRIT"]}], "error": [{"equals": ["ERROR", "ERR"]}], "warn": [{"equals": ["WARNING", "WARN"]}], "info": [{"equals": ["INFO", "INFORMATION"]}], "debug": [{"equals": ["DEBUG", "DBG"]}]}))
set(attributes["parsed_warn"], ParseSeverity(body["level_warning"], {"fatal": [{"equals": ["CRITICAL", "FATAL", "CRIT"]}], "error": [{"equals": ["ERROR", "ERR"]}], "warn": [{"equals": ["WARNING", "WARN"]}], "info": [{"equals": ["INFO", "INFORMATION"]}], "debug": [{"equals": ["DEBUG", "DBG"]}]}))
set(attributes["parsed_info"], ParseSeverity(body["level_info"], {"fatal": [{"equals": ["CRITICAL", "FATAL", "CRIT"]}], "error": [{"equals": ["ERROR", "ERR"]}], "warn": [{"equals": ["WARNING", "WARN"]}], "info": [{"equals": ["INFO", "INFORMATION"]}], "debug": [{"equals": ["DEBUG", "DBG"]}]}))
set(attributes["parsed_debug"], ParseSeverity(body["level_debug"], {"fatal": [{"equals": ["CRITICAL", "FATAL", "CRIT"]}], "error": [{"equals": ["ERROR", "ERR"]}], "warn": [{"equals": ["WARNING", "WARN"]}], "info": [{"equals": ["INFO", "INFORMATION"]}], "debug": [{"equals": ["DEBUG", "DBG"]}]}))
Output
{
"_type": "log",
"body": {
"level_critical": "CRITICAL",
"level_warning": "WARNING",
"level_info": "INFO",
"level_debug": "DEBUG"
},
"resource": {...},
"attributes": {
"parsed_crit": "fatal",
"parsed_warn": "warn",
"parsed_info": "info",
"parsed_debug": "debug"
}
}
Each custom severity string was mapped to its corresponding OTel severity level: CRITICAL mapped to fatal, WARNING to warn, INFO to info, and DEBUG to debug.