open-telemetry / opentelemetry-specification

Specifications for OpenTelemetry
https://opentelemetry.io
Apache License 2.0
3.64k stars 870 forks source link

Can active Context scopes be closed in arbitrary order? #4081

Closed mladedav closed 1 week ago

mladedav commented 1 week ago

Relevant issue in Rust OpenTelemetry

Can active contexts overlap? Some implementations like Rust or Java provide methods to set a given context as an active context and return a scope which will restore the previous active context when dropped/closed.

Is there a requirement for the caller to close the scopes in reverse order, i.e. something like this should not happen:

// Root context is active
make context_1 active
make context_2 active
close context_1
// What context should be active now?
close context_2
// What context should be active now, presumably the root context?

Or should the implementations be ready for this scenario and handle it? Naive implementation of restoring the context that was active before the context being closed will break with this case. This implementation is currently used by Rust and is what I think Java does based on its documentation.

mladedav commented 1 week ago

Sorry, I didn't find it in the spec but I've been just told elsewhere where it is stated.

Spec