When we derive the equation of a magnetic field produced by a long straight current-carrying wire, we do something like this:
Imagine a wire carrying a constant current $I$. Take a point at a distance of $r$ from the wire, this is the point where we want to find the magnetic field. So, draw a circle with radius $r$ and center at the wire (from which the point's distance is $r$). Applying the Ampere's Law $$ \oint \mathbf{B} \cdot d\mathbf{l} = \mu_{0} ~I$$
Since the magnitude of $\mathbf{B}$ is constant at every line element of the loop (circle) and it dot product with the line element is $B~dl$ everywhere, therefore $$ \oint B~dl = \mu_0 ~I$$ $$ B~\oint dl = \mu_0 ~I$$ $$ B~ 2\pi r = \mu_0 ~I $$ $$ B = \frac{\mu_0}{2\pi r} ~I $$
Now, the problem is how do we know that the magnitude of B is going to be constant and its direction will be the same as a line element. I think it's this assumption that has really solved the problem and not the mathematics . Is it an experimental fact? How can we ever made such an assumption when the only thing that we have is Elcetrostatics (I mean that electrostatics was the precursor of magnetostatics and magnetostatics always takes the analogy of static charges in electrostatics) where the field varies with distance.
I want to state my problem once more: How do we know that magnetic field's strength gonna be constant all around the loop and always tangential to the loop? .
Thank you. Any help will be much appreciated.
EDIT: Following @Dale answer, we can do something like this $$ d\mathbf{B} = \mu_0 /4\pi ~ I ~ \frac {d\mathbf{l} \times \mathbf{r}} {r^3} $$ Since, r can be written as $ \mathbf{r} = (rcos\theta, rsin\theta , z) $ and dl as $ d\mathbf{l} = ( dl,0,0) $ And now, if we take the cross product we would get $$ d\mathbf{l} \times \mathbf{r} = -z ~dl \hat j + rsin\theta \hat k$$ and therefore the magnitude of dB is equal to $$ dB = \mu_0/4\pi ~I~ |d\mathbf{l} \times \mathbf{r}| /r^3 = \mu_0/4\pi ~I ~ \sqrt{z^2+r^2sin^2\theta} dl/ r^3 $$
Thus, magnetic field is depending on $r, \theta, z$ . Please help.