Start by rearranging the given differential equation:
\[
x \sin \left( \frac{y}{x} \right) \, dy = \left( y \sin \left( \frac{y}{x} \right) - x \right) \, dx.
\]
First, divide both sides of the equation by \(x \sin \left( \frac{y}{x} \right)\):
\[
\frac{dy}{dx} = \frac{y \sin \left( \frac{y}{x} \right) - x}{x \sin \left( \frac{y}{x} \right)}.
\]
Simplify the equation by separating the terms:
\[
\frac{dy}{dx} = \frac{y}{x} - \frac{x}{x \sin \left( \frac{y}{x} \right)}.
\]
Now, integrate both sides of the equation:
\[
\int \frac{dy}{y} = \int \left( \frac{1}{x} - \frac{1}{x \sin \left( \frac{y}{x} \right)} \right) dx.
\]
On integrating, we get:
\[
\log |y| = \log |x| + c.
\]
Thus, solving for the general solution, we obtain:
\[
\cos \left( \frac{y}{x} \right) = \log_e x + c.
\]