A universal way to get the magnetic vector potential (##\mathbf{A}##), given the current density (##\mathbf{J}##) in magnetostatics is:
##\mathbf{A}(\mathbf{r})=\frac{\mu_0}{4\pi}\int d^3 r' \frac{\mathbf{J}(\mathbf{r}')}{\left|\mathbf{r}-\mathbf{r}'\right|}##
Where integration is over the whole space. To get the magnetic field you simply take the curl
##\mathbf{B}(\mathbf{r})=\boldsymbol{\nabla}\times\mathbf{A}(\mathbf{r})=-\frac{\mu_0}{4\pi}\int d^3 r' \mathbf{J}(\mathbf{r}')\times\boldsymbol{\nabla}\frac{1}{\left|\mathbf{r}-\mathbf{r}'\right|}=\frac{\mu_0}{4\pi}\int d^3 r' \mathbf{J}(\mathbf{r}')\times\frac{\left(\mathbf{r}-\mathbf{r}'\right)}{\left|\mathbf{r}-\mathbf{r}'\right|^3}##
Now define ##\mathbf{R}=\mathbf{r}-\mathbf{r}'## and integrate over the corross-section of the wire, assuming the wire is thin (comapred to ##R##). This will convert the volume integral into integral along the wire: ##\int d^3 r' \mathbf{J}(\mathbf{r}')\to\int dl I(l) \mathbf{\hat{l}}## where ##I## is current (i.e. current density over the whole cross-section of the wire) and ##\mathbf{\hat{l}}## is parallel to the wire (along the direction of current flow).
Thus:
##\mathbf{B}(\mathbf{r})=\frac{\mu_0}{4\pi}\int dl I(l) \boldsymbol{\hat{l}}\times\frac{\mathbf{\hat{R}}}{R^2}##
Now ##\mathbf{R}## points from the section of the wire (at position ##l##) towards the observer. This is the Biot-Savart law. It works in all cases, including shorter wires, your formula its special case.