If Spec Z is like a Riemann surface, what's the analogue of integration along a contour? Rings of functions on a nonsingular algebraic curve (which, over $\mathbb{C}$, are holomorphic functions on a compact Riemann surface) and rings of integers in number fields are both examples of Dedekind domains, and I've been trying to understand the classical analogy between the two.  As I understand it, $\operatorname{Spec} \mathcal{O}_k$ should be thought of as the curve / Riemann surface itself.  Is there a good notion of integration in this setting?  Is there any hope of recovering an analogue of the Cauchy integral formula?
(If I am misunderstanding the point of the analogy or stretching it too far, please let me know.)
 A: I think that you have understood the analogy correctly, and you have pinpointed one of its weaknesses. Although number fields are like one dimensional functional fields in many ways, one of the differences is that the vector space of Kahler differentials for a number field has dimension 0, not 1. Here Kahler differentials are the vector space generated by symbols $dx$, subject to the relations $d(x+y) = dx + dy$ and $d(xy) = x dy + y dx$. 
Therefore, there is nothing like differentials, and nothing we can integrate.
But it is possible that there is some more sophisticated way to solve this problem. (Maybe using Arakelov geometry?) I'm looking forward to reading the other answers.
A: For a number $f$ the local-global formula written as
$$
f_2\cdot f_3\cdot \dotsb \cdot f_{\mathbb Q} = 1
$$
where $f_p$ is the inverse power of $p$ that is equal to $f$ in the local field of $p$-adic numbers and $f_{\mathbb{Q}}$ is $f$ should provide a reasonable analogue (in other words, integration over all holes gives $0$ on a closed surface).
(An example for $f = 75: 1 \times 1/3 \times 1/25 \times 1 \times \dotsb \times 75  =  1$)
A better formulation would involve adeles: the adele ring $\mathbb{A}_{\mathbb Q}$ is a semi-restricted product of $p$-adic rationals and rationals themselves. There is a map $\mathbb Q\to\mathbb A_{\mathbb Q}$ and every element in the image has the property that the product over all places gives $1$.
A: For a variety $X$ over a finite field, I guess one can take $\ell$-adic sheaves to replace differential forms. Then the local integral around a closed point $x$ (like integral over a little loop around that point) is the trace of the local Frobenius $\operatorname{Frob}_x$ on the stalk of sheaf, the so-called naive local term. Note that $\operatorname{Frob}_x$ can be regarded as an element (or conjugacy class) in $\pi_1(X)$, "a loop around $x$". The global integral would be the global trace map 
$$
H^{2d}_c(X,\mathbf{Q}_{\ell})\to\mathbf{Q}_{\ell}(-d),
$$
and the Tate twist is responsible for the Hodge structure in Betti cohomology (or the $(2\pi i)^d$ one has to divide by). The Lefschetz trace formula might be the analog of the residue theorem in complex analysis on Riemann surfaces.
For the case of number fields, each closed point $v$ in $\operatorname{Spec} O_k$ still defines a "loop" $\operatorname{Frob}_v$ in $\pi_1(\operatorname{Spec} k)$ (let's allow ramified covers. One can take the image of $\operatorname{Frob}_v$ under $\pi_1(\operatorname{Spec} k)\to\pi_1(\operatorname{Spec} O_k)$, but the target group doesn't seem to be big enough). For global integral, there's the Artin-Verdier trace map $H^3(Spec\ O_k,\mathbb G_m)\to\mathbb{Q/Z}$ and a "Poincaré duality" in this setting, but I don't know if there is a trace formula. The fact that 3 is odd always makes me excited and confused.
So basically I think of trace maps (both local and global) as counterpart of integrals. Correct me if I was wrong.
