A clue here is the ... if that x were a tan of something, how would that change things?

Just in case a picture helps...

... where (key in spoiler) ...

Spoiler:

... is the chain rule. Straight continuous lines differentiate downwards (integrate up) with respect to the main variable (in this case theta), and the straight dashed line similarly but with respect to the dashed balloon expression (the inner function of the composite which is subject to the chain rule).

The general drift is...

Spoiler:

Late edit: Soroban's solution below is a bit simpler, as it does without the trigonometry. Just in case a picture helps...