When handling failures, choose behavior intentionally: either propagate a real error in a consistent format, or gracefully degrade only for explicitly non-error cases (e.g., notifications, permission edge cases). Avoid masking, asserting, or continuing after validation/parsing fails.

Apply:

Example (Lua error contract + explicit fallback):

local function get_context(headers)
  local trace_id = headers["x-instana-t"]
  if not trace_id then return nil end

  local parsed = trace_id:match("^(%x+)")
  if not parsed then
    -- invalid input: don't proceed with raw value
    return nil, "x-instana-t header invalid"
  end

  return parsed
end

-- usage
local trace_id, err = get_context(ngx.req.get_headers())
if err then
  ngx_log(ngx.WARN, err)
  return nil  -- or propagate: return nil, err
end

Use logging only when it’s part of the chosen error-handling policy (e.g., non-fatal notification missing handler), and keep error strings consistently formatted (e.g., lowercase-leading).