iand675 / hs-opentelemetry

OpenTelemetry support for the Haskell programming language
https://iankduncan.com/projects/opentelemetry
BSD 3-Clause "New" or "Revised" License
73 stars 34 forks source link

Fix callerAttributes in the presence of frozen call stacks #137

Closed michaelpj closed 4 months ago

michaelpj commented 4 months ago

Freezing the call stack is common when writing your own utility wrappers around e.g. withSpan. In this case you want to freeze the call stack before calling your utility, so that withSpan and friends see the "application" function as the top of the call stack.

However, the functions for getting information from call stacks just generally didn't work right in the presence of frozen call stacks. They assumed that the call stack was unfrozen, and hence that they could look up a fixed number of steps to find the caller info.

We can't in general tell directly if the call stack is frozen, but we use a pretty decent heuristic here: is the top element exactly our own function? If so, we probably have an unfrozen call stack. Otherwise we might have a frozen call stack and we have to try and do something else.

iand675 commented 4 months ago

Nice! Thanks for this, I've been hoping to improve it for some time.

iand675 commented 4 months ago

@michaelpj would you mind adding a note about this to the changelog?

michaelpj commented 4 months ago

Added