What exactly causes an alliance to be formed?
An alliance is caused if one of three things is true.
First, if you and that character are of the same dynasty, you count as being allies. Note that this must be you and the other ruler- not their son/half-brother/etc. This alliance is the most useful and long-lasting. Years down the line, if both realms remain of the same dynasty, the fifth-cousins-once removed ruling them will still be allies. This only applies if the rulers themselves are of the same dynasty so isn't the case in your game (but would be if she died and the son became rule).
Second, if a close relative of one character is married to a close relative of the other, an alliance is formed as long as the marriage lasts. Close relatives, for this, include brothers, sisters, parents and children but do not include anyone more distant such as uncles, nephews or cousins. Since a cousin is too distant, no alliance is formed in your game. When arranging marriages, a blue flag will be displayed if it would result in an alliance.
These alliances are briefer as they end if either the husband or wife dies (even if they had children). They can also end on succession since one of the married characters may not be closely related enough to the new ruler.
Finally, close relatives (parent/child/sibling/half-sibling) are always allies. Often they're of the same dynasty anyway- this just covers cases where they are not such as mothers or half-brothers with whom you share a mother.
Alliances in CK2 is not very transparent. The reason why your cousins wife is not your ally, is because the family relation (your cousin) is too distant. However, once he inherits, he will be your ally, since you are of the same dynasty.
If you or one of your close dynasty members are married to a ruler, or a close family member of a ruler, you are in an alliance. Otherwise not.
Close dynasty is:
Siblings and half-siblings, parents, children, grandparents, grandchildren, uncles and aunts, nephews and nieces. However, not all of these are "close enough" to warrant an alliance. We will cover later how to tell if you get an alliance or not, but a sibling, parent or child will give you an alliance (Thanks Studoku).
You can see who is closely related to you by the size of the blood drop in their character portrait. (The main use for this mechanism is to alert you of potential inbreeding, as some times marrying within the dynasty is alright – and some times risky).
Examples:
Below is my half-sister. When you mouse over the blood drop in her portrait, you will see that she is a close member of my Dynasty. (Pardon the cropping here – also I could not capture the mouse cursor, so the tooltip looks offset). Notice that her children – my nephews and nieces – have no blood drops. This is because she is in a normal mariage, and her children are of a different dynasty than mine. Had she been matrilineally married, they would also be considered members of my close dynasty.
Here is some cousin of mine. Notice that the blood drop is smaller, and the tooltip will only inform me that he is of my dynasty. Notice, however, that I am listed as an ally of his. This is because we are both rulers of the same dynasty. The text that says "Same Dynasty" is red here – this means, that he can not call me into any of his current wars. This is because he is a lesser part in that war (otherwise we would have crazy cascading in call to wars).
Finally, I will show you how to tell whether or not a marriage will generate an alliance for you. In the spouse selection screen, every portrait will have a blue or grey flag next to them. If it is blue, it means you will gain an alliance, and when you hover over it, you will see who it is. The same flag appears if you arrange marriage by going to a character screen, and select "arrange marriage".